diff --git a/src/genani/basic.ma b/src/genani/basic.ma new file mode 100644 index 0000000..3d6da0a --- /dev/null +++ b/src/genani/basic.ma @@ -0,0 +1,9 @@ +type Foo = + val: abc + j: Bar +type Bar = + val: def +type Fee = + j = 0 + new -> foo = + a = 10 \ No newline at end of file diff --git a/src/genani/genesis.1.ma b/src/genani/genesis.1.ma index 28a9b1a..fc41c19 100644 --- a/src/genani/genesis.1.ma +++ b/src/genani/genesis.1.ma @@ -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) diff --git a/src/martha.grammar.ts b/src/martha.grammar.ts index 1a9d53b..9031141 100644 --- a/src/martha.grammar.ts +++ b/src/martha.grammar.ts @@ -421,12 +421,12 @@ 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); @@ -434,13 +434,14 @@ class Util extends WithParserContext { 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, diff --git a/src/test/genesis.spec.ts b/src/test/genesis.spec.ts index d81cb70..c1aa50b 100644 --- a/src/test/genesis.spec.ts +++ b/src/test/genesis.spec.ts @@ -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;