Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Created May 25, 2012 13:00
Show Gist options
  • Save fjolnir/2787998 to your computer and use it in GitHub Desktop.
Save fjolnir/2787998 to your computer and use it in GitHub Desktop.
%token keyword_nil
%token tLPAREN tRPAREN // ()
%token tLBRACE tRBRACE // {}
%token tLBRACKET tRBRACKET // {}
%token tPIPE // |
%token tCOLON // :
%token tSEMICOLON // ;
%token tDOT // .
%token tCOMMA // ,
%token tASSIGN // =
%token tNUMBER // <number>
%token tSTRING // Contents of a quoted string
%token tIDENTIFIER // An identifier, non quoted string matching [a-zA-Z0-9_]+
%{
%}
%%
program:
| expr
;
call:
expr tCOLON args tSEMICOLON
| expr tSEMICOLON
;
args:
expr tIDENTIFIER tCOLON args
| expr tCOLON args /* Never reduced */
| expr /* never reduced */
;
block:
tLBRACE argDefs tPIPE expr tRBRACE
| tLBRACE expr tRBRACE
;
argDefs:
argDef tIDENTIFIER tCOLON argDefs
| argDef tCOLON argDefs
| argDef
;
argDef:
tIDENTIFIER
varDef:
var tASSIGN expr
;
var:
tIDENTIFIER
;
expr:
var
| varDef
| block
| objAccess
| obj
| tLPAREN expr tRPAREN
| literal
| call
;
obj:
tLBRACKET tRBRACKET
| tLBRACKET objMembers tRBRACKET
;
objMembers:
| objMembers tCOMMA objMembers
| objMember
;
objMember:
tIDENTIFIER tASSIGN expr
;
objAccess:
var tDOT tIDENTIFIER
;
literal:
tNUMBER
| tSTRING
;
%%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment