diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-10-31 21:10:28 -0700 |
---|---|---|
committer | Paul McGuire <ptmcg@users.noreply.github.com> | 2019-10-31 23:10:28 -0500 |
commit | 53d1b4a6f48a53c4c4ec4ac7031362b691c0366d (patch) | |
tree | 088ad3cf3561b78a00af4fb2fd474f4a2b8ca70c /examples/apicheck.py | |
parent | 41752aa52cc97c710474bb2972cceab057b52ad4 (diff) | |
download | pyparsing-git-53d1b4a6f48a53c4c4ec4ac7031362b691c0366d.tar.gz |
Blacken the project (#141)
Diffstat (limited to 'examples/apicheck.py')
-rw-r--r-- | examples/apicheck.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/examples/apicheck.py b/examples/apicheck.py index cd35a9a..1905d4a 100644 --- a/examples/apicheck.py +++ b/examples/apicheck.py @@ -9,25 +9,24 @@ from pyparsing import *
# define punctuation and simple tokens for locating API calls
-LBRACK,RBRACK,LBRACE,RBRACE = map(Suppress,"[]{}")
-ident = Word(alphas,alphanums+"_") | QuotedString("{",endQuoteChar="}")
+LBRACK, RBRACK, LBRACE, RBRACE = map(Suppress, "[]{}")
+ident = Word(alphas, alphanums + "_") | QuotedString("{", endQuoteChar="}")
arg = "$" + ident
# define an API call with a specific number of arguments - using '-'
# will ensure that after matching procname, an incorrect number of args will
# raise a ParseSyntaxException, which will interrupt the scanString
def apiProc(name, numargs):
- return LBRACK + Keyword(name)("procname") - arg*numargs + RBRACK
+ return LBRACK + Keyword(name)("procname") - arg * numargs + RBRACK
+
# create an apiReference, listing all API functions to be scanned for, and
# their respective number of arguments. Beginning the overall expression
# with FollowedBy allows us to quickly rule out non-api calls while scanning,
# since all of the api calls begin with a "["
-apiRef = FollowedBy("[") + MatchFirst([
- apiProc("procname1", 2),
- apiProc("procname2", 1),
- apiProc("procname3", 2),
- ])
+apiRef = FollowedBy("[") + MatchFirst(
+ [apiProc("procname1", 2), apiProc("procname2", 1), apiProc("procname3", 2),]
+)
test = """[ procname1 $par1 $par2 ]
other code here
@@ -45,13 +44,13 @@ test = """[ procname1 $par1 $par2 ] api_scanner = apiRef.scanString(test)
while 1:
try:
- t,s,e = next(api_scanner)
- print("found %s on line %d" % (t.procname, lineno(s,test)))
+ t, s, e = next(api_scanner)
+ print("found %s on line %d" % (t.procname, lineno(s, test)))
except ParseSyntaxException as pe:
print("invalid arg count on line", pe.lineno)
- print(pe.lineno,':',pe.line)
+ print(pe.lineno, ":", pe.line)
# reset api scanner to start after this exception location
- test = "\n"*(pe.lineno-1)+test[pe.loc+1:]
+ test = "\n" * (pe.lineno - 1) + test[pe.loc + 1 :]
api_scanner = apiRef.scanString(test)
except StopIteration:
break
|