bootstrap
annotate 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 |
| rev | line source |
|---|---|
| jewel@755 | 1 ometa ometa-parser <: ometa { |
| jewel@755 | 2 nameFirst = letter | $_, |
| jewel@755 | 3 nameRest = nameFirst | digit | $- | $!, |
| jewel@755 | 4 tsName = nameFirst:f nameRest*:r -> <<`(_string ,f ,r)>>, |
| jewel@755 | 5 name = wsnl* tsName, |
| jewel@755 | 6 okeyword :xs = token(xs) ~letterOrDigit, |
| jewel@755 | 7 |
| jewel@755 | 8 characters = "''''", |
| jewel@755 | 9 sCharacters = stringquote (~stringquote anything)*:xs stringquote -> <<'(_quoted_string ,xs)>>, |
| jewel@755 | 10 |
| jewel@755 | 11 osymbol = wsnl* "#" tsName:s -> << `(app exactly (symbol ,s))>>, |
| jewel@755 | 12 char-literal = "$" anything:d -> << `(app exactly (character ,d)) >>, |
| jewel@755 | 13 onumber = digit+:ds -> <<`(app exactly (_number ,ds))>>, |
| jewel@755 | 14 letterOrDigit = letter | digit, |
| jewel@755 | 15 |
| jewel@755 | 16 args = "(" hostExpr:x ")" -> << x >>, |
| jewel@755 | 17 |
| jewel@755 | 18 |
| jewel@755 | 19 application = name:rule args:as -> <<('app rule as)>> | name:rule1 -> <<('app rule1)>>, |
| jewel@755 | 20 |
| jewel@755 | 21 hostExpr = wsnl* (curlyHostExpr | atomicHostExpr), |
| jewel@755 | 22 curlyHostExpr = wsnl* "<<" (~">>" anything)*:xs ">>" -> << `(act ,xs) >>, |
| jewel@755 | 23 atomicHostExpr = (sCharacters | name):x -> <<x>>, |
| jewel@755 | 24 |
| jewel@755 | 25 semAction = wsnl* ("!" | "->") wsnl* (atomicHostExpr:x -> <<('act x)>> |
| jewel@755 | 26 | wsnl* curlyHostExpr:x -> <<x>>), |
| jewel@755 | 27 semPred = wsnl* "?" hostExpr:x -> <<('pred x)>>, |
| jewel@755 | 28 expr = expr4:h (wsnl* "|" wsnl* expr4)*:t -> <<('or h t)>>, |
| jewel@755 | 29 expr4 = (wsnl* expr3)*:xs -> << `(and ,xs)>>, |
| jewel@755 | 30 optIter :x = "*" -> <<('many x)>> |
| jewel@755 | 31 | "+" -> <<('many1 x)>> |
| jewel@755 | 32 | empty -> <<x>>, |
| jewel@755 | 33 expr3 = expr2:x optIter(x):x ( ":" name:n -> << ('set n x) >> |
| jewel@755 | 34 | empty -> << x >> |
| jewel@755 | 35 ) |
| jewel@755 | 36 | ":" name:n -> << ('set n ('loadarg)) >>, |
| jewel@755 | 37 expr2 = wsnl* "~" expr2:x -> <<('not x)>> |
| jewel@755 | 38 | wsnl* "&" expr1:x -> <<('lookahead x)>> |
| jewel@755 | 39 | expr1, |
| jewel@755 | 40 expr1 = application | semAction | semPred |
| jewel@755 | 41 | wsnl* (characters | sCharacters:s -> <<`(app token ,s)>> | char-literal | osymbol | onumber) |
| jewel@755 | 42 | wsnl* "(" wsnl* expr:x wsnl* ")" -> <<x>>, |
| jewel@755 | 43 rulearg = (":" name:argname wsnl* -> <<argname>>)* | empty, |
| jewel@755 | 44 rule = name:n wsnl* rulearg:locals wsnl* "=" wsnl* expr:rhs -> << `(rule ,n ,locals ,rhs) >>, |
| jewel@755 | 45 |
| jewel@755 | 46 |
| jewel@755 | 47 ws = $ | $ , |
| jewel@755 | 48 wsnl = ws | cnewline, |
| jewel@755 | 49 |
| jewel@755 | 50 empty = -> <<'true>>, |
| jewel@755 | 51 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) >> |
| jewel@755 | 52 |
| jewel@755 | 53 } |
