Skip to content

Instantly share code, notes, and snippets.

@stephpy
Created June 19, 2013 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephpy/5814496 to your computer and use it in GitHub Desktop.
Save stephpy/5814496 to your computer and use it in GitHub Desktop.
%skip space \s
// Scalars.
%token true true|TRUE
%token false false|FALSE
%token null null|NULL
// Comparator
%token isNot (is not|IS NOT)
%token is (is|IS)
// Logical operators
%token not NOT
%token and AND
%token nand NAND
%token or OR
%token nor NOR
%token xor XOR
%token xnor XNOR
// Value
%token string ("|')(.*?)(?<!\\)\1
%token number \d+
%token float \d+\.\d+
%token key [a-zA-Z0-9-_\.]+
%token bracket_ \(
%token _bracket \)
%token comma ,
%token operator [^\s]+
expression:
unary()
( (::and:: #and | ::nand:: #nand | ::or:: #or | ::nor:: #nor | ::xor:: #xor | ::xnor:: #xnor) expression())?
unary:
(::not:: #not)? condition()
condition:
(::bracket_:: expression() ::_bracket::)
| (value() operator() value()) #condition
operator:
<operator> | <key> | <is> | <isNot>
#array:
::bracket_:: value() ( ::comma:: value() )* ::_bracket::
value:
<true> | <false> | <null> | <number> | <float> | <string> | <key> | function() | array()
#function:
<key> ::bracket_::
( value() ( ::comma:: value() )* )?
::_bracket::
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment