Class: Teepee::ParagraphParser
- Inherits:
-
ParserNode
- Object
- ParserNode
- Teepee::ParagraphParser
- Defined in:
- lib/teepee/paragraph-parser.rb
Instance Attribute Summary collapse
-
#expressions ⇒ Object
Returns the value of attribute expressions.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Instance Method Summary collapse
-
#initialize(parser, tokens) ⇒ ParagraphParser
constructor
A new instance of ParagraphParser.
- #parse ⇒ Object
- #to_html ⇒ Object
Methods inherited from ParserNode
Constructor Details
#initialize(parser, tokens) ⇒ ParagraphParser
Returns a new instance of ParagraphParser.
53 54 55 56 57 58 59 60 |
# File 'lib/teepee/paragraph-parser.rb', line 53 def initialize(parser, tokens) @parser = parser @scope = Scope.new 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
Returns the value of attribute expressions.
51 52 53 |
# File 'lib/teepee/paragraph-parser.rb', line 51 def expressions @expressions end |
#parser ⇒ Object
Returns the value of attribute parser.
51 52 53 |
# File 'lib/teepee/paragraph-parser.rb', line 51 def parser @parser end |
#scope ⇒ Object
Returns the value of attribute scope.
51 52 53 |
# File 'lib/teepee/paragraph-parser.rb', line 51 def scope @scope end |
#tokens ⇒ Object
Returns the value of attribute tokens.
51 52 53 |
# File 'lib/teepee/paragraph-parser.rb', line 51 def tokens @tokens end |
Instance Method Details
#parse ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/teepee/paragraph-parser.rb', line 62 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 parser, scope.derive, rest @expressions << command else return self end end end |
#to_html ⇒ Object
79 80 81 |
# File 'lib/teepee/paragraph-parser.rb', line 79 def to_html "<p>\n" + expressions.map(&:to_html).join + "\n</p>\n" end |