diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2018-12-22 09:28:48 -0800 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2018-12-22 13:46:56 -0800 |
commit | de8326d00dffdb500c02839a98330b869c2457f3 (patch) | |
tree | 6c5fdae41cf8b335ff1c64f37856786523e4fd0d /examples/configParse.py | |
parent | 59dfd314c23fd653271bdad37631f0497e8ad748 (diff) | |
download | pyparsing-git-de8326d00dffdb500c02839a98330b869c2457f3.tar.gz |
Trim trailing white space throughout the project
Many editors clean up trailing white space on save. By removing it all
in one go, it helps keep future diffs cleaner by avoiding spurious white
space changes on unrelated lines.
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)
-
|