class Farts::Lexer

The Lexer class converts the text of a program to tokens

token

is the current token being assembled

Constants

Keywords

Table of keywords and token type values

Public Class Methods

new(str) click to toggle source
# File lib/farts/farts_lexer.rb, line 24
def initialize(str)
  @token = [:UNKNOWN, nil]
  super(str)
end

Public Instance Methods

lineno() click to toggle source
# File lib/farts/farts_lexer.rb, line 53
def lineno
  string[0,pos].count("\n") + 1
end
next_token() click to toggle source
# File lib/farts/farts_lexer.rb, line 29
def next_token
  @token = [:UNKNOWN, nil]
  scan(%r\s+/)
  check_unary if @token[0] == :UNKNOWN
  check_binary if @token[0] == :UNKNOWN
  check_string if @token[0] == :UNKNOWN
  check_numeric if @token[0] == :UNKNOWN
  check_ident if @token[0] == :UNKNOWN
  if @token[0] == :COMMENT
    @token[1] += skip_line
  end
  if @token[0] == :UNKNOWN
    @token[1] = scan_until(%r\s+/)
  end
  return [false,false] if eos?
  return @token
end
tokenpos() click to toggle source
# File lib/farts/farts_lexer.rb, line 47
def tokenpos
  p = string[0,pos].rindex("\n")
  p = -1 if !p
  pos - p
end