diff options
author | ptmcg <ptmcg@austin.rr.com> | 2019-01-09 17:18:22 -0600 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2019-01-09 17:18:22 -0600 |
commit | d626c99b6288afc4708d72f668b45a29d3263d22 (patch) | |
tree | 4cbeca134437387022e59b71631246e178393aca | |
parent | e9ef507bf1fd41d4bd3ffb0c193e5889254ba340 (diff) | |
download | pyparsing-git-d626c99b6288afc4708d72f668b45a29d3263d22.tar.gz |
Add enumerated place holders for strings that invoke str.format(), for Py2 compatibility
-rw-r--r-- | examples/adventureEngine.py | 2 | ||||
-rw-r--r-- | examples/chemicalFormulas.py | 8 | ||||
-rw-r--r-- | examples/gen_ctypes.py | 16 | ||||
-rw-r--r-- | examples/getNTPserversNew.py | 2 | ||||
-rw-r--r-- | examples/protobuf_parser.py | 2 | ||||
-rw-r--r-- | examples/pymicko.py | 66 | ||||
-rw-r--r-- | examples/pythonGrammarParser.py | 4 | ||||
-rw-r--r-- | examples/rangeCheck.py | 2 | ||||
-rw-r--r-- | examples/romanNumerals.py | 4 | ||||
-rw-r--r-- | examples/shapes.py | 2 | ||||
-rw-r--r-- | examples/simpleWiki.py | 2 | ||||
-rw-r--r-- | examples/sparser.py | 6 | ||||
-rw-r--r-- | examples/statemachine/documentSignoffDemo.py | 2 | ||||
-rw-r--r-- | examples/statemachine/libraryBookDemo.py | 4 | ||||
-rw-r--r-- | examples/statemachine/statemachine.py | 12 | ||||
-rw-r--r-- | examples/statemachine/trafficLightDemo.py | 4 | ||||
-rw-r--r-- | examples/wordsToNum.py | 4 | ||||
-rw-r--r-- | pyparsing.py | 18 |
18 files changed, 80 insertions, 80 deletions
diff --git a/examples/adventureEngine.py b/examples/adventureEngine.py index 259c03e..8dee391 100644 --- a/examples/adventureEngine.py +++ b/examples/adventureEngine.py @@ -66,7 +66,7 @@ class Room(object): is_form = "are"
else:
is_form = "is"
- print("There {} {} here.".format(is_form, enumerateItems(visibleItems)))
+ print("There {0} {1} here.".format(is_form, enumerateItems(visibleItems)))
else:
print("You see %s." % (enumerateItems(visibleItems)))
diff --git a/examples/chemicalFormulas.py b/examples/chemicalFormulas.py index abbe332..c1df9f3 100644 --- a/examples/chemicalFormulas.py +++ b/examples/chemicalFormulas.py @@ -34,7 +34,7 @@ formula.runTests("""\ C6H5OH
NaCl
""",
- fullDump=False, postParse=lambda _, tokens: "Molecular weight: {}".format(fn(tokens)))
+ fullDump=False, postParse=lambda _, tokens: "Molecular weight: {0}".format(fn(tokens)))
print()
# Version 2 - access parsed items by results name
@@ -47,7 +47,7 @@ formula.runTests("""\ C6H5OH
NaCl
""",
- fullDump=False, postParse=lambda _, tokens: "Molecular weight: {}".format(fn(tokens)))
+ fullDump=False, postParse=lambda _, tokens: "Molecular weight: {0}".format(fn(tokens)))
print()
# Version 3 - convert integers during parsing process
@@ -61,7 +61,7 @@ formula.runTests("""\ C6H5OH
NaCl
""",
- fullDump=False, postParse=lambda _, tokens: "Molecular weight: {}".format(fn(tokens)))
+ fullDump=False, postParse=lambda _, tokens: "Molecular weight: {0}".format(fn(tokens)))
print()
# Version 4 - parse and convert integers as subscript digits
@@ -81,5 +81,5 @@ formula.runTests("""\ C₆H₅OH
NaCl
""",
- fullDump=False, postParse=lambda _, tokens: "Molecular weight: {}".format(fn(tokens)))
+ fullDump=False, postParse=lambda _, tokens: "Molecular weight: {0}".format(fn(tokens)))
print()
diff --git a/examples/gen_ctypes.py b/examples/gen_ctypes.py index 325aa28..f4a8756 100644 --- a/examples/gen_ctypes.py +++ b/examples/gen_ctypes.py @@ -102,7 +102,7 @@ def getUDType(typestr): key = typestr.rstrip(" *")
if key not in typemap:
user_defined_types.add(key)
- typemap[key] = "{}_{}".format(module, key)
+ typemap[key] = "{0}_{1}".format(module, key)
def typeAsCtypes(typestr):
if typestr in typemap:
@@ -140,13 +140,13 @@ for en_,_,_ in enum_def.scanString(c_header): enum_constants.append( (ev.name, ev.value) )
print("from ctypes import *")
-print("{} = CDLL('{}.dll')".format(module, module))
+print("{0} = CDLL('{1}.dll')".format(module, module))
print()
print("# user defined types")
for tdname,tdtyp in typedefs:
- print("{} = {}".format(tdname, typemap[tdtyp]))
+ print("{0} = {1}".format(tdname, typemap[tdtyp]))
for fntd in fn_typedefs:
- print("{} = CFUNCTYPE({})".format(fntd.fn_name,
+ print("{0} = CFUNCTYPE({1})".format(fntd.fn_name,
',\n '.join(typeAsCtypes(a.argtype) for a in fntd.fn_args)))
for udtype in user_defined_types:
print("class %s(Structure): pass" % typemap[udtype])
@@ -154,19 +154,19 @@ for udtype in user_defined_types: print()
print("# constant definitions")
for en,ev in enum_constants:
- print("{} = {}".format(en,ev))
+ print("{0} = {1}".format(en,ev))
print()
print("# functions")
for fn in functions:
- prefix = "{}.{}".format(module, fn.fn_name)
+ prefix = "{0}.{1}".format(module, fn.fn_name)
- print("{}.restype = {}".format(prefix, typeAsCtypes(fn.fn_type)))
+ print("{0}.restype = {1}".format(prefix, typeAsCtypes(fn.fn_type)))
if fn.varargs:
print("# warning - %s takes variable argument list" % prefix)
del fn.fn_args[-1]
if fn.fn_args.asList() != [['void']]:
- print("{}.argtypes = ({},)".format(prefix, ','.join(typeAsCtypes(a.argtype) for a in fn.fn_args)))
+ print("{0}.argtypes = ({1},)".format(prefix, ','.join(typeAsCtypes(a.argtype) for a in fn.fn_args)))
else:
print("%s.argtypes = ()" % (prefix))
diff --git a/examples/getNTPserversNew.py b/examples/getNTPserversNew.py index 9d6b4ed..c87c0ae 100644 --- a/examples/getNTPserversNew.py +++ b/examples/getNTPserversNew.py @@ -31,5 +31,5 @@ serverListPage.close() addrs = {}
for srvr,startloc,endloc in timeServerPattern.scanString( serverListHTML ):
- print("{} ({}) - {}".format(srvr.ipAddr, srvr.hostname.strip(), srvr.loc.strip()))
+ print("{0} ({1}) - {2}".format(srvr.ipAddr, srvr.hostname.strip(), srvr.loc.strip()))
addrs[srvr.ipAddr] = srvr.loc
diff --git a/examples/protobuf_parser.py b/examples/protobuf_parser.py index ad5db3a..68a8f63 100644 --- a/examples/protobuf_parser.py +++ b/examples/protobuf_parser.py @@ -17,7 +17,7 @@ LBRACE,RBRACE,LBRACK,RBRACK,LPAR,RPAR,EQ,SEMI = map(Suppress,"{}[]()=;") kwds = """message required optional repeated enum extensions extends extend
to package service rpc returns true false option import"""
for kw in kwds.split():
- exec("{}_ = Keyword('{}')".format(kw.upper(), kw))
+ exec("{0}_ = Keyword('{1}')".format(kw.upper(), kw))
messageBody = Forward()
diff --git a/examples/pymicko.py b/examples/pymicko.py index 5a79594..7dcdf69 100644 --- a/examples/pymicko.py +++ b/examples/pymicko.py @@ -325,7 +325,7 @@ class SymbolTableEntry(object): def attribute_str(self):
"""Returns attribute string (used only for table display)"""
- return "{}={}".format(self.attribute_name, self.attribute) if self.attribute != None else "None"
+ return "{0}={1}".format(self.attribute_name, self.attribute) if self.attribute != None else "None"
class SymbolTable(object):
"""Class for symbol table of microC program"""
@@ -368,9 +368,9 @@ class SymbolTable(object): parameters = ""
for p in sym.param_types:
if parameters == "":
- parameters = "{}".format(SharedData.TYPES[p])
+ parameters = "{0}".format(SharedData.TYPES[p])
else:
- parameters += ", {}".format(SharedData.TYPES[p])
+ parameters += ", {0}".format(SharedData.TYPES[p])
print("{0:3d} | {1:^{2}s} | {3:^{4}s} | {5:^{6}s} | {7:^{8}} | ({9})".format(i, sym.name, sym_len, SharedData.KINDS[sym.kind], kind_len, SharedData.TYPES[sym.type], type_len, sym.attribute_str(), attr_len, parameters))
def insert_symbol(self, sname, skind, stype):
@@ -604,7 +604,7 @@ class CodeGenerator(object): internal - boolean value, adds "@" prefix to label
definition - boolean value, adds ":" suffix to label
"""
- return "{}{}{}".format(self.internal if internal else "", name, self.definition if definition else "")
+ return "{0}{1}{2}".format(self.internal if internal else "", name, self.definition if definition else "")
def symbol(self, index):
"""Generates symbol name from index"""
@@ -616,14 +616,14 @@ class CodeGenerator(object): sym = self.symtab.table[index]
#local variables are located at negative offset from frame pointer register
if sym.kind == SharedData.KINDS.LOCAL_VAR:
- return "-{}(%14)".format(sym.attribute * 4 + 4)
+ return "-{0}(1:%14)".format(sym.attribute * 4 + 4)
#parameters are located at positive offset from frame pointer register
elif sym.kind == SharedData.KINDS.PARAMETER:
- return "{}(%14)".format(8 + sym.attribute * 4)
+ return "{0}(1:%14)".format(8 + sym.attribute * 4)
elif sym.kind == SharedData.KINDS.CONSTANT:
- return "${}".format(sym.name)
+ return "${0}".format(sym.name)
else:
- return "{}".format(sym.name)
+ return "{0}".format(sym.name)
def save_used_registers(self):
"""Pushes all used working registers before function call"""
@@ -674,7 +674,7 @@ class CodeGenerator(object): internal - boolean value, adds "@" prefix to label
definition - boolean value, adds ":" suffix to label
"""
- self.newline_text(self.label("{}{}{}".format("@" if internal else "", name, ":" if definition else "")))
+ self.newline_text(self.label("{0}{1}{2}".format("@" if internal else "", name, ":" if definition else "")))
def global_var(self, name):
"""Inserts a new static (global) variable definition"""
@@ -704,7 +704,7 @@ class CodeGenerator(object): #if operand3 is not defined, reserve one free register for it
output = self.take_register(output_type) if operand3 == None else operand3
mnemonic = self.arithmetic_mnemonic(operation, output_type)
- self.newline_text("{}\t{},{},{}".format(mnemonic, self.symbol(operand1), self.symbol(operand2), self.symbol(output)), True)
+ self.newline_text("{0}\t{1},{2},{3}".format(mnemonic, self.symbol(operand1), self.symbol(operand2), self.symbol(output)), True)
return output
def relop_code(self, relop, operands_type):
@@ -723,13 +723,13 @@ class CodeGenerator(object): label - jump label
"""
jump = self.OPPOSITE_JUMPS[relcode] if opposite else self.CONDITIONAL_JUMPS[relcode]
- self.newline_text("{}\t{}".format(jump, label), True)
+ self.newline_text("{0}\t{1}".format(jump, label), True)
def unconditional_jump(self, label):
"""Generates an unconditional jump instruction
label - jump label
"""
- self.newline_text("JMP \t{}".format(label), True)
+ self.newline_text("JMP \t{0}".format(label), True)
def move(self,operand1, operand2):
"""Generates a move instruction
@@ -741,7 +741,7 @@ class CodeGenerator(object): self.free_if_register(operand1)
else:
output_type = SharedData.TYPES.NO_TYPE
- self.newline_text("MOV \t{},{}".format(self.symbol(operand1), self.symbol(operand2)), True)
+ self.newline_text("MOV \t{0},{1}".format(self.symbol(operand1), self.symbol(operand2)), True)
if isinstance(operand2, int):
if self.symtab.get_kind(operand2) == SharedData.KINDS.WORKING_REGISTER:
self.symtab.set_type(operand2, output_type)
@@ -761,7 +761,7 @@ class CodeGenerator(object): typ = self.symtab.get_type(operand1)
self.free_if_register(operand1)
self.free_if_register(operand2)
- self.newline_text("CMP{}\t{},{}".format(self.OPSIGNS[typ], self.symbol(operand1), self.symbol(operand2)), True)
+ self.newline_text("CMP{0}\t{1},{2}".format(self.OPSIGNS[typ], self.symbol(operand1), self.symbol(operand2)), True)
def function_begin(self):
"""Inserts function name label and function frame initialization"""
@@ -772,7 +772,7 @@ class CodeGenerator(object): def function_body(self):
"""Inserts a local variable initialization and body label"""
if self.shared.function_vars > 0:
- const = self.symtab.insert_constant("{}".format(self.shared.function_vars * 4), SharedData.TYPES.UNSIGNED)
+ const = self.symtab.insert_constant("0{}".format(self.shared.function_vars * 4), SharedData.TYPES.UNSIGNED)
self.arithmetic("-", "%15", const, "%15")
self.newline_label(self.shared.function_name + "_body", True, True)
@@ -796,7 +796,7 @@ class CodeGenerator(object): args = self.symtab.get_attribute(function)
#generates stack cleanup if function has arguments
if args > 0:
- args_space = self.symtab.insert_constant("{}".format(args * 4), SharedData.TYPES.UNSIGNED)
+ args_space = self.symtab.insert_constant("{0}".format(args * 4), SharedData.TYPES.UNSIGNED)
self.arithmetic("+", "%15", args_space, "%15")
##########################################################################################
@@ -1148,7 +1148,7 @@ class MicroC(object): if DEBUG > 2: return
exshared.setpos(loc, text)
if not self.symtab.same_types(arg[0], arg[2]):
- raise SemanticException("Invalid operands for operator '{}'".format(arg[1]))
+ raise SemanticException("Invalid operands for operator '{0}'".format(arg[1]))
self.codegen.compare(arg[0], arg[2])
#return relational operator's code
self.relexp_code = self.codegen.relop_code(arg[1], self.symtab.get_type(arg[0]))
@@ -1161,7 +1161,7 @@ class MicroC(object): print("AND+EXP:",arg)
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
- label = self.codegen.label("false{}".format(self.false_label_number), True, False)
+ label = self.codegen.label("false{0}".format(self.false_label_number), True, False)
self.codegen.jump(self.relexp_code, True, label)
self.andexp_code = self.relexp_code
return self.andexp_code
@@ -1173,9 +1173,9 @@ class MicroC(object): print("LOG_EXP:",arg)
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
- label = self.codegen.label("true{}".format(self.label_number), True, False)
+ label = self.codegen.label("true{0}".format(self.label_number), True, False)
self.codegen.jump(self.relexp_code, False, label)
- self.codegen.newline_label("false{}".format(self.false_label_number), True, True)
+ self.codegen.newline_label("false{0}".format(self.false_label_number), True, True)
self.false_label_number += 1
def if_begin_action(self, text, loc, arg):
@@ -1187,7 +1187,7 @@ class MicroC(object): if DEBUG > 2: return
self.false_label_number += 1
self.label_number = self.false_label_number
- self.codegen.newline_label("if{}".format(self.label_number), True, True)
+ self.codegen.newline_label("if{0}".format(self.label_number), True, True)
def if_body_action(self, text, loc, arg):
"""Code executed after recognising if statement's body"""
@@ -1197,10 +1197,10 @@ class MicroC(object): if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
#generate conditional jump (based on last compare)
- label = self.codegen.label("false{}".format(self.false_label_number), True, False)
+ label = self.codegen.label("false{0}".format(self.false_label_number), True, False)
self.codegen.jump(self.relexp_code, True, label)
#generate 'true' label (executes if condition is satisfied)
- self.codegen.newline_label("true{}".format(self.label_number), True, True)
+ self.codegen.newline_label("true{0}".format(self.label_number), True, True)
#save label numbers (needed for nested if/while statements)
self.label_stack.append(self.false_label_number)
self.label_stack.append(self.label_number)
@@ -1214,10 +1214,10 @@ class MicroC(object): if DEBUG > 2: return
#jump to exit after all statements for true condition are executed
self.label_number = self.label_stack.pop()
- label = self.codegen.label("exit{}".format(self.label_number), True, False)
+ label = self.codegen.label("exit{0}".format(self.label_number), True, False)
self.codegen.unconditional_jump(label)
#generate final 'false' label (executes if condition isn't satisfied)
- self.codegen.newline_label("false{}".format(self.label_stack.pop()), True, True)
+ self.codegen.newline_label("false{0}".format(self.label_stack.pop()), True, True)
self.label_stack.append(self.label_number)
def if_end_action(self, text, loc, arg):
@@ -1227,7 +1227,7 @@ class MicroC(object): print("IF_END:",arg)
if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
- self.codegen.newline_label("exit{}".format(self.label_stack.pop()), True, True)
+ self.codegen.newline_label("exit{0}".format(self.label_stack.pop()), True, True)
def while_begin_action(self, text, loc, arg):
"""Code executed after recognising a while statement (while keyword)"""
@@ -1238,7 +1238,7 @@ class MicroC(object): if DEBUG > 2: return
self.false_label_number += 1
self.label_number = self.false_label_number
- self.codegen.newline_label("while{}".format(self.label_number), True, True)
+ self.codegen.newline_label("while{0}".format(self.label_number), True, True)
def while_body_action(self, text, loc, arg):
"""Code executed after recognising while statement's body"""
@@ -1248,10 +1248,10 @@ class MicroC(object): if DEBUG == 2: self.symtab.display()
if DEBUG > 2: return
#generate conditional jump (based on last compare)
- label = self.codegen.label("false{}".format(self.false_label_number), True, False)
+ label = self.codegen.label("false{0}".format(self.false_label_number), True, False)
self.codegen.jump(self.relexp_code, True, label)
#generate 'true' label (executes if condition is satisfied)
- self.codegen.newline_label("true{}".format(self.label_number), True, True)
+ self.codegen.newline_label("true{0}".format(self.label_number), True, True)
self.label_stack.append(self.false_label_number)
self.label_stack.append(self.label_number)
@@ -1264,11 +1264,11 @@ class MicroC(object): if DEBUG > 2: return
#jump to condition checking after while statement body
self.label_number = self.label_stack.pop()
- label = self.codegen.label("while{}".format(self.label_number), True, False)
+ label = self.codegen.label("while{0}".format(self.label_number), True, False)
self.codegen.unconditional_jump(label)
#generate final 'false' label and exit label
- self.codegen.newline_label("false{}".format(self.label_stack.pop()), True, True)
- self.codegen.newline_label("exit{}".format(self.label_number), True, True)
+ self.codegen.newline_label("false{0}".format(self.label_stack.pop()), True, True)
+ self.codegen.newline_label("exit{0}".format(self.label_number), True, True)
def program_end_action(self, text, loc, arg):
"""Checks if there is a 'main' function and the type of 'main' function"""
@@ -1320,7 +1320,7 @@ if 0: input_file = argv[1]
output_file = argv[2]
else:
- usage = """Usage: {} [input_file [output_file]]
+ usage = """Usage: {0} [input_file [output_file]]
If output file is omitted, output.asm is used
If input file is omitted, stdin is used""".format(argv[0])
print(usage)
diff --git a/examples/pythonGrammarParser.py b/examples/pythonGrammarParser.py index ed6a484..4a8adce 100644 --- a/examples/pythonGrammarParser.py +++ b/examples/pythonGrammarParser.py @@ -137,7 +137,7 @@ class SemanticGroup(object): self.contents = self.contents[:-1] + self.contents[-1].contents
def __str__(self):
- return "{}({})".format(self.label,
+ return "{0}({1})".format(self.label,
" ".join([isinstance(c,str) and c or str(c) for c in self.contents]) )
class OrList(SemanticGroup):
@@ -164,7 +164,7 @@ class Atom(SemanticGroup): self.contents = contents[0]
def __str__(self):
- return "{}{}".format(self.rep, self.contents)
+ return "{0}{1}".format(self.rep, self.contents)
def makeGroupObject(cls):
def groupAction(s,l,t):
diff --git a/examples/rangeCheck.py b/examples/rangeCheck.py index 66af545..29e9459 100644 --- a/examples/rangeCheck.py +++ b/examples/rangeCheck.py @@ -26,7 +26,7 @@ def ranged_value(expr, minval=None, maxval=None): outOfRangeMessage = {
(True, False) : "value is greater than %s" % maxval,
(False, True) : "value is less than %s" % minval,
- (False, False) : "value is not in the range ({} to {})".format(minval,maxval),
+ (False, False) : "value is not in the range ({0} to {1})".format(minval,maxval),
}[minval is None, maxval is None]
return expr().addCondition(inRangeCondition, message=outOfRangeMessage)
diff --git a/examples/romanNumerals.py b/examples/romanNumerals.py index 0f15ac8..8765055 100644 --- a/examples/romanNumerals.py +++ b/examples/romanNumerals.py @@ -57,14 +57,14 @@ expected = 1 for t,s,e in romanNumeral.scanString(tests):
orig = tests[s:e]
if t[0] != expected:
- print("{} {} {}".format("==>", t, orig))
+ print("{0} {1} {2}".format("==>", t, orig))
roman_int_map[orig] = t[0]
expected += 1
def verify_value(s, tokens):
expected = roman_int_map[s]
if tokens[0] != expected:
- raise Exception("incorrect value for {} ({}), expected {}".format(s, tokens[0], expected ))
+ raise Exception("incorrect value for {0} ({1}), expected {2}".format(s, tokens[0], expected ))
romanNumeral.runTests("""\
XVI
diff --git a/examples/shapes.py b/examples/shapes.py index 73ed334..2df8572 100644 --- a/examples/shapes.py +++ b/examples/shapes.py @@ -15,7 +15,7 @@ class Shape(object): raise NotImplementedException()
def __str__(self):
- return "<{}>: {}".format(self.__class__.__name__, self.__dict__)
+ return "<{0}>: {1}".format(self.__class__.__name__, self.__dict__)
class Square(Shape):
def area(self):
diff --git a/examples/simpleWiki.py b/examples/simpleWiki.py index 89191c9..35346bc 100644 --- a/examples/simpleWiki.py +++ b/examples/simpleWiki.py @@ -21,7 +21,7 @@ def convertToHTML_A(s,l,t): text,url=t[0].split("->")
except ValueError:
raise ParseFatalException(s,l,"invalid URL link reference: " + t[0])
- return '<A href="{}">{}</A>'.format(url,text)
+ return '<A href="{0}">{1}</A>'.format(url, text)
urlRef = QuotedString("{{",endQuoteChar="}}").setParseAction(convertToHTML_A)
diff --git a/examples/sparser.py b/examples/sparser.py index a7027eb..d4604da 100644 --- a/examples/sparser.py +++ b/examples/sparser.py @@ -77,12 +77,12 @@ def msg(txt): def debug(ftn, txt):
"""Used for debugging."""
if debug_p:
- sys.stdout.write("{}.{}:{}\n".format(modname, ftn, txt))
+ sys.stdout.write("{0}.{1}:{2}\n".format(modname, ftn, txt))
sys.stdout.flush()
def fatal(ftn, txt):
"""If can't continue."""
- msg = "{}.{}:FATAL:{}\n".format(modname, ftn, txt)
+ msg = "{0}.{1}:FATAL:{2}\n".format(modname, ftn, txt)
raise SystemExit(msg)
def usage():
@@ -116,7 +116,7 @@ class ParseFileLineByLine: compressed. Compression is deduced from the file name suffixes '.Z'
(compress/uncompress), '.gz' (gzip/gunzip), and '.bz2' (bzip2).
- The parse definition file name is developed based on the input file name.
+ The parse definition fi le name is developed based on the input file name.
If the input file name is 'basename.ext', then the definition file is
'basename_def.ext'. If a definition file specific to the input file is not
found, then the program searches for the file 'sparse.def' which would be
diff --git a/examples/statemachine/documentSignoffDemo.py b/examples/statemachine/documentSignoffDemo.py index 89c6440..58aa208 100644 --- a/examples/statemachine/documentSignoffDemo.py +++ b/examples/statemachine/documentSignoffDemo.py @@ -26,7 +26,7 @@ class Document: return attr def __str__(self): - return "{}: {}".format(self.__class__.__name__, self._state) + return "{0}: {1}".format(self.__class__.__name__, self._state) def run_demo(): diff --git a/examples/statemachine/libraryBookDemo.py b/examples/statemachine/libraryBookDemo.py index 84108e5..2e60eac 100644 --- a/examples/statemachine/libraryBookDemo.py +++ b/examples/statemachine/libraryBookDemo.py @@ -19,7 +19,7 @@ class Book: return attr def __str__(self): - return "{}: {}".format(self.__class__.__name__, self._state) + return "{0}: {1}".format(self.__class__.__name__, self._state) class RestrictedBook(Book): @@ -35,7 +35,7 @@ class RestrictedBook(Book): if user in self._authorized_users: self._state = self._state.checkout() else: - raise Exception("{} could not check out restricted book".format((user, "anonymous")[user is None])) + raise Exception("{0} could not check out restricted book".format((user, "anonymous")[user is None])) def run_demo(): diff --git a/examples/statemachine/statemachine.py b/examples/statemachine/statemachine.py index b7b60d2..2e35869 100644 --- a/examples/statemachine/statemachine.py +++ b/examples/statemachine/statemachine.py @@ -72,10 +72,10 @@ def expand_state_definition(source, loc, tokens): ]) # define all state classes - statedef.extend("class {}({}): pass".format(s, baseStateClass) for s in states) + statedef.extend("class {0}({1}): pass".format(s, baseStateClass) for s in states) # define state->state transitions - statedef.extend("{}._next_state_class = {}".format(s, fromTo[s]) for s in states if s in fromTo) + statedef.extend("{0}._next_state_class = {1}".format(s, fromTo[s]) for s in states if s in fromTo) return indent + ("\n" + indent).join(statedef) + "\n" @@ -113,9 +113,9 @@ def expand_named_state_definition(source, loc, tokens): " return self.transitionName", ]) statedef.extend( - "{} = {}Transition()".format(tn, baseStateClass) + "{0} = {1}Transition()".format(tn, baseStateClass) for tn in transitions) - statedef.extend("{}.transitionName = '{}'".format(tn, tn) + statedef.extend("{0}.transitionName = '{1}'".format(tn, tn) for tn in transitions) # define base class for state classes @@ -199,7 +199,7 @@ class SuffixImporter(object): # it probably isn't even a filesystem path finder = sys.path_importer_cache.get(dirpath) if isinstance(finder, (type(None), importlib.machinery.FileFinder)): - checkpath = os.path.join(dirpath, '{}.{}'.format(fullname, self.suffix)) + checkpath = os.path.join(dirpath, '{0}.{1}'.format(fullname, self.suffix)) yield checkpath def find_module(self, fullname, path=None): @@ -257,4 +257,4 @@ class PystateImporter(SuffixImporter): PystateImporter.register() if DEBUG: - print("registered {!r} importer".format(PystateImporter.suffix)) + print("registered {0!r} importer".format(PystateImporter.suffix)) diff --git a/examples/statemachine/trafficLightDemo.py b/examples/statemachine/trafficLightDemo.py index 4fc737c..4d70541 100644 --- a/examples/statemachine/trafficLightDemo.py +++ b/examples/statemachine/trafficLightDemo.py @@ -21,12 +21,12 @@ class TrafficLight: return getattr(self._state, attrname) def __str__(self): - return "{}: {}".format(self.__class__.__name__, self._state) + return "{0}: {1}".format(self.__class__.__name__, self._state) light = TrafficLight() for i in range(10): - print("{} {}".format(light, ("STOP", "GO")[light.cars_can_go])) + print("{0} {1}".format(light, ("STOP", "GO")[light.cars_can_go])) light.crossing_signal() light.delay() print() diff --git a/examples/wordsToNum.py b/examples/wordsToNum.py index 3d5c4b7..cbd3d26 100644 --- a/examples/wordsToNum.py +++ b/examples/wordsToNum.py @@ -85,9 +85,9 @@ def test(s,expected): if not fail_expected:
teststr, results = results_tup[0]
observed = results[0]
- assert expected == observed, "incorrect parsed value, {} -> {}, should be {}".format(teststr, observed, expected)
+ assert expected == observed, "incorrect parsed value, {0} -> {1}, should be {2}".format(teststr, observed, expected)
except Exception as exc:
- print("{}: {}".format(type(exc).__name__, exc))
+ print("{0}: {1}".format(type(exc).__name__, exc))
test("one hundred twenty hundred", None)
test("one hundred and twennty", None)
diff --git a/pyparsing.py b/pyparsing.py index 2b071b2..d6f016d 100644 --- a/pyparsing.py +++ b/pyparsing.py @@ -94,7 +94,7 @@ classes inherit from. Use the docstrings for examples of how to: """ __version__ = "2.3.1" -__versionTime__ = "08 Jan 2019 01:25 UTC" +__versionTime__ = "09 Jan 2019 23:17 UTC" __author__ = "Paul McGuire <ptmcg@users.sourceforge.net>" import string @@ -342,7 +342,7 @@ class ParseException(ParseBaseException): if isinstance(exc, ParseBaseException): ret.append(exc.line) ret.append(' ' * (exc.col - 1) + '^') - ret.append("{}: {}".format(type(exc).__name__, exc)) + ret.append("{0}: {1}".format(type(exc).__name__, exc)) callers = inspect.getinnerframes(exc.__traceback__, context=depth) seen = set() @@ -360,19 +360,19 @@ class ParseException(ParseBaseException): seen.add(f_self) self_type = type(f_self) - ret.append("{}.{} - {}".format(self_type.__module__, - self_type.__name__, - f_self)) + ret.append("{0}.{1} - {2}".format(self_type.__module__, + self_type.__name__, + f_self)) elif f_self is not None: self_type = type(f_self) - ret.append("{}.{}".format(self_type.__module__, - self_type.__name__)) + ret.append("{0}.{1}".format(self_type.__module__, + self_type.__name__)) else: code = frm.f_code if code.co_name in ('wrapper', '<module>'): continue - ret.append("{}".format(code.co_name)) + ret.append("{0}".format(code.co_name)) depth -= 1 if not depth: @@ -2526,7 +2526,7 @@ class ParserElement(object): if pp_value is not None: out.append(str(pp_value)) except Exception as e: - out.append("{} failed: {}: {}".format(postParse.__name__, type(e).__name__, e)) + out.append("{0} failed: {1}: {2}".format(postParse.__name__, type(e).__name__, e)) except ParseBaseException as pe: fatal = "(FATAL)" if isinstance(pe, ParseFatalException) else "" if '\n' in t: |