Class: Peruby::Lexer::State
- Inherits:
-
Object
- Object
- Peruby::Lexer::State
- Defined in:
- lib/peruby/lexer/state.rb
Overview
Tracks whether the lexer expects a term, operator, statement, block, or reference.
Defined Under Namespace
Classes: Frame
Constant Summary collapse
- STATES =
%i[state term operator block ref].freeze
Instance Attribute Summary collapse
-
#brackets ⇒ Object
readonly
Returns the value of attribute brackets.
-
#expect ⇒ Object
Returns the value of attribute expect.
Instance Method Summary collapse
- #block! ⇒ Object
-
#initialize ⇒ State
constructor
A new instance of State.
- #operator! ⇒ Object
- #pop(close) ⇒ Object
- #push(open, kind, line) ⇒ Object
- #statement! ⇒ Object
- #term! ⇒ Object
Constructor Details
#initialize ⇒ State
Returns a new instance of State.
13 14 15 16 |
# File 'lib/peruby/lexer/state.rb', line 13 def initialize @expect = :state @brackets = [] end |
Instance Attribute Details
#brackets ⇒ Object (readonly)
Returns the value of attribute brackets.
10 11 12 |
# File 'lib/peruby/lexer/state.rb', line 10 def brackets @brackets end |
#expect ⇒ Object
Returns the value of attribute expect.
11 12 13 |
# File 'lib/peruby/lexer/state.rb', line 11 def expect @expect end |
Instance Method Details
#block! ⇒ Object
41 42 43 |
# File 'lib/peruby/lexer/state.rb', line 41 def block! @expect = :block end |
#operator! ⇒ Object
33 34 35 |
# File 'lib/peruby/lexer/state.rb', line 33 def operator! @expect = :term end |
#pop(close) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/peruby/lexer/state.rb', line 22 def pop(close) frame = @brackets.pop raise CompileError, "Unmatched #{close}" unless frame frame end |
#push(open, kind, line) ⇒ Object
18 19 20 |
# File 'lib/peruby/lexer/state.rb', line 18 def push(open, kind, line) @brackets << Frame.new(open, kind, line) end |
#statement! ⇒ Object
37 38 39 |
# File 'lib/peruby/lexer/state.rb', line 37 def statement! @expect = :state end |
#term! ⇒ Object
29 30 31 |
# File 'lib/peruby/lexer/state.rb', line 29 def term! @expect = :operator end |