Class: NanDoc::Filters::CustomTag::TagParser::RegexpSymbol

Inherits:
Object
  • Object
show all
Includes:
ParserSymbol
Defined in:
lib/nandoc/filters/tag-parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ParserSymbol

#secret_grammar

Constructor Details

#initialize(grammar, hash, name) ⇒ RegexpSymbol

Returns a new instance of RegexpSymbol.



101
102
103
104
105
106
107
108
# File 'lib/nandoc/filters/tag-parser.rb', line 101

def initialize(grammar, hash, name)
  secret_grammar grammar
  @desc = hash[:desc] or fail("no")
  @re   = hash[:re]   or fail("no")
  @next = hash[:next]
  @no_sexp = hash[:no_sexp]
  self.name = name
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



109
110
111
# File 'lib/nandoc/filters/tag-parser.rb', line 109

def desc
  @desc
end

#nameObject

Returns the value of attribute name.



110
111
112
# File 'lib/nandoc/filters/tag-parser.rb', line 110

def name
  @name
end

#nextObject (readonly)

Returns the value of attribute next.



112
113
114
# File 'lib/nandoc/filters/tag-parser.rb', line 112

def next
  @next
end

#reObject (readonly)

Returns the value of attribute re.



111
112
113
# File 'lib/nandoc/filters/tag-parser.rb', line 111

def re
  @re
end

Instance Method Details

#next_symbol_or_nilObject



113
114
115
# File 'lib/nandoc/filters/tag-parser.rb', line 113

def next_symbol_or_nil
  self.next and grammar.get_symbol(self.next)
end

#parse(scn, sex, fails) ⇒ Object

Returns:

  • nil iff you succeed and have no next

  • next parser if you succeed and have a next parser

  • false if you fail



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/nandoc/filters/tag-parser.rb', line 119

def parse scn, sex, fails
  print "[#{name.inspect}] is parsing #{scn.rest.inspect}"
  my_ret = nil
  if matched = scn.scan(re)
    sex.push([name, matched]) unless @no_sexp
    my_ret = next_symbol_or_nil
    my_ret ||= true # assume no next and we parsed it ok
    puts " matched: #{matched}"
  else
    fails.push "expecting #{desc} near #{scn.rest.inspect}."
    my_ret = false
    puts " not found"
  end
  my_ret
end