Class: Mlc::ParserState

Inherits:
Object
  • Object
show all
Defined in:
lib/mlc/parserstate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, inherit = true) ⇒ ParserState

Returns a new instance of ParserState.



6
7
8
9
10
11
# File 'lib/mlc/parserstate.rb', line 6

def initialize(parent = nil, inherit = true)
  @tmpid = -1
  @lvars = []
  @parent = parent
  @inherit = inherit
end

Instance Attribute Details

#lvarsObject (readonly)

Returns the value of attribute lvars.



4
5
6
# File 'lib/mlc/parserstate.rb', line 4

def lvars
  @lvars
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/mlc/parserstate.rb', line 4

def parent
  @parent
end

Instance Method Details

#add_lvar(name) ⇒ Object



17
18
19
20
21
# File 'lib/mlc/parserstate.rb', line 17

def add_lvar(name)
  unless knows_lvar? name
    @lvars << name
  end
end

#knows_lvar?(name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/mlc/parserstate.rb', line 23

def knows_lvar?(name)
  @lvars.include? name || (@inherit && @parent && @parent.knows_lvar?(name))
end

#lvars_defineObject



27
28
29
# File 'lib/mlc/parserstate.rb', line 27

def lvars_define
  @lvars.map{|el| 'l' + el.to_s}.join(', ')
end

#tmpvarObject



13
14
15
# File 'lib/mlc/parserstate.rb', line 13

def tmpvar
  "__tmp_#{@tmpid += 1}"
end