Class Farts::Lexer
In: lib/farts/farts_lexer.rb
Parent: StringScanner
SyntaxNode
LiteralSyntaxNode
ProgramSyntaxNode
AttributeSyntaxNode
IfSyntaxNode
CommentSyntaxNode
EndSyntaxNode
LocalVarSyntaxNode
CallSyntaxNode
CommandSyntaxNode
Racc::Parser
Parser
StringScanner
Lexer
Lib
Interpreter
Farts
dot/f_21.png

The Lexer class converts the text of a program to tokens

token
is the current token being assembled

Methods

lineno   new   next_token   tokenpos  

Constants

Keywords = %w(if else endif and or end args actor this true false)   Table of keywords and token type values

Public Class methods

[Source]

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

Public Instance methods

[Source]

# File lib/farts/farts_lexer.rb, line 53
  def lineno
    string[0,pos].count("\n") + 1
  end

[Source]

# File lib/farts/farts_lexer.rb, line 29
  def next_token
    @token = [:UNKNOWN, nil]
    scan(/\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(/\s+/)
    end
    return [false,false] if eos?
    return @token
  end

[Source]

# File lib/farts/farts_lexer.rb, line 47
  def tokenpos
    p = string[0,pos].rindex("\n")
    p = -1 if !p
    pos - p
  end

[Validate]