Class: TBMX::ParagraphParser
- Inherits:
-
ParserNode
- Object
- ParserNode
- TBMX::ParagraphParser
- Defined in:
- lib/tbmx.rb
Instance Attribute Summary collapse
-
#expressions ⇒ Object
readonly
Returns the value of attribute expressions.
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(tokens) ⇒ ParagraphParser
constructor
A new instance of ParagraphParser.
- #parse ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(tokens) ⇒ ParagraphParser
Returns a new instance of ParagraphParser.
517 518 519 520 521 522 |
# File 'lib/tbmx.rb', line 517 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
#expressions ⇒ Object (readonly)
Returns the value of attribute expressions.
515 516 517 |
# File 'lib/tbmx.rb', line 515 def expressions @expressions end |
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
515 516 517 |
# File 'lib/tbmx.rb', line 515 def tokens @tokens end |
Instance Method Details
#parse ⇒ Object
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/tbmx.rb', line 524 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_html ⇒ Object
541 542 543 |
# File 'lib/tbmx.rb', line 541 def to_html "<p>\n" + expressions.map(&:to_html).join + "\n</p>\n" end |