Class: Fusion::Lexer

Inherits:
Object
  • Object
show all
Defined in:
lib/fusion/lexer.rb

Constant Summary collapse

PUNCT =
{
  "(" => :lparen, ")" => :rparen,
  "[" => :lbracket, "]" => :rbracket,
  "{" => :lbrace, "}" => :rbrace,
  "," => :comma, ":" => :colon,
  "?" => :question, "." => :dot,
  "@" => :at, "/" => :slash,
  "=" => :equals,
  "+" => :plus, "-" => :minus, "*" => :star,
  "%" => :percent, "~" => :tilde,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ Lexer

Returns a new instance of Lexer.



25
26
27
28
29
# File 'lib/fusion/lexer.rb', line 25

def initialize(src)
  @src = src
  @i = 0
  @n = src.length
end

Instance Method Details

#tokensObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fusion/lexer.rb', line 31

def tokens
  out = []
  loop do
    t = next_token
    out << t
    # A file-reference path is one tight token, lexed only right after `@`/`@@`.
    if t.type == :at || t.type == :atat
      p = try_lex_path
      out << p unless p.nil?
    end
    break if t.type == :eof
  end
  out
end