Skip to content

Commit

Permalink
writing macro
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Apr 28, 2019
1 parent b444bc3 commit b64f0f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/genani/basic.ma
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type Foo =
val: abc
j: Bar
type Bar =
val: def
type Fee =
j = 0
new -> foo =
a = 10
7 changes: 5 additions & 2 deletions src/genani/genesis.1.ma
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import OrganisationRegister from organisation

type WitnessedAttribute is VisitAttribute =
foooddddd: b
macro witnessed for $typedef =
as foo =
pass


machine Genesis =
static root: Organisation
static unlockScript: boolean(ScriptHash)
Expand Down
15 changes: 8 additions & 7 deletions src/martha.grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,26 +421,27 @@ class Util extends WithParserContext {
super(context)
}
indents:string[] = [];
pushIndent = rule(this.context.ws.space0ton, this.context.ws.newline, this.context.ws.indent).yields((r:ResultTokens) => {
this.indents.push(r.one("indent")!.value);
pushIndent = rule(this.context.ws.newline, this.context.ws.indent).yields((r:ResultTokens) => {
this.indents.push(r.one("indent")!.value)
});
peekIndent = rule(this.context.ws.newline, (input:Input):Result => {
this.indents /* ?+ */
peekIndent = rule(this.context.ws.space0ton, this.context.ws.newline, (input:Input):Result => {
let index:number = input.source.substring(input.location).indexOf(this.indents[this.indents.length - 1]);
index // ?
if (index === 0) {
input.location += this.indents[this.indents.length - 1].length;
return Result.pass(input);
}
return Result.fault(input);
});
popIndent = rule((input:Input):Result => {
this.indents.pop();
return Result.pass(input);
input.source.substring(input.location)
this.indents.pop()
return Result.pass(input)
});
EOF = rule((input:Input):Result => input.location === input.source.length ?
Result.pass(input) : Result.fault(input));
block = (begin:Pattern, repeat:Pattern) => rule(
many(this.context.ws.newline),
// many(this.context.ws.newline),
begin, /[ \t]*=[ \t]*/,
either(
all(this.pushIndent, repeat,
Expand Down
6 changes: 3 additions & 3 deletions src/test/genesis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ function parse(file:string):ProgramDef {
fs.writeFileSync(file + ".json", JSON.stringify(parsed,null,2))
return parsed
}

// file.only
describe("genesis", () => {
let f = parse(__dirname + "../../genani/genesis.1.ma")

it("should be a program", () => expect(f).to.not.be.undefined)

it("should have one type at root level", () => expect(f.types.length).to.eq(1))
it("should have one type at root level", () => expect(f.types.length).to.eq(2))

f.types[0].members[0] /* ?+ */
f.macros /* ?+ */

return;

Expand Down

0 comments on commit b64f0f7

Please sign in to comment.