Class: Glyph::Parser
- Inherits:
-
Object
- Object
- Glyph::Parser
- Defined in:
- lib/glyph/parser.rb
Overview
The Glyph::Parser class can parse a string of text containing Glyph macros and produce the corresponding syntax tree.
Instance Method Summary collapse
-
#initialize(text, source_name = "--") ⇒ Parser
constructor
Initializes the parser.
-
#parse ⇒ Glyph::SyntaxNode
Parses the string of text provided during initialization.
Constructor Details
#initialize(text, source_name = "--") ⇒ Parser
Initializes the parser.
16 17 18 19 20 21 22 23 |
# File 'lib/glyph/parser.rb', line 16 def initialize(text, source_name="--") @ruby19 = RUBY_VERSION >= '1.9' ? true : false @source_name = source_name || "--" @input = StringScanner.new text @output = create_node DocumentNode, :name => @source_name.to_sym @current_macro = nil @current_attribute = nil end |
Instance Method Details
#parse ⇒ Glyph::SyntaxNode
Parses the string of text provided during initialization
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/glyph/parser.rb', line 28 def parse count = 0 while result = parse_contents(@output) do @output << result count +=1 end if @input.pos < @input.string.bytesize then current_char = @input.string[@input.pos].chr rescue nil illegal_delimiter = current_char.match(/\]|\[/) rescue nil error "Macro delimiter '#{current_char}' not escaped" if illegal_delimiter end @output end |