summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/asymptote/GUI/xasyFile.py
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/asymptote/GUI/xasyFile.py')
-rwxr-xr-xMaster/texmf-dist/asymptote/GUI/xasyFile.py54
1 files changed, 27 insertions, 27 deletions
diff --git a/Master/texmf-dist/asymptote/GUI/xasyFile.py b/Master/texmf-dist/asymptote/GUI/xasyFile.py
index 890f1ad3eef..7516fc7d3b5 100755
--- a/Master/texmf-dist/asymptote/GUI/xasyFile.py
+++ b/Master/texmf-dist/asymptote/GUI/xasyFile.py
@@ -28,7 +28,7 @@ def parseFile(inFile):
#lines = [line for line in lines.splitlines() if not line.startswith("//")]
result = []
if lines[0] != "initXasyMode();":
- raise xasyFileError,"Invalid file format: First line must be \"initXasyMode();\""
+ raise xasyFileError("Invalid file format: First line must be \"initXasyMode();\"")
lines.pop(0)
lineCount = 2
lineNum = len(lines)
@@ -37,14 +37,14 @@ def parseFile(inFile):
lines.pop(0)
if not line.isspace() and len(line)>0:
try:
- #print "Line %d: %s"%(lineCount,line),
+ #print ("Line {:d}: {:s}".format(lineCount,line))
lineResult = parseLine(line.strip(),lines)
except:
- raise xasyParseError,"Parsing error: line %d in %s\n%s"%(lineCount,inFile.name,line)
+ raise xasyParseError("Parsing error: line {:d} in {:s}\n{:s}".format(lineCount,inFile.name,line))
if lineResult != None:
result.append(lineResult)
- #print "\tproduced: %s"%str(lineResult)
+ #print ("\tproduced: {:s}".format(str(lineResult)))
lineCount += lineNum-len(lines)
lineNum = len(lines)
return result
@@ -105,7 +105,7 @@ def parseTransformExpression(line):
global pendingTransforms
stackCmd = line[len(transformPrefix)+1:line.find("(")]
if line[-2:] != ");":
- raise xasyParseError,"Invalid syntax"
+ raise xasyParseError("Invalid syntax")
args = line[line.find("(")+1:-2]
if stackCmd == "push":
t = asyTransform(eval(args))
@@ -113,19 +113,19 @@ def parseTransformExpression(line):
elif stackCmd == "add":
parseIndexedTransforms(args)
else:
- raise xasyParseError,"Invalid transform stack command."
+ raise xasyParseError("Invalid transform stack command.")
return None
def parseLabel(line):
"""Parse an asy Label statement, returning an xasyText item"""
if not (line.startswith("Label(") and line.endswith(",align=SE)")):
- raise xasyParseError,"Invalid syntax"
+ raise xasyParseError("Invalid syntax")
args = line[6:-1]
loc2 = args.rfind(",align=SE")
loc1 = args.rfind(",",0,loc2-1)
loc = args.rfind(",(",0,loc1-1)
if loc < 2:
- raise xasyParseError,"Invalid syntax"
+ raise xasyParseError("Invalid syntax")
text = args[1:loc-1]
location = eval(args[loc+1:args.find("),",loc)+1])
pen = args[loc:loc2]
@@ -143,7 +143,7 @@ def parseLabelCommand(line):
e.g.: label(Label("Hello world!",(0,0),rgb(0,0,0)+0.5,align=SE));
"""
if line[-2:] != ");":
- raise xasyParseError,"Invalid syntax"
+ raise xasyParseError("Invalid syntax")
arguments = line[6:-2]
return parseLabel(arguments)
@@ -155,7 +155,7 @@ def parseDrawCommand(line):
e.g.: draw((0,0)..controls(0.33,0.33)and(0.66,0.66)..(1,1),rgb(1,0,1)+1.5);
"""
if line[-2:] != ");":
- raise xasyParseError,"Invalid syntax"
+ raise xasyParseError("Invalid syntax")
args = line[5:-2]
loc = args.rfind(",rgb")
path = args[:loc]
@@ -171,7 +171,7 @@ def parseFillCommand(line):
e.g.: fill((0,0)..controls(0.33,0.33)and(0.66,0.66)..(1,1)..controls(0.66,0)and(0.33,0)..cycle,rgb(1,0,1)+1.5);
"""
if line[-2:] != ");":
- raise xasyParseError,"Invalid syntax"
+ raise xasyParseError("Invalid syntax")
args = line[5:-2]
loc = args.rfind(",rgb")
path = args[:loc]
@@ -197,13 +197,13 @@ def parsePen(pen):
options = ""
return asyPen(color,width,options)
except:
- raise xasyParseError,"Invalid pen"
+ raise xasyParseError("Invalid pen")
def parsePathExpression(expr):
"""Parse an asy path returning an asyPath()"""
result = asyPath()
expr = "".join(expr.split())
- #print expr
+ #print (expr)
if expr.find("controls") != -1:
#parse a path with control points
tokens = expr.split("..")
@@ -211,18 +211,18 @@ def parsePathExpression(expr):
for a in range(len(nodes)):
if nodes[a] != "cycle":
nodes[a] = eval(nodes[a])
- controls = [map(eval,a.replace("controls","").split("and")) for a in tokens if a.startswith("controls")]
+ controls = [[eval(b) for b in a.replace("controls", "").split("and")] for a in tokens if a.startswith("controls")]
result.initFromControls(nodes, controls)
else:
#parse a path without control points
tokens = re.split(r"(::|--|\.\.)",expr)
linkSet = re.findall("::|--|\.\.",expr)
nodeSet = [a for a in tokens if not re.match(r"::|--|\.\.",a)]
- #print nodeSet
+ #print (nodeSet)
for a in range(len(nodeSet)):
if nodeSet[a] != "cycle":
nodeSet[a] = eval(nodeSet[a])
- #print nodeSet
+ #print (nodeSet)
result.initFromNodeList(nodeSet, linkSet)
return result
@@ -250,7 +250,7 @@ def parseLine(line,lines):
return parseFillCommand(takeUntilSemicolon(line,lines))
elif line.startswith("exitXasyMode();"):
return None
- raise Exception,"Could not parse the line"
+ raise Exception("Could not parse the line")
fileHeader = """initXasyMode();
// This file was generated by xasy. It may be edited manually, however, a strict
@@ -280,28 +280,28 @@ if __name__ == '__main__':
name = "../../xasyTest.asy"
f = open(name,"rt")
except:
- print "Could not open file."
+ print ("Could not open file.")
asy.quit()
sys.exit(1)
fileItems = []
try:
fileItems = parseFile(f)
- res = map(str,fileItems)
- print "----------------------------------"
- print "Objects in %s"%f.name
- print "----------------------------------"
+ res = [str(a) for a in fileItems]
+ print ("----------------------------------")
+ print ("Objects in {:s}".format(f.name))
+ print ("----------------------------------")
for a in res:
- print a
- print "----------------------------------"
- print "successful parse"
+ print (a)
+ print ("----------------------------------")
+ print ("successful parse")
f.close()
except:
f.close()
- print "parse failed"
+ print ("parse failed")
raise
- print "making a file"
+ print ("making a file")
f = open("testfile.asy","wt")
saveFile(f,fileItems)
f.close()