Class: Teepee::ParagraphParser

Inherits:
ParserNode show all
Defined in:
lib/teepee/paragraph-parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ParserNode

#use_scope

Constructor Details

#initialize(parser, tokens) ⇒ ParagraphParser

Returns a new instance of ParagraphParser.

Raises:

  • (ArgumentError)


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

#expressionsObject

Returns the value of attribute expressions.



52
53
54
# File 'lib/teepee/paragraph-parser.rb', line 52

def expressions
  @expressions
end

#parserObject

Returns the value of attribute parser.



52
53
54
# File 'lib/teepee/paragraph-parser.rb', line 52

def parser
  @parser
end

#scopeObject

Returns the value of attribute scope.



52
53
54
# File 'lib/teepee/paragraph-parser.rb', line 52

def scope
  @scope
end

#tokensObject

Returns the value of attribute tokens.



52
53
54
# File 'lib/teepee/paragraph-parser.rb', line 52

def tokens
  @tokens
end

Instance Method Details

#parseObject



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_htmlObject



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