Class: TBMX::ParagraphParser

Inherits:
ParserNode show all
Defined in:
lib/tbmx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens) ⇒ ParagraphParser

Returns a new instance of ParagraphParser.

Raises:

  • (ArgumentError)


271
272
273
274
275
276
# File 'lib/tbmx.rb', line 271

def initialize(tokens)
  raise ArgumentError if not tokens.is_a? Array
  tokens.each {|token| raise ArgumentError if not token.kind_of? ParserNode}
  @tokens = tokens
  parse
end

Instance Attribute Details

#expressionsObject (readonly)

Returns the value of attribute expressions.



269
270
271
# File 'lib/tbmx.rb', line 269

def expressions
  @expressions
end

#tokensObject (readonly)

Returns the value of attribute tokens.



269
270
271
# File 'lib/tbmx.rb', line 269

def tokens
  @tokens
end

Instance Method Details

#parseObject



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/tbmx.rb', line 278

def parse
  @expressions = []
  rest = tokens
  while rest.length > 0
    if rest.first.is_a? WordToken
      @expressions << rest.shift
    elsif rest.first.is_a? WhitespaceToken
      @expressions << rest.shift
    elsif rest.first.is_a? BackslashToken
      command, rest = CommandParser.parse(rest)
      @expressions << command
    else
      return self
    end
  end
end

#to_htmlObject



295
296
297
# File 'lib/tbmx.rb', line 295

def to_html
  "<p>\n" + expressions.map(&:to_html).join + "\n</p>\n"
end