Class: Nay::Lexer
- Inherits:
-
Object
- Object
- Nay::Lexer
- Defined in:
- lib/nay/lexer.rb
Overview
Read in a string and generate Token instances.
Constant Summary collapse
- EXPRESSION =
Stack States
:expression
- EXPRESSION_LITERAL =
:expression_literal
- CLOSE_EXPRESSION =
Token Types
:close_expression
- CONTENT =
:content
- END_EXPRESSION_LITERAL =
:end_expression_literal
- IDENTIFIER =
:identifier
- IGNORE =
:ignore
- OPEN_EXPRESSION =
:open_expression
- OPEN_EXPRESSION_LITERAL =
:open_expression_literal
Instance Attribute Summary collapse
-
#scanner ⇒ Object
readonly
Returns the value of attribute scanner.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize(string) ⇒ Lexer
constructor
A new instance of Lexer.
- #next_token ⇒ Object
- #rest ⇒ Object
Constructor Details
Instance Attribute Details
#scanner ⇒ Object (readonly)
Returns the value of attribute scanner.
22 23 24 |
# File 'lib/nay/lexer.rb', line 22 def scanner @scanner end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
22 23 24 |
# File 'lib/nay/lexer.rb', line 22 def state @state end |
Instance Method Details
#next_token ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nay/lexer.rb', line 37 def next_token return nil if scanner.eos? case state.current when State::DEFAULT default when EXPRESSION expression when EXPRESSION_LITERAL expression_literal end end |
#rest ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/nay/lexer.rb', line 29 def rest [].tap do |tokens| while (token = next_token) tokens << token end end end |