Class: Lexer
- Inherits:
-
Object
- Object
- Lexer
- Defined in:
- lib/lasp/lexer.rb
Constant Summary collapse
- TOKENS =
[ /\(|\)/, # parens /'/, # quote /"(\\"|[^"])*"/, # string literal /[^\s)]+/, # any non-whitespace character excluding ) ]
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(program) ⇒ Lexer
constructor
A new instance of Lexer.
- #tokenize ⇒ Object
Constructor Details
#initialize(program) ⇒ Lexer
Returns a new instance of Lexer.
15 16 17 |
# File 'lib/lasp/lexer.rb', line 15 def initialize(program) @scanner = StringScanner.new(sanitize(program)) end |
Class Method Details
.tokenize(program) ⇒ Object
11 12 13 |
# File 'lib/lasp/lexer.rb', line 11 def self.tokenize(program) new(program).tokenize end |
Instance Method Details
#tokenize ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/lasp/lexer.rb', line 19 def tokenize tokens = [] while (token = read_token) tokens << token end tokens end |