view genesis/ometa/ometa-parser.g @ 755:d6a2c4d7c783 alpha-6

add new grammar for parsing ometa grammars remove old church grammar
author John Leuner <jewel@subvert-the-dominant-paradigm.net>
date Sun, 27 Mar 2011 22:16:31 +0200
parents
children 42c043932622
line wrap: on
line source
ometa ometa-parser <: ometa {
nameFirst = letter | $_,
nameRest = nameFirst | digit | $- | $!,
tsName = nameFirst:f nameRest*:r -> <<`(_string ,f ,r)>>,
name = wsnl* tsName,
okeyword :xs = token(xs) ~letterOrDigit,

characters = "''''",
sCharacters = stringquote (~stringquote anything)*:xs stringquote -> <<'(_quoted_string ,xs)>>,

osymbol = wsnl* "#" tsName:s -> << `(app exactly (symbol ,s))>>,
char-literal = "$" anything:d -> << `(app exactly (character ,d)) >>,
onumber = digit+:ds -> <<`(app exactly (_number ,ds))>>,
letterOrDigit = letter | digit,

args = "(" hostExpr:x ")" -> << x >>,


application = name:rule args:as -> <<('app rule as)>> | name:rule1 -> <<('app rule1)>>,

hostExpr = wsnl* (curlyHostExpr | atomicHostExpr),
curlyHostExpr = wsnl* "<<" (~">>" anything)*:xs ">>" -> << `(act ,xs) >>,
atomicHostExpr = (sCharacters | name):x -> <<x>>,

semAction = wsnl* ("!" | "->") wsnl* (atomicHostExpr:x -> <<('act x)>>
            | wsnl* curlyHostExpr:x -> <<x>>),
semPred = wsnl* "?" hostExpr:x -> <<('pred x)>>,
expr = expr4:h (wsnl* "|" wsnl* expr4)*:t -> <<('or h t)>>,
expr4 = (wsnl* expr3)*:xs -> << `(and ,xs)>>,
optIter :x = "*" -> <<('many x)>>
           | "+" -> <<('many1 x)>>
           | empty -> <<x>>,
expr3 = expr2:x optIter(x):x ( ":" name:n -> << ('set n x) >>
                               | empty -> << x >>
                             )
        | ":" name:n -> <<  ('set n ('loadarg)) >>,
expr2 = wsnl* "~" expr2:x -> <<('not x)>>
      | wsnl* "&" expr1:x -> <<('lookahead x)>>
      | expr1,
expr1 = application | semAction | semPred
      | wsnl* (characters | sCharacters:s -> <<`(app token ,s)>> | char-literal | osymbol | onumber)
      | wsnl* "(" wsnl* expr:x wsnl* ")" -> <<x>>,
rulearg = (":" name:argname wsnl* -> <<argname>>)* | empty,
rule = name:n wsnl* rulearg:locals wsnl* "=" wsnl* expr:rhs -> << `(rule ,n ,locals ,rhs) >>, 


ws = $  | $	,
wsnl = ws | cnewline,

empty = -> <<'true>>,
grammar = "ometa" ws+ name:n wsnl* ("<:" name | empty -> <<'OMeta>>):sn wsnl* "{" wsnl* rule:h wsnl* ("," wsnl* rule)*:t  wsnl* "}" wsnl* -> << ('grammar n sn h t) >>

}