A "high-level" language for the Gameboy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

27 lines
682 B

// AST factories
{
const attr = (name, args) => ({ name, args })
}
// Attributes
Attrs = LATTR l:AttrList RATTR { return l }
AttrList = h:Attr t:(COMMA @Attr)* { return [h].concat(t) }
/ '' { return [] }
Attr = name:Ident args:(LPAREN @AttrArgs RPAREN)? { return attr(name, args || []) }
AttrArgs = h:AttrArg t:(COMMA @AttrArg)* { return [h].concat(t) }
/ '' { return [] }
AttrArg = Ident / Number
// Terminals
Ident = h:[a-zA-Z_] t:[0-9a-zA-Z_]* WS { return h + t.join('') }
Number = digits:[0-9]+ WS { return parseInt(digits.join(''), 10) }
// Terminal symbols
LPAREN = '(' WS
RPAREN = ')' WS
COMMA = ',' WS
LATTR = '[[' WS
RATTR = ']]' WS
// Misc
WS = [ \t\r\n]*