Module: LLIP::AbstractParser::ClassMethods
- Defined in:
- lib/llip/abstract_parser.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Contains the evaluated code, it’s useful for debugging.
Instance Method Summary collapse
-
#autocompile(autocompile = nil) ⇒ Object
:call-seq: autocompile(true) autocompile(false).
-
#compile ⇒ Object
Compile all the productions and sets the code attribute correctly.
-
#compiled ⇒ Object
Returns a boolean which specify if the parser has been compiled.
-
#production(name, mode = nil) {|| ... } ⇒ Object
Add a production to the parser, the block must accept an argument which is a new ProductionSpecification.
-
#productions ⇒ Object
Return an hash containing all the specified productions.
-
#scope(name = nil) ⇒ Object
Return/set the scope, which is the first production to be called.
Instance Attribute Details
#code ⇒ Object (readonly)
Contains the evaluated code, it’s useful for debugging.
57 58 59 |
# File 'lib/llip/abstract_parser.rb', line 57 def code @code end |
Instance Method Details
#autocompile(autocompile = nil) ⇒ Object
:call-seq: autocompile(true) autocompile(false)
Set the autocompile flag true or false. The default is true. If this flag is turned on every production is automatically evaulated and converted into code. Otherwise you can compile it using AbstractParser::ClassMethods#compile.
66 67 68 69 70 71 72 73 74 |
# File 'lib/llip/abstract_parser.rb', line 66 def autocompile(autocompile=nil) if not autocompile.nil? @autocompile = autocompile else @autocompile = true if @autocompile.nil? end init_compile if @autocompile @autocompile end |
#compile ⇒ Object
Compile all the productions and sets the code attribute correctly.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/llip/abstract_parser.rb', line 105 def compile init_compile #first check the scope if @scope.nil? or not @productions.has_key? @scope.to_sym raise "You must give a legal scope" end compile_scope #compile and eval all the productions @productions.values.each { |prod| compile_production(prod) } class_eval(@code) @compiled = true end |
#compiled ⇒ Object
Returns a boolean which specify if the parser has been compiled
124 125 126 |
# File 'lib/llip/abstract_parser.rb', line 124 def compiled @compiled ||= false end |
#production(name, mode = nil) {|| ... } ⇒ Object
Add a production to the parser, the block must accept an argument which is a new ProductionSpecification. The ProductionSpecficiation name is set to the first parameter and its mode to the second if exists. A ProductionSpecification is compiled to a method named parse_name
80 81 82 83 84 85 86 |
# File 'lib/llip/abstract_parser.rb', line 80 def production(name,mode=nil) # :yields: production_specification productions[name.to_sym] ||= LLIP::ProductionSpecification.new(name.to_sym) productions[name.to_sym].mode = mode if mode yield productions[name.to_sym] compile_production(productions[name.to_sym]) if autocompile name end |
#productions ⇒ Object
Return an hash containing all the specified productions
89 90 91 |
# File 'lib/llip/abstract_parser.rb', line 89 def productions @productions ||= {} end |
#scope(name = nil) ⇒ Object
Return/set the scope, which is the first production to be called. The scope is mandatory to generate the parse method.
95 96 97 98 99 100 101 102 |
# File 'lib/llip/abstract_parser.rb', line 95 def scope(name=nil) if name raise ArgumentError.new("The scope must be a not empty string") if name == "" @scope = name compile_scope if autocompile end @scope end |