Commit 1852506c authored by acholewa's avatar acholewa

Fixed a very subtle bug that sometimes occasionally caused multiple statements...

Fixed a very subtle bug that sometimes occasionally caused multiple statements to be grouped into a single statement, resulting in nonsensical error messages despite having a well-formed theory.
parent 0bcfb8d4
......@@ -149,10 +149,10 @@ def lex_code(pslFile):
errorMsgs = []
for i in range(len(numberedLines)):
line, num = numberedLines[i]
for i in range(len(line)):
token = line[i]
for j in range(len(line)):
token = line[j].strip()
try:
nextToken = line[i+1]
nextToken = line[j+1]
except IndexError:
try:
nextToken = numberedLines[i+1][0][0]
......@@ -168,7 +168,7 @@ def lex_code(pslFile):
nextNextToken = ''
else:
try:
nextNextToken = line[i+2]
nextNextToken = line[j+2]
except IndexError:
try:
nextNextToken = numberedLines[i+1][0][0]
......@@ -294,7 +294,7 @@ def gen_intermediate(parseTree, theoryFileName):
otherDef = defMap[(defPair.role(), defPair.term())]
raise pslErrors.TranslationError(' '.join([pslErrors.error, pslErrors.color_line_number(defPair.lineNum) + ",",
otherDef[DEF_LINE_NUM], "Term", pslErrors.color_token(defPair.term()),
"has multiple shorthands: ", pslErrors.color_token(defPair.shorthands()) + ",",
"has multiple shorthands: ", pslErrors.color_token(defPair.shorthand()) + ",",
pslErrors.color_token(otherDef[DEF_SHORTHAND])]))
else:
defMap[(defPair.role(), defPair.term())] = (defPair.shorthand(), defPair.lineNum)
......
......@@ -1242,7 +1242,8 @@ class DefDecl(PSLStmtNode):
node.children.append(Token(node, [token], lineNum))
roleNameFound = True
elif roleNameFound:
raise pslErrors.SyntaxError(' '.join([pslErrors.error, pslErrors.color_line_number(lineNum), "Unexpected token: ", pslErrors.color_token(token) + ".",
raise pslErrors.SyntaxError(' '.join([pslErrors.error, pslErrors.color_line_number(lineNum), "Unexpected token: ",
pslErrors.color_token(token) + ".",
"Expected a statement of the form:", pslErrors.color_token(' '.join(defSyntax.tokens))]))
equalityIndex = stmt.tokens.index('=')
defs = zip(stmt.tokens[equalityIndex+1:], stmt.lineNums[equalityIndex+1:])
......@@ -1254,9 +1255,11 @@ class DefDecl(PSLStmtNode):
lastDef = node.children[-1]
lastDefTokens = [lastDef.children[0], ':=']
lastDefTokens.extend([token.get_token() for token in lastDef.children[1]])
raise pslErrors.SyntaxError(' '.join([pslErrors.error, pslErrors.color_line_number(lineNum), "Missing comma before definition:", ' '.join(lastDefTokens)]))
raise pslErrors.SyntaxError(' '.join([pslErrors.error, pslErrors.color_line_number(lineNum),
"Missing comma before definition:", ' '.join(lastDefTokens)]))
elif token == ',' and colonEqualsFound:
raise pslErrors.SyntaxError(' '.join([pslErrors.error, pslErrors.color_line_number(lineNum), "Missing identifier for term: ", ' '.join([token.get_token() for token in term]) + "."]))
raise pslErrors.SyntaxError(' '.join([pslErrors.error, pslErrors.color_line_number(lineNum),
"Missing identifier for term: ", ' '.join([token.get_token() for token in term]) + "."]))
if colonEqualsFound:
roleName = token
node.children.append(DefPair(node, children=[roleName, list(reversed(term))], lineNum=lineNum))
......@@ -1268,7 +1271,8 @@ class DefDecl(PSLStmtNode):
else:
term.append(Token(node, [token], lineNum))
if colonEqualsFound:
raise pslErrors.SyntaxError(' '.join([pslErrors.error, pslErrors.color_line_number(lineNum), "Missing identifier for term: ", ' '.join([token.get_token() for token in term]) + "."]))
raise pslErrors.SyntaxError(' '.join([pslErrors.error, pslErrors.color_line_number(lineNum),
"Missing identifier for term: ", ' '.join([token.get_token() for token in term]) + "."]))
return node
def translate(self):
......@@ -1423,13 +1427,6 @@ class StepStmt(PSLStmtNode):
return {firstRole:firstRoleVars, secondRole:secondRoleVars}
class DefList(Node):
@staticmethod
def parse(stmt, parent):
raise NotImplementedError()
class Intruder(PSLSection):
className = "Intruder"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment