bootstrap
view genesis/ometa/ometa-parser.g @ 758:42c043932622
rename parse to parse-memo
add comments to ometa grammar
add 'transient' flags to ometa grammar
'memoize' instructions used by the interpreter so that we don't duplicate cons lists
add comments to ometa grammar
add 'transient' flags to ometa grammar
'memoize' instructions used by the interpreter so that we don't duplicate cons lists
| author | John Leuner <jewel@subvert-the-dominant-paradigm.net> |
|---|---|
| date | Sun Apr 24 12:42:17 2011 +0200 (13 months ago) |
| parents | d6a2c4d7c783 |
| children | 5441d4d13f04 |
line source
1 ometa ometa-parser <: ometa {
2 nameFirst = letter | $_,
3 nameRest = nameFirst | digit | $- | $!,
4 tsName = nameFirst:f nameRest*:r -> <<`(_string ,f ,r)>>,
5 name = wsnl* tsName,
6 okeyword :xs = token(xs) ~letterOrDigit,
8 characters = "''''",
9 sCharacters = stringquote (~stringquote anything)*:xs stringquote -> <<'(_quoted_string ,xs)>>,
11 osymbol = wsnl* "#" tsName:s -> << `(app exactly (symbol ,s))>>,
12 char-literal = "$" anything:d -> << `(app exactly (character ,d)) >>,
13 onumber = digit+:ds -> <<`(app exactly (_number ,ds))>>,
14 letterOrDigit = letter | digit,
16 args = "(" hostExpr:x ")" -> << x >>,
19 application = name:rule args:as -> <<('app rule as)>> | name:rule1 -> <<('app rule1)>>,
21 hostExpr = wsnl* (curlyHostExpr | atomicHostExpr),
22 curlyHostExpr = wsnl* "<<" (~">>" anything)*:xs ">>" -> << `(act ,xs) >>,
23 atomicHostExpr = (sCharacters | name):x -> <<x>>,
25 semAction = wsnl* ("!" | "->") wsnl* (atomicHostExpr:x -> <<('act x)>>
26 | wsnl* curlyHostExpr:x -> <<x>>),
27 semPred = wsnl* "?" hostExpr:x -> <<('pred x)>>,
28 expr = expr4:h (wsnl* "|" wsnl* expr4)*:t -> <<('or h t)>>,
29 expr4 = (wsnl* expr3)*:xs -> << `(and ,xs)>>,
30 optIter :x = "*" -> <<('many x)>>
31 | "+" -> <<('many1 x)>>
32 | empty -> <<x>>,
33 expr3 = expr2:x optIter(x):x ( ":" name:n -> << ('set n x) >>
34 | empty -> << x >>
35 )
36 | ":" name:n -> << ('set n ('loadarg)) >>,
37 expr2 = wsnl* "~" expr2:x -> <<('not x)>>
38 | wsnl* "&" expr1:x -> <<('lookahead x)>>
39 | expr1,
40 expr1 = application | semAction | semPred
41 | wsnl* (characters | sCharacters:s -> <<`(app token ,s)>> | char-literal | osymbol | onumber)
42 | wsnl* "(" wsnl* expr:x wsnl* ")" -> <<x>>,
43 rulearg = (":" name:argname wsnl* -> <<argname>>)* | empty,
45 comment = ";" (~cnewline anything)* cnewline,
46 rule-flags = (("transient" | "inline"):flag ws+ -> << flag >>)*,
47 rule = comment* rule-flags:flags name:n wsnl* rulearg:locals wsnl* "=" wsnl* expr:rhs -> << `(rule1 ,n ,flags ,locals ,rhs) >>,
49 ws = $ | $ ,
50 wsnl = ws | cnewline,
52 empty = -> <<'true>>,
53 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) >>
55 }
