Class SDL4R::Parser

  1. lib/sdl4r/parser.rb
  2. lib/sdl4r/parser/reader.rb
  3. lib/sdl4r/parser/token.rb
  4. lib/sdl4r/parser/tokenizer.rb
  5. lib/sdl4r/parser/time_span_with_zone.rb
  6. show all
Parent: Object

The SDL parser.

In Ruby 1.8, in order to enable UTF-8 support, you may have to declare the following lines:

$KCODE = 'u'
require 'jcode'

This will give you correct input and output and correct UTF-8 “general” sorting. Alternatively you can use the following options when launching the Ruby interpreter:

/path/to/ruby -Ku -rjcode

Authors

Daniel Leuck, Philippe Vosges

Methods

public class

  1. new

public instance

  1. new_date_time
  2. parse

Constants

UNKNOWN_POSITION = -2   Passed to parse_error() in order to specify an error that occured on no specific position (column).

Public class methods

new (io)

Creates an SDL parser on the specified IO.

IO.open("path/to/sdl_file") { |io|
  parser = SDL4R::Parser.new(io)
  tags = parser.parse()
}
[show source]
    # File lib/sdl4r/parser.rb, line 59
59:     def initialize(io)
60:       raise ArgumentError, "io == nil" if io.nil?
61:                         
62:       @tokenizer = Tokenizer.new(io)
63:     end

Public instance methods

new_date_time (year, month, day, hour, min, sec, time_zone_offset)

Creates and returns the object representing a datetime (DateTime in the default implementation). Can be overriden.

def new_date_time(year, month, day, hour, min, sec, time_zone_offset)
  Time.utc(year, month, day, hour, min, sec)
end
[show source]
     # File lib/sdl4r/parser.rb, line 105
105:     def new_date_time(year, month, day, hour, min, sec, time_zone_offset)
106:       SDL4R::new_date_time(year, month, day, hour, min, sec, time_zone_offset)
107:     end
parse ()

Parses the underlying IO and returns an Array of Tag.

Errors

IOError
If a problem is encountered with the IO
SdlParseError
If the document is malformed
[show source]
    # File lib/sdl4r/parser.rb, line 70
70:     def parse
71:       tags = []
72:                         
73:       while tokens = @tokenizer.read_line_tokens()
74:         if tokens.last.type == :START_BLOCK
75:           # tag with a block
76:           tag = construct_tag(tokens[0...-1])
77:           add_children(tag)
78:           tags << tag
79: 
80:         elsif tokens.first.type == :END_BLOCK
81:           # we found an block end token that should have been consumed by
82:           # add_children() normally
83:           parse_error(
84:             "No opening block ({) for close block (}).",
85:             tokens.first.line,
86:             tokens.first.position)
87:         else
88:           # tag without block
89:           tags << construct_tag(tokens)
90:         end
91:       end
92:                         
93:       @tokenizer.close()
94:                         
95:       return tags
96:     end