Method: Parser::Base#initialize

Defined in:
lib/parser/base.rb

#initialize(builder = Parser::Builders::Default.new) ⇒ Base

Returns a new instance of Base.

Parameters:

  • builder (Parser::Builders::Default) (defaults to: Parser::Builders::Default.new)

    The AST builder to use.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/parser/base.rb', line 129

def initialize(builder=Parser::Builders::Default.new)
  @diagnostics = Diagnostic::Engine.new

  @static_env  = StaticEnvironment.new

  # Stack that holds current parsing context
  @context = Context.new

  # Maximum numbered parameters stack
  @max_numparam_stack = MaxNumparamStack.new

  # Current argument names stack
  @current_arg_stack = CurrentArgStack.new

  # Stack of set of variables used in the current pattern
  @pattern_variables = VariablesStack.new

  # Stack of set of keys used in the current hash in pattern matchinig
  @pattern_hash_keys = VariablesStack.new

  @lexer = Lexer.new(version)
  @lexer.diagnostics = @diagnostics
  @lexer.static_env  = @static_env
  @lexer.context     = @context

  @builder = builder
  @builder.parser = self

  # Last emitted token
  @last_token = nil

  if self.class::Racc_debug_parser && ENV['RACC_DEBUG']
    @yydebug = true
  end

  reset
end