Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Type inference for rule return types

  • Loading branch information...
commit 000623ce0a7e6fa9e38b88516cbba568ba39f98d 1 parent f52c378
@ribrdb ribrdb authored
Showing with 7,497 additions and 6,943 deletions.
  1. +5 −6 README.txt
  2. +3 −3 Rakefile
  3. +1,527 −1,604 boot/mirah_compiler.mirah
  4. +70 −78 boot/mirah_compiler.mmeta
  5. +5,536 −5,039 boot/parser.mirah
  6. +21 −18 boot/parser.mmeta
  7. +2 −2 boot/templates/action.xtm
  8. +9 −9 boot/templates/and.xtm
  9. +5 −2 boot/templates/build_list.xtm
  10. +5 −5 boot/templates/build_non_empty_list.xtm
  11. +8 −5 boot/templates/list.xtm
  12. +8 −6 boot/templates/list_items.xtm
  13. +10 −0 boot/templates/memo_rule.xtm
  14. +0 −1  boot/templates/method.xtm
  15. +8 −2 boot/templates/not.xtm
  16. +5 −2 boot/templates/opt.xtm
  17. +4 −4 boot/templates/or.xtm
  18. +8 −0 boot/templates/parser.xtm
  19. +2 −2 boot/templates/peek.xtm
  20. +1 −1  boot/templates/predicate.xtm
  21. +6 −0 boot/templates/recursive_rule.xtm
  22. +20 −0 boot/templates/rule.xtm
  23. +0 −14 boot/templates/rule_body.xtm
  24. +0 −2  boot/templates/rule_body_2.xtm
  25. +3 −2 boot/templates/save_to_var.xtm
  26. +1 −1  boot/templates/scope.xtm
  27. +7 −7 boot/templates/string_literal.xtm
  28. +5 −8 boot/templates/syn_pred.xtm
  29. +5 −0 boot/templates/syntax_error.xtm
  30. +1 −2  boot/templates/token_literal.xtm
  31. +8 −3 boot/templates/token_range.xtm
  32. +23 −0 license.hapax
  33. +120 −94 mmeta/BaseParser.java
  34. +1 −1  mmeta/{ErrorObject.java → RuleFailure.java}
  35. +5 −5 mmeta/SyntaxError.java
  36. +3 −0  mmeta/ast.mirah
  37. +10 −11 test/MirahCalculator.mmeta
  38. +1 −1  test/MirahLexer.java
  39. 0  test/ParserTest.mmeta
  40. +16 −2 test/TestParser.mmeta
  41. +25 −1 test/test_parser.rb
