Class: NanDoc::Filters::CustomTag::TagParser::RegexpSymbol
- Inherits:
-
Object
- Object
- NanDoc::Filters::CustomTag::TagParser::RegexpSymbol
- Includes:
- ParserSymbol
- Defined in:
- lib/nandoc/filters/tag-parser.rb
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#next ⇒ Object
readonly
Returns the value of attribute next.
-
#re ⇒ Object
readonly
Returns the value of attribute re.
Instance Method Summary collapse
-
#initialize(grammar, hash, name) ⇒ RegexpSymbol
constructor
A new instance of RegexpSymbol.
- #next_symbol_or_nil ⇒ Object
- #parse(scn, sex, fails) ⇒ Object
Methods included from ParserSymbol
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
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
109 110 111 |
# File 'lib/nandoc/filters/tag-parser.rb', line 109 def desc @desc end |
#name ⇒ Object
Returns the value of attribute name.
110 111 112 |
# File 'lib/nandoc/filters/tag-parser.rb', line 110 def name @name end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
112 113 114 |
# File 'lib/nandoc/filters/tag-parser.rb', line 112 def next @next end |
#re ⇒ Object (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_nil ⇒ Object
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
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 |