Commit 1852506c authored by acholewa's avatar acholewa
Browse files

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): ...@@ -149,10 +149,10 @@ def lex_code(pslFile):
errorMsgs = [] errorMsgs = []
for i in range(len(numberedLines)): for i in range(len(numberedLines)):
line, num = numberedLines[i] line, num = numberedLines[i]
for i in range(len(line)): for j in range(len(line)):
token = line[i] token = line[j].strip()
try: try:
nextToken = line[i+1] nextToken = line[j+1]
except IndexError: except IndexError:
try: try:
nextToken = numberedLines[i+1][0][0] nextToken = numberedLines[i+1][0][0]
...@@ -168,7 +168,7 @@ def lex_code(pslFile): ...@@ -168,7 +168,7 @@ def lex_code(pslFile):
nextNextToken = '' nextNextToken = ''
else: else:
try: try:
nextNextToken = line[i+2] nextNextToken = line[j+2]
except IndexError: except IndexError:
try: try:
nextNextToken = numberedLines[i+1][0][0] nextNextToken = numberedLines[i+1][0][0]
...@@ -294,7 +294,7 @@ def gen_intermediate(parseTree, theoryFileName): ...@@ -294,7 +294,7 @@ def gen_intermediate(parseTree, theoryFileName):
otherDef = defMap[(defPair.role(), defPair.term())] otherDef = defMap[(defPair.role(), defPair.term())]
raise pslErrors.TranslationError(' '.join([pslErrors.error, pslErrors.color_line_number(defPair.lineNum) + ",", raise pslErrors.TranslationError(' '.join([pslErrors.error, pslErrors.color_line_number(defPair.lineNum) + ",",
otherDef[DEF_LINE_NUM], "Term", pslErrors.color_token(defPair.term()), 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])])) pslErrors.color_token(otherDef[DEF_SHORTHAND])]))
else: else:
defMap[(defPair.role(), defPair.term())] = (defPair.shorthand(), defPair.lineNum) defMap[(defPair.role(), defPair.term())] = (defPair.shorthand(), defPair.lineNum)
......
...@@ -1242,7 +1242,8 @@ class DefDecl(PSLStmtNode): ...@@ -1242,7 +1242,8 @@ class DefDecl(PSLStmtNode):
node.children.append(Token(node, [token], lineNum)) node.children.append(Token(node, [token], lineNum))
roleNameFound = True roleNameFound = True
elif roleNameFound: 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))])) "Expected a statement of the form:", pslErrors.color_token(' '.join(defSyntax.tokens))]))
equalityIndex = stmt.tokens.index('=') equalityIndex = stmt.tokens.index('=')
defs = zip(stmt.tokens[equalityIndex+1:], stmt.lineNums[equalityIndex+1:]) defs = zip(stmt.tokens[equalityIndex+1:], stmt.lineNums[equalityIndex+1:])
...@@ -1254,9 +1255,11 @@ class DefDecl(PSLStmtNode): ...@@ -1254,9 +1255,11 @@ class DefDecl(PSLStmtNode):
lastDef = node.children[-1] lastDef = node.children[-1]
lastDefTokens = [lastDef.children[0], ':='] lastDefTokens = [lastDef.children[0], ':=']
lastDefTokens.extend([token.get_token() for token in lastDef.children[1]]) 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: 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: if colonEqualsFound:
roleName = token roleName = token
node.children.append(DefPair(node, children=[roleName, list(reversed(term))], lineNum=lineNum)) node.children.append(DefPair(node, children=[roleName, list(reversed(term))], lineNum=lineNum))
...@@ -1268,7 +1271,8 @@ class DefDecl(PSLStmtNode): ...@@ -1268,7 +1271,8 @@ class DefDecl(PSLStmtNode):
else: else:
term.append(Token(node, [token], lineNum)) term.append(Token(node, [token], lineNum))
if colonEqualsFound: 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 return node
def translate(self): def translate(self):
...@@ -1423,13 +1427,6 @@ class StepStmt(PSLStmtNode): ...@@ -1423,13 +1427,6 @@ class StepStmt(PSLStmtNode):
return {firstRole:firstRoleVars, secondRole:secondRoleVars} return {firstRole:firstRoleVars, secondRole:secondRoleVars}
class DefList(Node):
@staticmethod
def parse(stmt, parent):
raise NotImplementedError()
class Intruder(PSLSection): class Intruder(PSLSection):
className = "Intruder" 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