cat coding code example
Example: cat programming language
export var catGrammar = new function()
{
var _this = this;
this.identifier = m.identifier.ast;
this.integer = m.integer.ast;
this.true = m.keyword("true").ast;
this.false = m.keyword("false").ast;
this.typeExprRec = m.delay(() => { return _this.typeExpr});
this.typeArray = m.guardedSeq('[', m.ws, this.typeExprRec.ws.zeroOrMore, ']').ast;
this.funcInput = this.typeExprRec.ws.zeroOrMore.ast;
this.funcOutput = this.typeExprRec.ws.zeroOrMore.ast;
this.typeFunc = m.guardedSeq('(', m.ws, this.funcInput, '->', m.ws, this.funcOutput, ')').ast;
this.typeVar = m.guardedSeq("'", m.identifier).ast;
this.typeConstant = m.identifier.ast;
this.typeExpr = m.choice(this.typeArray, this.typeFunc, this.typeVar, this.typeConstant).ast;
this.recTerm = m.delay(() => { return _this.term; });
this.quotation = m.guardedSeq('[', m.ws, this.recTerm.ws.zeroOrMore, ']').ast;
this.term = m.choice(this.quotation, this.integer, this.true, this.false, this.identifier);
this.terms = m.ws.then(this.term.ws.zeroOrMore);
this.definedName = m.identifier.ast;
this.typeSig = m.guardedSeq(":", m.ws, this.typeExpr).ast;
this.extern = m.guardedSeq(m.keyword('extern').ws, this.definedName, m.ws, this.typeSig).ast;
this.definition = m.guardedSeq('{', this.term.zeroOrMore, '}').ast;
this.define = m.guardedSeq(m.keyword('define').ws, this.definedName, m.ws, this.typeSig.opt, this.definition).ast;
this.program = m.choice(this.define, this.extern, this.term).zeroOrMore.ast;
}