Last active
February 11, 2019 15:11
-
-
Save mueslo/4813f0d67fc596c96714dd82495c7608 to your computer and use it in GitHub Desktop.
PyParsing 2.3.1 Bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyparsing import (Word, Literal, Regex, Keyword, CaselessKeyword, Forward, | |
Group, OneOrMore, ZeroOrMore, alphas, nums, Suppress, | |
delimitedList, CharsNotIn, Empty, Optional, Or, | |
restOfLine) | |
IDENTIFIER = Word(alphas + "_", alphas + nums + "_") | |
(LPAREN, RPAREN, LBRACK, RBRACK, LBRACE, RBRACE, | |
SEMI, COMMA, EQUAL, DQUOTE) = map(Suppress, "()[]{};,=\"") | |
VARIABLE = IDENTIFIER("name") | |
SCALARTYPE = Or(map(Keyword, "int real logical flag char string".split())) | |
# here's the breaking change | |
STRUCTMEMBERS = Forward() | |
STRUCTTYPE = Keyword("struct") + LBRACE + STRUCTMEMBERS("members") + RBRACE | |
DECLARATION = (SCALARTYPE | STRUCTTYPE)("type") + VARIABLE | |
STRUCTMEMBERS << Group(ZeroOrMore(Group(DECLARATION + SEMI))) | |
config_str = """struct {char mainversion;char subversion;} version""" | |
token = DECLARATION.parseString(config_str, parseAll=True) | |
print(token.type) | |
# <= 2.3.0: 'struct' | |
# == 2.3.1: ['struct', [['char', 'mainversion'], ['char', 'subversion']]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment