diff options
author | Paul McGuire <ptmcg@users.noreply.github.com> | 2018-12-23 21:30:40 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-23 21:30:40 -0600 |
commit | 4fba64a079016e6ea62d041f19b7eadd081341e8 (patch) | |
tree | 6c5fdae41cf8b335ff1c64f37856786523e4fd0d /examples/configParse.py | |
parent | 59dfd314c23fd653271bdad37631f0497e8ad748 (diff) | |
parent | de8326d00dffdb500c02839a98330b869c2457f3 (diff) | |
download | pyparsing-git-4fba64a079016e6ea62d041f19b7eadd081341e8.tar.gz |
Merge pull request #55 from jdufresne/ws
Trim trailing white space throughout the project
Diffstat (limited to 'examples/configParse.py')
-rw-r--r-- | examples/configParse.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/examples/configParse.py b/examples/configParse.py index 769249c..db7b6c7 100644 --- a/examples/configParse.py +++ b/examples/configParse.py @@ -15,7 +15,7 @@ import pprint inibnf = None
def inifile_BNF():
global inibnf
-
+
if not inibnf:
# punctuation
@@ -23,24 +23,24 @@ def inifile_BNF(): rbrack = Literal("]").suppress()
equals = Literal("=").suppress()
semi = Literal(";")
-
+
comment = semi + Optional( restOfLine )
-
+
nonrbrack = "".join( [ c for c in printables if c != "]" ] ) + " \t"
nonequals = "".join( [ c for c in printables if c != "=" ] ) + " \t"
-
+
sectionDef = lbrack + Word( nonrbrack ) + rbrack
keyDef = ~lbrack + Word( nonequals ) + equals + empty + restOfLine
# strip any leading or trailing blanks from key
def stripKey(tokens):
tokens[0] = tokens[0].strip()
keyDef.setParseAction(stripKey)
-
+
# using Dict will allow retrieval of named data fields as attributes of the parsed results
inibnf = Dict( ZeroOrMore( Group( sectionDef + Dict( ZeroOrMore( Group( keyDef ) ) ) ) ) )
-
+
inibnf.ignore( comment )
-
+
return inibnf
@@ -59,14 +59,13 @@ def test( strng ): print(err.line)
print(" "*(err.column-1) + "^")
print(err)
-
+
iniFile.close()
print()
return tokens
-
+
if __name__ == "__main__":
ini = test("setup.ini")
- print("ini['Startup']['modemid'] =", ini['Startup']['modemid'])
+ print("ini['Startup']['modemid'] =", ini['Startup']['modemid'])
print("ini.Startup =", ini.Startup)
print("ini.Startup.modemid =", ini.Startup.modemid)
-
|