From 5c3bd2542e04440b690d99da9ab4e78d85b16f26 Mon Sep 17 00:00:00 2001 From: Ondrej Bilka Date: Sun, 7 Nov 2010 09:47:21 +0100 Subject: [PATCH] `ometa expresion` in rule argument translated to proc --- lib/ometa/bootstrap.rb | 13 +++++++++---- ometa/bsruby_parser.ometa | 2 +- ometa/ometa_translator.ometa | 10 ++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/ometa/bootstrap.rb b/lib/ometa/bootstrap.rb index 870a2ec..b55d980 100644 --- a/lib/ometa/bootstrap.rb +++ b/lib/ometa/bootstrap.rb @@ -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 @@ -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 diff --git a/ometa/bsruby_parser.ometa b/ometa/bsruby_parser.ometa index 67572c5..50cf85d 100644 --- a/ometa/bsruby_parser.ometa +++ b/ometa/bsruby_parser.ometa @@ -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, diff --git a/ometa/ometa_translator.ometa b/ometa/ometa_translator.ometa index 42dc14a..9eb8a82 100644 --- a/ometa/ometa_translator.ometa +++ b/ometa/ometa_translator.ometa @@ -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 * ', '})" },