bootstrap
diff genesis/ometa/ometa-parser.g @ 755:d6a2c4d7c783
add new grammar for parsing ometa grammars
remove old church grammar
remove old church grammar
| author | John Leuner <jewel@subvert-the-dominant-paradigm.net> |
|---|---|
| date | Sun Mar 27 22:16:31 2011 +0200 (13 months ago) |
| parents | |
| children | 42c043932622 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/genesis/ometa/ometa-parser.g Sun Mar 27 22:16:31 2011 +0200 1.3 @@ -0,0 +1,53 @@ 1.4 +ometa ometa-parser <: ometa { 1.5 +nameFirst = letter | $_, 1.6 +nameRest = nameFirst | digit | $- | $!, 1.7 +tsName = nameFirst:f nameRest*:r -> <<`(_string ,f ,r)>>, 1.8 +name = wsnl* tsName, 1.9 +okeyword :xs = token(xs) ~letterOrDigit, 1.10 + 1.11 +characters = "''''", 1.12 +sCharacters = stringquote (~stringquote anything)*:xs stringquote -> <<'(_quoted_string ,xs)>>, 1.13 + 1.14 +osymbol = wsnl* "#" tsName:s -> << `(app exactly (symbol ,s))>>, 1.15 +char-literal = "$" anything:d -> << `(app exactly (character ,d)) >>, 1.16 +onumber = digit+:ds -> <<`(app exactly (_number ,ds))>>, 1.17 +letterOrDigit = letter | digit, 1.18 + 1.19 +args = "(" hostExpr:x ")" -> << x >>, 1.20 + 1.21 + 1.22 +application = name:rule args:as -> <<('app rule as)>> | name:rule1 -> <<('app rule1)>>, 1.23 + 1.24 +hostExpr = wsnl* (curlyHostExpr | atomicHostExpr), 1.25 +curlyHostExpr = wsnl* "<<" (~">>" anything)*:xs ">>" -> << `(act ,xs) >>, 1.26 +atomicHostExpr = (sCharacters | name):x -> <<x>>, 1.27 + 1.28 +semAction = wsnl* ("!" | "->") wsnl* (atomicHostExpr:x -> <<('act x)>> 1.29 + | wsnl* curlyHostExpr:x -> <<x>>), 1.30 +semPred = wsnl* "?" hostExpr:x -> <<('pred x)>>, 1.31 +expr = expr4:h (wsnl* "|" wsnl* expr4)*:t -> <<('or h t)>>, 1.32 +expr4 = (wsnl* expr3)*:xs -> << `(and ,xs)>>, 1.33 +optIter :x = "*" -> <<('many x)>> 1.34 + | "+" -> <<('many1 x)>> 1.35 + | empty -> <<x>>, 1.36 +expr3 = expr2:x optIter(x):x ( ":" name:n -> << ('set n x) >> 1.37 + | empty -> << x >> 1.38 + ) 1.39 + | ":" name:n -> << ('set n ('loadarg)) >>, 1.40 +expr2 = wsnl* "~" expr2:x -> <<('not x)>> 1.41 + | wsnl* "&" expr1:x -> <<('lookahead x)>> 1.42 + | expr1, 1.43 +expr1 = application | semAction | semPred 1.44 + | wsnl* (characters | sCharacters:s -> <<`(app token ,s)>> | char-literal | osymbol | onumber) 1.45 + | wsnl* "(" wsnl* expr:x wsnl* ")" -> <<x>>, 1.46 +rulearg = (":" name:argname wsnl* -> <<argname>>)* | empty, 1.47 +rule = name:n wsnl* rulearg:locals wsnl* "=" wsnl* expr:rhs -> << `(rule ,n ,locals ,rhs) >>, 1.48 + 1.49 + 1.50 +ws = $ | $ , 1.51 +wsnl = ws | cnewline, 1.52 + 1.53 +empty = -> <<'true>>, 1.54 +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) >> 1.55 + 1.56 +}
