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.
54 55 56 57 58 59 60 61 62 |
# File 'lib/teepee/paragraph-parser.rb', line 54 def initialize(parser, tokens) raise ArgumentError if not parser.is_a? Parser @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.
52 53 54 |
# File 'lib/teepee/paragraph-parser.rb', line 52 def expressions @expressions end |
#parser ⇒ Object
Returns the value of attribute parser.
52 53 54 |
# File 'lib/teepee/paragraph-parser.rb', line 52 def parser @parser end |
#scope ⇒ Object
Returns the value of attribute scope.
52 53 54 |
# File 'lib/teepee/paragraph-parser.rb', line 52 def scope @scope end |
#tokens ⇒ Object
Returns the value of attribute tokens.
52 53 54 |
# File 'lib/teepee/paragraph-parser.rb', line 52 def tokens @tokens end |
Instance Method Details
#parse ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/teepee/paragraph-parser.rb', line 64 def parse @expressions = [] rest = tokens while rest.length > 0 if rest.first.is_a? LeftBraceToken list, rest = ListParser.parse parser, scope.derive, rest @expressions << list elsif 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
84 85 86 |
# File 'lib/teepee/paragraph-parser.rb', line 84 def to_html "<p>\n" + expressions.map(&:to_html).join + "\n</p>\n" end |