class String(Grammar):
grammar_whitespace_mode = "explicit"
grammar = L('"'), ZERO_OR_MORE(ANY_EXCEPT('\n"\\')|(L('\\'), ANY)), L('"')
class Strings(Grammar):
grammar = ONE_OR_MORE(String)
class StringG(Grammar):
grammar_whitespace_mode = "explicit"
grammar = G(L('"'), ZERO_OR_MORE(ANY_EXCEPT('\n"\\')|(L('\\'), ANY)), L('"'))
class StringGs(Grammar):
grammar = ONE_OR_MORE(StringG)
In [3]: p = Strings.parser()
In [4]: ss = p.parse_string('" "')
---------------------------------------------------------------------------
ParseError Traceback (most recent call last)
<ipython-input-4-2e3c7158d7cf> in <module>
----> 1 ss = p.parse_string('" "')
~/anaconda2/envs/nmigen/lib/python3.7/site-packages/modgrammar/__init__.py in parse_string(self, string, data)
519 self.reset()
--> 520 for result in self._parse_text(string, True, True, data, 'complete'):
521 # This will always just return the first result
522 return result
~/anaconda2/envs/nmigen/lib/python3.7/site-packages/modgrammar/__init__.py in _parse_text(self, string, bol, eof, data, matchtype)
453
454 while True:
--> 455 count, obj = self._parse(pos, session, matchtype)
456 if count is None:
457 # Partial match
~/anaconda2/envs/nmigen/lib/python3.7/site-packages/modgrammar/__init__.py in _parse(self, pos, session, matchtype)
393 char = self.char + errpos
394 line, col = util.calc_line_col(self.text.string, errpos, self.line, self.col, self.tabs)
--> 395 raise ParseError(self.grammar, self.text.string, errpos, char, line=line, col=col, expected=expected)
396 if count is None:
397 # We need more input
ParseError: [line 1, column 3] Expected '\\' or ANY_EXCEPT('\n"\\'): Found '"'
In [5]: pg = StringGs.parser()
In [6]: ssg = pg.parse_string('" "')
Why is this ? Can this be considered a bug ?
grammar = G(L('"'), ZERO_OR_MORE(ANY_EXCEPT('\n"\\')|(L('\\'), ANY)), L('"'))
grammar = G(L('"'), ZERO_OR_MORE(ANY_EXCEPT('\n"\\')|(L('\\'), ANY)), L('"'), grammar_whitespace_mode="explicit")
class String(Grammar):
grammar_whitespace_mode = "explicit"
grammar = L('"'), ZERO_OR_MORE(ANY_EXCEPT('\n"\\') | (L('\\'), ANY), grammar_whitespace_mode="explicit"), L('"')
--
You received this message because you are subscribed to the Google Groups "modgrammar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modgrammar+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modgrammar/2c7ca787-8f8f-4a9e-ac23-dbcdf4636c8b%40googlegroups.com.
I really should document those extras a bit better, though..
modgrammar.extras.QuotedString
(nmigen) [verhaegs@localhost pdkmaster]$ ipython
Python 3.7.6 (default, Jan 8 2020, 19:59:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.11.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from modgrammar import *
In [2]: from modgrammar.extras import *
In [3]: class String(Grammar):
...: grammar = QuotedString
...:
In [4]: p = String.parser()
In [5]: print(p.parse_string('" "'))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-240f7c39ba59> in <module>
----> 1 print(p.parse_string('" "'))
~/anaconda2/envs/nmigen/lib/python3.7/site-packages/modgrammar/__init__.py in parse_string(self, string, data)
519 self.reset()
--> 520 for result in self._parse_text(string, True, True, data, 'complete'):
521 # This will always just return the first result
522 return result
~/anaconda2/envs/nmigen/lib/python3.7/site-packages/modgrammar/__init__.py in _parse_text(self, string, bol, eof, data, matchtype)
453
454 while True:
--> 455 count, obj = self._parse(pos, session, matchtype)
456 if count is None:
457 # Partial match
~/anaconda2/envs/nmigen/lib/python3.7/site-packages/modgrammar/__init__.py in _parse(self, pos, session, matchtype)
367 if debugger:
368 parsestate = debugger.debug_wrapper(parsestate, self.grammar, pos, self.text)
--> 369 count, obj = next(parsestate)
370 else:
371 count, obj = parsestate.send(self.text)
~/anaconda2/envs/nmigen/lib/python3.7/site-packages/modgrammar/__init__.py in grammar_parse(cls, text, index, session)
702 s = debugger.debug_wrapper(s, g, pos, text)
703 while True:
--> 704 offset, obj = next(s)
705 while offset is None:
706 text = yield (None, None)
~/anaconda2/envs/nmigen/lib/python3.7/site-packages/modgrammar/__init__.py in grammar_parse(cls, text, index, session)
637 """
638
--> 639 grammar = cls.grammar
640 grammar_min = cls.grammar_min
641 grammar_max = cls.grammar_max
AttributeError: type object 'QuotedString' has no attribute 'grammar'
--
You received this message because you are subscribed to the Google Groups "modgrammar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modgrammar+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modgrammar/6d7d36eb-19c8-466b-a875-737ab13606c1%40googlegroups.com.