I'm trying to write a SMTP parser and took some information for quoted strings from the rfc. So I have the following grammar (taken out all the parts that work, focusing on the thing that doesn't):
quoted_string : /[\x22]/ qcontentsmtp* /[\x22]/
qcontentsmtp : qtextsmtp | quoted_pairsmtp
quoted_pairsmtp : /[\x5C\x5C]/ /[\x20-\x7E]/
qtextsmtp : /[\x20-\x21|\x23-\x5B|\x5D-\x7E]/
command : [ quoted_string ]
With the only start
for the parser being the command
-rule.
When I input "quoted_string"
, I would expect it to be parsed as such:
command -> quoted_string -> qcontentsmtp -> qtextsmtp
As you can see, qtextsmtp
contains alphanumeric characters, coded as a regex, as shown in the rfc. However, when I try to parse it, I get this message:
input = '"quoted_string"'
....
####### Parsing Failed
No terminal defined for 'q' at line 1 col 2
"quoted_string"
^
when I input just ""
it works as expected.
When I change the rule qtextsmtp
and exchange the regex for "a"
and make the input be '"a"'
it also works.
I defined all the rules as functions in my transformer, very basic, like so:
class StringsTransformer(Transformer):
# externals
def quoted_string(self, args):
return "".join(args)
# internals
def qcontentsmtp(self, args):
return "".join(args)
def quoted_pairsmtp(self, args):
return "".join(args)
def qtextsmtp(self, args):
return "".join(args)
But I don't even get to those rules because, as I said, it won't even parse.
I'm not quite sure why the regex doesn't work. I use these type of rules in other parts and they work just fine, just with this one it doesn't.