Class Voodoo::Parser
In: voodoo/parser.rb
Parent: Object

Voodoo parser. The parser reads Voodoo source code and turns it into Ruby objects.

The public interface to Parser consists of the methods new and parse_top_level

Example usage:

  require 'voodoo/parser'

  File.open('example.voo') do |infile|
    parser = Voodoo::Parser.new infile

    while (element = parser.parse_top_level)
      puts element.inspect
    end
  end

Methods

Classes and Modules

Class Voodoo::Parser::Error
Class Voodoo::Parser::MultipleErrors
Class Voodoo::Parser::ParseError
Class Voodoo::Parser::ParserInternalError

Public Class methods

Creates a parser using the specified object as input. The input object must support a method getc, which must return the next character of the input, or nil to indicate the end of the input has been reached.

Public Instance methods

Parses a body for a function or a conditional

Parses an escape sequence. This method should be called while the lookahead is the escape character (backslash). It decodes the escape sequence and returns the result as a string.

Parses a number. This method should be called while the lookahead is the first character of the number.

Parses a string. This method should be called while the lookahead is the opening double quote.

Parses a symbol. This method should be called while the lookahead is the first character of the symbol name.

Parses a top-level element. Returns an array containing the parts of the element.

Some examples (Voodoo code, Ruby return values in comments):

  section functions
  # [:section, :functions]

  call foo x 12
  # [:call, :foo, :x, 12]

  set x add x 42
  # [:set, :x, :add, :x, 42]

  set-byte @x 1 10
  # [:"set-byte", [:"@", :x], 1, 10]

  ifeq x y
      set z equal
  else
      set z not-equal
  end if
  # [:ifeq, [:x, :y], [[:set, :z, :equal]], [[:set, :z, :"not-equal"]]]

  foo:
  # [:label, :foo]

  function x y
      let z add x y
      return z
  end function
  # [:function, [:x, :y], [:let, :z, :add, :x, :y], [:return, :z]]

[Validate]