View
11 README.txt
@@ -32,8 +32,6 @@ TODO: allow parsers with custom constructors.
TODO: we could do without a runtime, by just creating inline classes, unless we
inherit a grammar.
TODO: implement a more fancy memoization schema, including argument support.
-TODO: experiment with throwing exceptions, instead of returning ERROR, see what
- is faster/safer.
TODO: change the syntax to be more mirah-like, or more OMeta like?
TODO: Create multiple parser classes - string, list, generic, token, etc.
@@ -96,10 +94,11 @@ consequences:
1. Methods must be surrounded with braces instead of using end.
2. When writing semantic expressions, make sure to match the curly braces. Even
-inside strings. you may need to add a closing brace inside a comment, just to
-balance the braces.
-3. Every variable is of type `Object`, and every rule returns an `Object` you
-have to cast it, maybe even inspect it using `instanceof`.
+ inside strings. you may need to add a closing brace inside a comment, just to
+ balance the braces.
+3. Memoized rules return Object by default. You either need to cast the result
+ or you can use $Memo[String] to declare a rule should be memoized and return
+ a string.
4. The parser throws a `SyntaxError` on error, which is not an `Exception`, but
an `Error`, so take care to catch it correctly.
View
6 Rakefile
@@ -26,7 +26,7 @@ file 'dist/mmeta-runtime.jar' => Dir.glob('mmeta/*.{java,mirah}') + ['build/runt
ant.jar :destfile=>'dist/mmeta-runtime.jar', :basedir=>'build/runtime'
end
-file 'build/boot/mmeta/MMetaParser.class' => ['boot/parser.mirah', 'build/boot/mmeta', 'dist/mmeta-runtime.jar'] do
+file 'build/boot/mmeta/MMetaParser.class' => ['boot/parser.mirah', 'build/boot/mmeta', 'dist/mmeta-runtime.jar' ] do
cp 'boot/parser.mirah', 'build/boot/mmeta/'
mirahc('mmeta/parser.mirah',
:dir => 'build/boot',
@@ -34,7 +34,7 @@ file 'build/boot/mmeta/MMetaParser.class' => ['boot/parser.mirah', 'build/boot/m
:options => ['--classpath', 'dist/mmeta-runtime.jar'])
end
-file 'build/boot/mmeta/MMetaCompiler.class' => ['boot/mirah_compiler.mirah', 'build/boot/mmeta', 'dist/mmeta-runtime.jar'] do
+file 'build/boot/mmeta/MMetaCompiler.class' => ['boot/mirah_compiler.mirah', 'build/boot/mmeta', 'dist/mmeta-runtime.jar' ] do
cp 'boot/mirah_compiler.mirah', 'build/boot/mmeta/'
mirahc('mmeta/mirah_compiler.mirah',
:dir => 'build/boot',
@@ -48,9 +48,9 @@ file 'dist/mmeta.jar' => ['dist/mmeta-runtime.jar',
cp_r 'boot/templates', 'build/boot/mmeta/'
ant.jar :destfile=>'dist/mmeta.jar' do
fileset :dir=>"build/boot", :includes=>"mmeta/*.class"
- fileset :dir=>"build/runtime", :includes=>"mmeta/*.class"
fileset :dir=>"build/boot", :includes=>"mmeta/templates/*.xtm"
zipfileset :includes=>"**/*.class", :src=>"javalib/hapax-2.3.5-autoindent.jar"
+ zipfileset :includes=>"mmeta/*.class", :src=>'dist/mmeta-runtime.jar'
manifest do
attribute :name=>"Main-Class", :value=>"mmeta.MMetaCompiler"
end
View
3,131 boot/mirah_compiler.mirah
@@ -1,40 +1,31 @@
-# generated by mmeta on Tue Apr 26 15:11:31 PDT 2011
+# generated by mmeta on Mon May 02 13:20:12 PDT 2011
# do not modify, instead edit original .mmeta file
import java.util.ArrayList
import java.util.Date
import java.util.List
import java.util.EnumSet
-import jmeta.*;
-
-
-import java.util.*;
-import hapax.TemplateDataDictionary;
-import hapax.TemplateDictionary;
-import hapax.TemplateResourceLoader;
-
-
- class DoError
-
- def initialize(m:Object)
- @msg = String(m)
- end
-
- def message
- @msg
- end
-
-end
+import mmeta.*
+import java.util.*
+import hapax.TemplateDataDictionary
+import hapax.TemplateDictionary
+import hapax.TemplateResourceLoader
class MMetaCompiler < BaseParser
def _init
-
+ @error = RuleFailure.new
@chars = _chars
super()
+ end
+ def _error(expected:String)
+ throws RuleFailure
+ @error.last = expected
+ raise @error
end
- def self.main(args:String[])
+ def self.main(args:String[])
+
returns void
if args.length < 1
puts "MMetaCompiler <input> [output]"
@@ -62,7 +53,7 @@ class MMetaCompiler < BaseParser
output_file = args[i] + ".mirah"
end
input = Utils.readFile(args[i])
-
+
compiler = MMetaCompiler.new
compiler.left_recursion = Boolean(options.get(:recursion)).booleanValue
compiler.auto_memo = Boolean(options.get(:auto_memo)).booleanValue
@@ -72,16 +63,16 @@ class MMetaCompiler < BaseParser
ast = parser.parse(input)
BaseParser.tracing = false
# puts BaseParser.print_r(ast)
-
+
output = String(compiler.parse(ast))
Utils.writeFile(output_file, output)
System.exit(0)
end
-
+
def initialize()
-
+
@jpackage = String(nil)
@embedded = false
@locals = ArrayList.new
@@ -97,1636 +88,1559 @@ class MMetaCompiler < BaseParser
@templates = TemplateResourceLoader.create('mmeta/templates/')
end
-
+
def left_recursion_set(value:boolean)
-
+
@left_recursion = value
end
-
+
def auto_memo_set(value:boolean)
-
+
@auto_memo = value
end
-
+
def reset()
-
+
@locals = ArrayList.new
@methods = ArrayList.new
@rules = ArrayList.new
end
-
+
def addLocal(n:Object)
-
+
s = String(n).intern
@locals.add(s) unless @locals.contains(s)
end
-
-
- def localsAsArgs()
-
- localsAsCall
-
- end
-
-
- def localsAsCall()
-
- join(@locals, ",")
-
- end
-
+
def localsAsInit()
-
- return '' if @locals.size == 0
- res = join(@locals, " = ") + " = Object(nil)\n"
+
+ @locals.each do |local|
+ @dict.addSection(:LOCALS).setVariable(:LOCAL, local.toString)
+ end
@locals.clear
- res
end
-
+
def embedded_set(embedded:boolean)
@embeded = embedded
end
-
+
def genvar()
"" + (@__genc = @__genc + 1);
end
-
-
- def destruct:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('destruct')
- t = r = Object(nil)
-
- begin # and
- _p0 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- t = _t
-
- raise SyntaxError.new("", _pos, _string, _list) if _t == BaseParser.__ERROR__
-
- _push(t); _t=self.apply();
- r = _t
-
- raise SyntaxError.new("", _pos, _string, _list) if _t == BaseParser.__ERROR__
-
- _t=self.end();
- raise SyntaxError.new("", _pos, _string, _list) if _t == BaseParser.__ERROR__
-
- _t=r;
- raise SyntaxError.new("", _pos, _string, _list) if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p0 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "destruct" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def trans:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('trans')
- r = Object(nil)
-
- __saved_dict = @dict
- begin # scope
- begin # and
- _p3 = _pos; _t=nil
- begin # and (inner)
- break if _t == BaseParser.__ERROR__
-
- _t = BaseParser.__ERROR__
- begin # or
- begin # and
- _p2 = _pos; _t=nil
- begin # and (inner)
- _t = _listBegin()
- if (_t != BaseParser.__ERROR__)
- _t = BaseParser.__ERROR__
- begin # or
- begin # and
- _p1 = _pos; _t=nil
- begin # and (inner)
- _t=self.destruct();
- r = _t
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p1 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- end while false
-
- _listEnd()
- end
-
- break if _t == BaseParser.__ERROR__
-
- _t=r;
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p2 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- end while false
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p3 if (_t==BaseParser.__ERROR__)
- end # and
-
- ensure
- @dict = __saved_dict
- end # scope
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "trans" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def HList:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('HList')
- ls = Object(nil)
-
- begin # and
- _p5 = _pos; _t=nil
- begin # and (inner)
- as4 = ArrayList.new
- while true # star
- _t=self.trans();
- if (_t == BaseParser.__ERROR__)
- break
- else
- as4.add(_t)
- nil
+
+
+
+ def destruct
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ t = nil
+ r = nil
+ begin
+ begin
+ _p0 = _pos
+ begin
+ t = (
+ self._any()
+ )
+ r = (
+ begin
+ _push([t].toArray)
+ self.apply()
+ end
+ )
+ self.end()
+ r
+ rescue RuleFailure => ex
+ self._pos = _p0
+ raise ex
end
end
- _t = as4
-
-
- ls = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- if List(ls).size == 0
- "ArrayList.new"
- else
- "[#{join(ls, ", ")}]"
+ rescue RuleFailure
+ raise SyntaxError.new("", @error.last, _pos, _string, _list)
+ end
+ rescue RuleFailure => ex
+ ex.last = 'destruct'
+ raise ex
+ end
+ end
+
+
+
+ def trans
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ r = nil
+ __saved_dict = @dict
+ begin # scope
+ begin
+ _p3 = _pos
+ begin
+
+ begin
+ _p2 = _pos
+ begin
+ begin
+ _t = _listBegin()
+ begin
+ begin
+ _p1 = _pos
+ begin
+ r = (
+ self.destruct()
+ )
+ rescue RuleFailure => ex
+ self._pos = _p1
+ raise ex
+ end
+ end
+ ensure
+ _listEnd()
+ end
end
-
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p5 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "HList" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def HConcat:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('HConcat')
- l = r = Object(nil)
-
- begin # and
- _p6 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- l = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- r = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="concat(#{l}, #{r})";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p6 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "HConcat" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def HStr:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('HStr')
- c = Object(nil)
-
- begin # and
- _p7 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- c = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="\"#{c}\"";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p7 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "HStr" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def HLit:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('HLit')
- c = Object(nil)
-
- begin # and
- _p8 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- c = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=c;
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p8 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "HLit" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Node:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Node')
- n = c = Object(nil)
-
- begin # and
- _p9 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- n = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- c = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="build_node('#{n}', #{c}, _real_start > 1 ? _real_start : _start, _pos)";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p9 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Node" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Error:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Error')
- msg = Object(nil)
-
- begin # and
- _p10 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- msg = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- DoError.new(msg);
-
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p10 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Error" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Set:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Set')
- n = x = Object(nil)
-
- begin # and
- _p11 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- n = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- x = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- addLocal(n);
- add_dict
- @dict.setVariable(:NAME, n.toString)
- add_expr(:EXPR, x)
- render(:save_to_var)
-
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p11 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Set" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Str:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Str')
- s = Object(nil)
-
- begin # and
- _p12 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- s = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
- compile_literal_string(s)
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p12 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Str" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Sym:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Sym')
- s = Object(nil)
-
- begin # and
- _p13 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- s = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="_t=_sym(\"#{s}\");";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p13 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Sym" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def App:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('App')
- rule = args = Object(nil)
-
- _t = BaseParser.__ERROR__
- begin # or
- begin # and
- _p15 = _pos; _t=nil
- begin # and (inner)
- _t=_sym("super");
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- rule = _t
-
- break if _t == BaseParser.__ERROR__
-
- as14 = ArrayList.new
- _t=self.trans();
- if (_t!=BaseParser.__ERROR__) # plus
- as14.add(_t)
- while true # star
- _t=self.trans();
- if (_t == BaseParser.__ERROR__)
- break
- else
- as14.add(_t)
- nil
+ r
+ rescue RuleFailure => ex
+ self._pos = _p2
+ raise ex
end
end
- _t = as14
-
+ rescue RuleFailure => ex
+ self._pos = _p3
+ raise ex
end
-
- args = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- arg_str = if List(args).size == 1
- join(args, ", ")
- else
- "[#{join(args, ", ")}].toArray"
- end
- "_push(#{arg_str}); _t=super();"
-
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p15 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- begin # and
- _p16 = _pos; _t=nil
- begin # and (inner)
- _t=_sym("super");
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- rule = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="_t=super();";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p16 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- begin # and
- _p18 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- rule = _t
-
- break if _t == BaseParser.__ERROR__
-
- as17 = ArrayList.new
- _t=self.trans();
- if (_t!=BaseParser.__ERROR__) # plus
- as17.add(_t)
- while true # star
- _t=self.trans();
- if (_t == BaseParser.__ERROR__)
- break
- else
- as17.add(_t)
- nil
- end
+ end
+ ensure
+ @dict = __saved_dict
+ end # scope
+ rescue RuleFailure => ex
+ ex.last = 'trans'
+ raise ex
+ end
+ end
+
+
+
+ def HList
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ ls = nil
+ begin
+ _p5 = _pos
+ begin
+ ls = (
+ begin
+ as4 = ArrayList.new
+ begin
+ while true do
+ _li = Object(
+ self.trans()
+ )
+ as4.add(_li)
+ end
+ rescue RuleFailure; end
+ as4
end
- _t = as17
-
- end
-
- args = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- arg_str = if List(args).size == 1
- join(args, ", ")
- else
- "[#{join(args, ", ")}].toArray"
- end
- "_push(#{arg_str}); _t=self.#{rule}();"
+ )
+ begin
+
+ if List(ls).size == 0
+ "ArrayList.new"
+ else
+ "[#{join(ls, ", ")}]"
+ end
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p18 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- begin # and
- _p19 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- rule = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="_t=self.#{rule}();";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p19 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- end while false
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "App" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Dot:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Dot')
- _t="if _start == _pos;_t=ws();_real_start=_pos;nil;else;_t=ws();end;";
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Dot" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def SAct:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('SAct')
- expr = Object(nil)
-
- begin # and
- _p20 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- expr = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="_t=#{expr};";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p20 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "SAct" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Act:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Act')
- expr = Object(nil)
-
- begin # and
- _p21 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- expr = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- add_dict
- add_expr(:BODY, expr)
- render(:action)
-
+ rescue RuleFailure => ex
+ self._pos = _p5
+ raise ex
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p21 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Act" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Pred:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Pred')
- expr = Object(nil)
-
- begin # and
- _p22 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- expr = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- add_dict
- @dict.setVariable(:EXPR, expr.toString)
- render('predicate')
-
+ end
+ rescue RuleFailure => ex
+ ex.last = 'HList'
+ raise ex
+ end
+ end
+
+
+
+ def HConcat
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ l = nil
+ r = nil
+ begin
+ _p6 = _pos
+ begin
+ l = (
+ self.trans()
+ )
+ r = (
+ self.trans()
+ )
+ "concat(#{l}, #{r})"
+ rescue RuleFailure => ex
+ self._pos = _p6
+ raise ex
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p22 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Pred" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def SynPred:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('SynPred')
- pred = t = e = Object(nil)
-
- begin # and
- _p23 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- pred = _t
-
- raise SyntaxError.new("", _pos, _string, _list) if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- t = _t
-
- raise SyntaxError.new("", _pos, _string, _list) if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- e = _t
-
- raise SyntaxError.new("", _pos, _string, _list) if _t == BaseParser.__ERROR__
-
- _t = begin
-
- add_dict
- add_expr(:PRED, pred)
- add_expr(:BODY, t)
- add_expr(:ELSE, e)
- render('syn_pred')
-
+ end
+ rescue RuleFailure => ex
+ ex.last = 'HConcat'
+ raise ex
+ end
+ end
+
+
+
+ def HStr
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ c = nil
+ begin
+ _p7 = _pos
+ begin
+ c = (
+ self._any()
+ )
+ "\"#{c}\""
+ rescue RuleFailure => ex
+ self._pos = _p7
+ raise ex
end
-
- raise SyntaxError.new("", _pos, _string, _list) if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p23 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "SynPred" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Token:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Token')
- name = Object(nil)
-
- begin # and
- _p24 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- name = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="_t = _lex(Tokens.t#{name})\n";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p24 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Token" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def TokenRange:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('TokenRange')
- first = last = Object(nil)
-
- begin # and
- _p25 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- first = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- last = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- range = lookup_range(first, last)
- add_dict
- @dict.setVariable(:FIRST, first.toString)
- @dict.setVariable(:LAST, last.toString)
- @dict.setVariable(:RANGE, range)
- render('token_range')
-
+ end
+ rescue RuleFailure => ex
+ ex.last = 'HStr'
+ raise ex
+ end
+ end
+
+
+
+ def HLit
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ c = nil
+ begin
+ _p8 = _pos
+ begin
+ c = (
+ self._any()
+ )
+ c
+ rescue RuleFailure => ex
+ self._pos = _p8
+ raise ex
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p25 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "TokenRange" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def TLit:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('TLit')
- name = Object(nil)
-
- begin # and
- _p26 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- name = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- token = Integer.valueOf(lookup_token(name))
- add_dict
- @dict.setVariable(:NAME, name.toString)
- @dict.setVariable(:TOKEN, token.toString)
-
+ end
+ rescue RuleFailure => ex
+ ex.last = 'HLit'
+ raise ex
+ end
+ end
+
+
+
+ def Node
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ n = nil
+ c = nil
+ begin
+ _p9 = _pos
+ begin
+ n = (
+ self._any()
+ )
+ c = (
+ self.trans()
+ )
+ "build_node('#{n}', #{c}, _real_start > 1 ? _real_start : _start, _pos)"
+ rescue RuleFailure => ex
+ self._pos = _p9
+ raise ex
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p26 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "TLit" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Or:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Or')
- xs = Object(nil)
-
- begin # and
- _p28 = _pos; _t=nil
- begin # and (inner)
- as27 = ArrayList.new
- while true # star
- _t=self.trans();
- if (_t == BaseParser.__ERROR__)
- break
- else
- as27.add(_t)
- nil
+ end
+ rescue RuleFailure => ex
+ ex.last = 'Node'
+ raise ex
+ end
+ end
+
+
+
+ def Error
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ msg = nil
+ body = nil
+ begin
+ _p10 = _pos
+ begin
+ msg = (
+ self._any()
+ )
+ body = (
+ self.trans()
+ )
+ begin
+
+ add_dict
+ @dict.setVariable(:MESSAGE, msg.toString)
+ add_expr(:BODY, body)
+ render(:syntax_error)
+
end
+ rescue RuleFailure => ex
+ self._pos = _p10
+ raise ex
end
- _t = as27
-
-
- xs = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- dict = add_dict
- List(xs).each do |expr|
- @dict = dict.addSection(:EXPR)
- add_expr(:EXPR, expr)
- end
- render('or', dict)
-
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p28 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Or" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def And:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('And')
- ts = Object(nil)
-
- _t = BaseParser.__ERROR__
- begin # or
- begin # and
- _p30 = _pos; _t=nil
- begin # and (inner)
- as29 = ArrayList.new
- _t=self.trans();
- if (_t!=BaseParser.__ERROR__) # plus
- as29.add(_t)
- while true # star
- _t=self.trans();
- if (_t == BaseParser.__ERROR__)
- break
- else
- as29.add(_t)
- nil
- end
- end
- _t = as29
-
- end
-
- ts = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- dict = add_dict
- @dict.setVariable(:VAR, genvar)
- err = String(nil)
- List(ts).each do |expr|
- if expr.kind_of?(DoError)
- err = DoError(expr).message
- next
- end
- @dict = dict.addSection(:EXPR)
- if err
- @dict.setVariable(:ERROR, err)
- else
- @dict.showSection(:NO_ERROR)
- end
- add_expr(:EXPR, expr)
- end
- render('and', dict)
+ end
+ rescue RuleFailure => ex
+ ex.last = 'Error'
+ raise ex
+ end
+ end
+
+
+
+ def Set
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ n = nil
+ x = nil
+ begin
+ _p11 = _pos
+ begin
+ n = (
+ self._any()
+ )
+ x = (
+ self.trans()
+ )
+ begin
+
+ addLocal(n);
+ add_dict
+ @dict.setVariable(:NAME, n.toString)
+ add_expr(:EXPR, x)
+ render(:save_to_var)
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p30 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- _t="";
- break unless _t == BaseParser.__ERROR__
- end while false
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "And" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def makeMany(x:Object, many1:boolean)
-
- add_dict
- @dict.setVariable(:VAR, genvar)
- @dict.setVariable(:LIST_ITEMS, :list_items)
- add_expr(:EXPR, x)
- add_expr(:EXPR, x, @dict.addSection(:LIST_ITEMS))
- if many1
- render('build_non_empty_list')
- else
- render('build_list')
- end
-
- end
-
-
- def Many:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Many')
- x = Object(nil)
-
- begin # and
- _p31 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- x = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
- makeMany(x, false)
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p31 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Many" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Many1:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Many1')
- x = Object(nil)
-
- begin # and
- _p32 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- x = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
- makeMany(x, true)
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p32 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Many1" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Opt:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Opt')
- x = Object(nil)
-
- begin # and
- _p33 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- x = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- add_dict
- add_expr(:EXPR, x)
- render('opt')
-
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p33 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Opt" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Not:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Not')
- x = Object(nil)
-
- begin # and
- _p34 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- x = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- add_dict
- add_expr(:EXPR, x)
- render('not')
-
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p34 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Not" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Peek:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Peek')
- x = Object(nil)
-
- begin # and
- _p35 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- x = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- add_dict
- @dict.setVariable(:VAR, genvar)
- add_expr(:EXPR, x)
- render('peek')
-
- end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p35 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Peek" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def List:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('List')
- x = Object(nil)
-
- begin # and
- _p36 = _pos; _t=nil
- begin # and (inner)
- _t=self.trans();
- x = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- add_dict
- add_expr(:EXPR, x)
- render('list')
-
+ rescue RuleFailure => ex
+ self._pos = _p11
+ raise ex
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p36 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "List" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def MemoRule:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('MemoRule')
- n = b = Object(nil)
-
- begin # and
- _p37 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- n = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- b = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- rule_body(n, b, true)
-
+ end
+ rescue RuleFailure => ex
+ ex.last = 'Set'
+ raise ex
+ end
+ end
+
+
+
+ def Str
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ s = nil
+ begin
+ _p12 = _pos
+ begin
+ s = (
+ self._any()
+ )
+ begin
+ compile_literal_string(s)
+ end
+ rescue RuleFailure => ex
+ self._pos = _p12
+ raise ex
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p37 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "MemoRule" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Rule:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Rule')
- n = b = Object(nil)
-
- begin # and
- _p38 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- n = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- b = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- rule_body(n, b, false)
+ end
+ rescue RuleFailure => ex
+ ex.last = 'Str'
+ raise ex
+ end
+ end
+
+
+
+ def Sym
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ s = nil
+ begin
+ _p13 = _pos
+ begin
+ s = (
+ self._any()
+ )
+ "_sym(\"#{s}\")"
+ rescue RuleFailure => ex
+ self._pos = _p13
+ raise ex
+ end
+ end
+ rescue RuleFailure => ex
+ ex.last = 'Sym'
+ raise ex
+ end
+ end
+
+
+
+ def App
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ rule = nil
+ args = nil
+ begin
+ begin
+ _p15 = _pos
+ begin
+ _sym("super")
+ rule = (
+ self._any()
+ )
+ args = (
+ begin
+ as14 = ArrayList.new
+ begin
+ while true do
+ _li = Object(
+ self.trans()
+ )
+ as14.add(_li)
+ end
+ rescue RuleFailure; end
+ raise @error if as14.size == 0
+ as14
+ end
+ )
+ begin
+ arg_str = "[#{join(args, ", ")}].toArray"
+ "begin\n _push(#{arg_str})\n super()\nend"
+
+ end
+ rescue RuleFailure => ex
+ self._pos = _p15
+ raise ex
+ end
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p38 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Rule" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Scope:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Scope')
- names = body = Object(nil)
-
- begin # and
- _p39 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- names = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- body = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- add_dict
- add_expr(:BODY, body)
- l = if names.kind_of?(List)
- List(names)
- else
- Arrays.asList(Object[].cast(names))
- end
- l.each do |_name|
- name = String(_name)
- dict = @dict.addSection(:VARS)
- dict.setVariable(:NAME, name)
- dict.setVariable(:SIMPLE_NAME, name.replace('@', ''))
+ rescue RuleFailure
+ begin
+ begin
+ _p16 = _pos
+ begin
+ _sym("super")
+ rule = (
+ self._any()
+ )
+ "super()"
+ rescue RuleFailure => ex
+ self._pos = _p16
+ raise ex
+ end
+ end
+ rescue RuleFailure
+ begin
+ begin
+ _p18 = _pos
+ begin
+ rule = (
+ self._any()
+ )
+ args = (
+ begin
+ as17 = ArrayList.new
+ begin
+ while true do
+ _li = Object(
+ self.trans()
+ )
+ as17.add(_li)
+ end
+ rescue RuleFailure; end
+ raise @error if as17.size == 0
+ as17
+ end
+ )
+ begin
+
+ arg_str = "[#{join(args, ", ")}].toArray"
+ "begin\n _push(#{arg_str})\n self.#{rule}()\nend"
+
end
- render('scope')
-
+ rescue RuleFailure => ex
+ self._pos = _p18
+ raise ex
+ end
+ end
+ rescue RuleFailure
+ begin
+ _p19 = _pos
+ begin
+ rule = (
+ self._any()
+ )
+ "self.#{rule}()"
+ rescue RuleFailure => ex
+ self._pos = _p19
+ raise ex
+ end
+ end
+ end
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p39 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Scope" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Parser:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Parser')
- p = n = s = xs = Object(nil)
-
- begin # and
- _p41 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- p = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- n = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- s = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
- @name = String(n); @sname = String(s)
+ end
+ rescue RuleFailure => ex
+ ex.last = 'App'
+ raise ex
+ end
+ end
+
+
+
+ def Dot
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ "if _start == _pos;ws();_real_start=_pos;nil;else;ws();nil;end"
+ rescue RuleFailure => ex
+ ex.last = 'Dot'
+ raise ex
+ end
+ end
+
+
+
+ def SAct
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ expr = nil
+ begin
+ _p20 = _pos
+ begin
+ expr = (
+ self.trans()
+ )
+ "#{expr}"
+ rescue RuleFailure => ex
+ self._pos = _p20
+ raise ex
end
-
- break if _t == BaseParser.__ERROR__
-
- as40 = ArrayList.new
- while true # star
- _t=self.trans();
- if (_t == BaseParser.__ERROR__)
- break
- else
- as40.add(_t)
- nil
+ end
+ rescue RuleFailure => ex
+ ex.last = 'SAct'
+ raise ex
+ end
+ end
+
+
+
+ def Act
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ expr = nil
+ begin
+ _p21 = _pos
+ begin
+ expr = (
+ self._any()
+ )
+ begin
+
+ add_dict
+ add_expr(:BODY, expr)
+ render(:action)
+
end
+ rescue RuleFailure => ex
+ self._pos = _p21
+ raise ex
end
- _t = as40
-
-
- xs = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
- dict = add_dict
- build_init
- @rules.each do |name|
- @dict.addSection(:RULE).setVariable(:RULE, String(name))
- end
- @dict.setVariable(:PARSER, @name)
- @dict.setVariable(:SUPERCLASS, @sname)
- List(xs).each do |expr|
- @dict = dict.addSection(:BODY)
- add_expr(:BODY, expr)
+ end
+ rescue RuleFailure => ex
+ ex.last = 'Act'
+ raise ex
+ end
+ end
+
+
+
+ def Pred
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ expr = nil
+ begin
+ _p22 = _pos
+ begin
+ expr = (
+ self._any()
+ )
+ begin
+
+ add_dict
+ unless expr.nil? || "false".equals(expr.toString.trim)
+ @dict.setVariable(:EXPR, expr.toString)
+ end
+ render('predicate')
+
+ end
+ rescue RuleFailure => ex
+ self._pos = _p22
+ raise ex
+ end
+ end
+ rescue RuleFailure => ex
+ ex.last = 'Pred'
+ raise ex
+ end
+ end
+
+
+
+ def SynPred
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ pred = nil
+ body = nil
+ tail = nil
+ begin
+ begin
+ _p24 = _pos
+ begin
+ pred = (
+ self.trans()
+ )
+ body = (
+ self.trans()
+ )
+ tail = (
+ begin
+ self.trans()
+ rescue RuleFailure
+ begin
+ _p23 = _pos
+ begin
+ self.end()
+ nil
+ rescue RuleFailure => ex
+ self._pos = _p23
+ raise ex
+ end
end
- b = render('parser', dict)
- reset
- b
+ end
+ )
+ begin
+ add_dict
+ add_expr(:PRED, pred)
+ add_expr(:BODY, body)
+ unless tail.nil?
+ add_expr(:ELSE, tail, @dict.addSection(:ELSE))
+ end
+ render('syn_pred')
+
+ end
+ rescue RuleFailure => ex
+ self._pos = _p24
+ raise ex
+ end
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p41 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Parser" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Method:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Method')
- name = args = body = c = Object(nil)
-
- _t = BaseParser.__ERROR__
- begin # or
- begin # and
- _p42 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- name = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- args = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- body = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
-
+ rescue RuleFailure
+ raise SyntaxError.new("", @error.last, _pos, _string, _list)
+ end
+ rescue RuleFailure => ex
+ ex.last = 'SynPred'
+ raise ex
+ end
+ end
+
+
+
+ def Token
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ name = nil
+ begin
+ _p25 = _pos
+ begin
+ name = (
+ self._any()
+ )
+ "_lex(Tokens.t#{name})"
+ rescue RuleFailure => ex
+ self._pos = _p25
+ raise ex
+ end
+ end
+ rescue RuleFailure => ex
+ ex.last = 'Token'
+ raise ex
+ end
+ end
+
+
+
+ def TokenRange
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ first = nil
+ last = nil
+ begin
+ _p26 = _pos
+ begin
+ first = (
+ self._any()
+ )
+ last = (
+ self._any()
+ )
+ begin
+
+ range = lookup_range(first, last)
+ add_dict
+ @dict.setVariable(:FIRST, first.toString)
+ @dict.setVariable(:LAST, last.toString)
+ @dict.setVariable(:RANGE, range)
+ render('token_range')
+
+ end
+ rescue RuleFailure => ex
+ self._pos = _p26
+ raise ex
+ end
+ end
+ rescue RuleFailure => ex
+ ex.last = 'TokenRange'
+ raise ex
+ end
+ end
+
+
+
+ def TLit
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ name = nil
+ begin
+ _p27 = _pos
+ begin
+ name = (
+ self._any()
+ )
+ begin
+
+ token = Integer.valueOf(lookup_token(name))
add_dict
@dict.setVariable(:NAME, name.toString)
- @dict.setVariable(:ARGS, args.toString)
- add_expr(:BODY, body)
- render('method')
+ @dict.setVariable(:TOKEN, token.toString)
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p42 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- begin # and
- _p43 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- c = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=" #{c}\n";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p43 if (_t==BaseParser.__ERROR__)
- end # and
-
- break unless _t == BaseParser.__ERROR__
- end while false
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Method" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Field:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Field')
- c = Object(nil)
-
- begin # and
- _p44 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- c = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=" #{c}\n";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p44 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Field" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Package:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Package')
- c = Object(nil)
-
- begin # and
- _p45 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- c = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
- @jpackage = String(c); "";
+ rescue RuleFailure => ex
+ self._pos = _p27
+ raise ex
end
-
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p45 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Package" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Import:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Import')
- c = Object(nil)
-
- begin # and
- _p46 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- c = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=c;
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p46 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Import" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Class:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Class')
- q = d = c = Object(nil)
-
- begin # and
- _p47 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- q = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- d = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self._any();
- c = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t="#{d}\n#{c}\n end";
- break if _t == BaseParser.__ERROR__
-
- end while false # and (inner)
- self._pos=_p47 if (_t==BaseParser.__ERROR__)
- end # and
-
- _t = _exit(_t)
- BaseParser.__ERROR__.last = "Class" if (_t==BaseParser.__ERROR__)
- return _t
- end
-
- def Line:Object
- _t = Object(nil); _start = _pos; _real_start = -1
- _enter('Line')
- ws = x = Object(nil)
-
- begin # and
- _p48 = _pos; _t=nil
- begin # and (inner)
- _t=self._any();
- ws = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t=self.trans();
- x = _t
-
- break if _t == BaseParser.__ERROR__
-
- _t = begin
- ws.toString + x.toString
+ end
+ rescue RuleFailure => ex
+ ex.last = 'TLit'
+ raise ex
+ end
+ end
+
+
+
+ def Or
+ throws RuleFailure
+ begin
+ _start = _pos; _real_start = -1
+ xs = nil
+ begin
+ _p29 = _pos
+ begin
+ xs = (
+ begin
+ as28 = ArrayList.new
+ begin
+ while true do
+ _li = Object(
+ self.trans()
+