Closed nisanthchunduru closed 9 years ago
wsp? >> str('=') >> wsp? is repetitive among definitions of known tags like dmarc_version, dmarc_policy etc.
wsp? >> str('=') >> wsp?
dmarc_version
dmarc_policy
Since they are essentially tag value pairs, should we extract it out into a method/dsl?
class Parser < Parslet::Parser def tag_value_pair(tag_definition, value_definition) tag_definition >> wsp? >> str('=') >> wsp? >> value_definition end
rule(:dmarc_version) do tag_value_pair( str('v'), str('DMARC1').as(:v) ) end
in place of
rule(:dmarc_version) do str('v') >> wsp? >> str('=') >> wsp? >> str('DMARC1').as(:v) end
and
rule(:dmarc_request) do tag_value_pair( str('p'), ( str('none') | str('quarantine') | str('reject') ).as(:p) ) end
rule(:dmarc_request) do str('p') >> wsp? >> str('=') >> wsp? >> ( str('none') | str('quarantine') | str('reject') ).as(:p) end
We should make a class method for this called tag_rule.
tag_rule
wsp? >> str('=') >> wsp?
is repetitive among definitions of known tags likedmarc_version
,dmarc_policy
etc.Since they are essentially tag value pairs, should we extract it out into a method/dsl?
in place of
and
in place of