grammar 1 - a-f-m/japath3 GitHub Wiki

start = simpleExpr !. 
simpleExpr = 
    '(' simpleExpr ')' /
    'null' /
    (Number / String!(':')) /
    path!(':') /
    assignment
assignment = (path / String) ':' simpleExpr
path =  
    stepExpr (('.') stepExpr)* 
stepExpr = 
    step  subscript* filter? binding? subExpr? 
step = 
    nil / self / wild / selector / union / comparison / boolExpr / 
    filter / cond / optional / 
    type / text / var / argNumber / 
    exprDef / scriptDef / message /
    exprAppl / create / struct / array /
    funcCall /
    property 
nil = 'nil'
self = ('_' / 'self')
wild = 
    '**' ('^')? / 
    '*' 
selector = 
    '&' / 'selector'
union = 
    'union' '(' args ')' 
array = 
    '[' args? ']'  
comparison = ('eq'/'neq'/'lt'/'gt'/'le'/'ge'/'match') '(' simpleExpr ')' 
/* 'assert' used in schema context, same semantics as 'and' */
boolExpr = 
    ('and'/'assert'/'or'/'xor'/'not') '(' args ')' /
    ('true' /'false')
    'imply' '(' simpleExpr ',' simpleExpr ')' /
    'every' '(' path ',' simpleExpr ')' /
    'some' '(' path ',' simpleExpr ')' 
filter = ('filter'/'?') '(' simpleExpr ')' 
cond = 'cond' '(' simpleExpr ',' simpleExpr (',' simpleExpr)? ')' 
optional = ('optional'/'opt') '(' path ')' 
type = 'type' '(' ('String' / 'Number' / 'Boolean' / 'Any') ')' 
text = 'text' '(' ')' 
var = '$'  Identifier?  
exprDef = 'def'  '(' Identifier ('(' parameters? ')')? ',' simpleExpr ')' 
parameters = 
    parameter (',' parameter)* 
parameter = Identifier (':'  simpleExpr)?
scriptDef = 'def-script'  '(' MultilineString ')' 
message = 'message'  '(' simpleExpr ')' 
argNumber = '#' index
exprAppl = !'asProperty' Identifier '(' args? ')' 

subExpr = '{' args '}' 
create = 'new'
struct = '{' structArgs? '}' 
funcCall =
    ('js'/'javascript') '::' Identifier '(' args? ')' /
    'j''ava'? '::' Identifier '::' Identifier '(' args? ')' /
    '::' Identifier ('(' args? ')')? 
property = 
    'asProperty' '(' path ')' /
    Identifier / QIdentifier) 
subscript = 
    '[' '#' index ('..' index?)? ']' /
    '[' index ']' /
    '[' '>' ']'  
binding = '$'  Identifier  
args = 
    simpleExpr (',' simpleExpr)* 
structArgs = 
    assignment (',' assignment)* 
index = int 
/* equivalent to json spec */
Number = "-"? int frac? exp? 
exp           = [eE] ("-" / "+")? digit+
frac          = "." digit+
int           = "0" / (digit1_9 digit*)
digit1_9      = [1-9]
digit  = [0-9]

String = SingleQuoteString / MultilineString / DoubleQuoteString 
SingleQuoteString = "'" ('\\\''/[^'])* "'"  
DoubleQuoteString = "\"" ('\\"'/[^\"])* "\""  
MultilineString = 
    '"""' (!'"""'.)* '"""'  
Identifier = ([a-zA-Z ] [a-zA-Z0-9 ]*) 
Keyword = 
    'selector' / 'filter' / 'and' / 'assert' / 'or' / 'xor' / 'not' / 'true' / 'false' / 'cond' / 'imply' / 
    'optional' / 'opt' / 'every' / 'union' / 'eq' / 'neq' / 'lt' / 'gt' / 'le' / 'ge' / 'call' / 'type' / 
    'self' / 'def' / 'def-script' / 'new' / 'java' / 'j' / 'js' / 'match' / 'null' / 'error' / 'message' / 'property'
QIdentifier = 
    '`' ('\\`'/[^`])+ '`'