Skip to content

Commit

Permalink
ometa expresion in rule argument translated to proc
Browse files Browse the repository at this point in the history
  • Loading branch information
neleai committed Nov 7, 2010
1 parent e75f9a2 commit 5c3bd25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
13 changes: 9 additions & 4 deletions lib/ometa/bootstrap.rb
Expand Up @@ -246,7 +246,7 @@ def innerBra

def outerBra
xs = nil
(_applyWithArgs("exactly", "(");xs = _xmany { _apply("insideBra") };_applyWithArgs("exactly", ")"); xs*"" )
(_applyWithArgs("exactly", "(");xs = _xmany { _apply("insideBra") };_applyWithArgs("exactly", ")"); [ xs] )
end

def expr
Expand Down Expand Up @@ -460,12 +460,17 @@ def trans

def App
args = rule = args = rule = nil
_or(proc { (_applyWithArgs("exactly", "super");args = _xmany1 { _apply("arg") }; "_superApplyWithArgs(#{args*", "})" ) }, proc { (rule = _apply("anything");args = _xmany1 { _apply("arg") };"_applyWithArgs(#{rule.inspect}, #{args*", "})" ) }, proc { (rule = _apply("anything"); "_apply(#{rule.inspect})" ) })
_or(proc { (_applyWithArgs("exactly", "super");args = _xmany1 { _apply("arg") }; "_superApplyWithArgs(#{args*", "})" ) }, proc { (rule = _apply("anything");args = _xmany1 { _apply("arg") }; "_applyWithArgs(#{rule.inspect}, #{args*", "})" ) }, proc { (rule = _apply("anything"); "_apply(#{rule.inspect})" ) })
end

def arg
c = s = x = nil
_or(proc { (c = _apply("anything");c) }, proc { (s = _apply("anything");_pred(s.is_a? String);","+s) }, proc { (x = _apply("transFn");","+x ) })
m = s = nil
_or(proc { (_xform { m = _xmany { _apply("ag") } };m*"") }, proc { (s = _apply("anything");_pred(s.is_a? String);s) })
end

def ag
t = nil
_or(proc { _apply("char") }, proc { (_xform { t = _apply("transFn") };t) })
end

def Act
Expand Down
2 changes: 1 addition & 1 deletion ometa/bsruby_parser.ometa
Expand Up @@ -6,7 +6,7 @@ ometa BSRubyParser <: OMeta {
nonBraChar = ~'(' ~')' char,
insideBra = omproc:o ->{[o]} | innerBra | nonBraChar,
innerBra = '(' insideBra*:xs ')' -> {"("+xs*"" +")" },
outerBra = '(' insideBra*:xs ')' -> { xs*"" },
outerBra = '(' insideBra*:xs ')' -> { [ xs] },
expr = outerBra,
semAction1 = spaces (~seq("\n") anything)*:xs -> { xs.join('') },
nonBraceChar = ~'{' ~'}' char,
Expand Down
10 changes: 6 additions & 4 deletions ometa/ometa_translator.ometa
Expand Up @@ -2,12 +2,14 @@
ometa RubyOMetaTranslator {
trans [:t apply(t):ans] = -> { ans },
App 'super' arg+:args = -> { "_superApplyWithArgs(#{args*", "})" },
App :rule arg+:args = -> {"_applyWithArgs(#{rule.inspect}, #{args*", "})" },
App :rule arg+:args = -> { "_applyWithArgs(#{rule.inspect}, #{args*", "})" },
App :rule = -> { "_apply(#{rule.inspect})" },
arg = :c -> c
| :s &{s.is_a? String} ->","+s
| transFn:x -> ","+x
arg = [ ag*:m ] -> m*""
| :s &{s.is_a? String} -> s
,
ag= char
| [ transFn:t ] -> t
,
Act :expr = -> { expr },
Pred :expr = -> { "_pred(#{expr})" },
Or transFn*:xs = -> { "_or(#{xs * ', '})" },
Expand Down

0 comments on commit 5c3bd25

Please sign in to comment.