From: Jean Privat Date: Thu, 30 Jul 2009 13:39:51 +0000 (-0400) Subject: parser: correct error messages for syntax errors X-Git-Tag: v0.3~97 X-Git-Url: http://nitlanguage.org parser: correct error messages for syntax errors And get rid of the useless error_messages table. Signed-off-by: Jean Privat --- diff --git a/src/parser/lexer.nit b/src/parser/lexer.nit index fca2137..fd1edf5 100644 --- a/src/parser/lexer.nit +++ b/src/parser/lexer.nit @@ -2029,9 +2029,9 @@ class Lexer return token end else - var location = new Location(_filename, start_line + 1, accept_line + 1, start_pos + 1, accept_pos) + var location = new Location(_filename, start_line + 1, start_line + 1, start_pos + 1, start_pos + 1) if text.length > 0 then - var token = new AError.init_error("Unknown token: {text}", location) + var token = new AError.init_error("Syntax error: unknown token {text}.", location) return token else var token = new EOF(location) diff --git a/src/parser/parser.nit b/src/parser/parser.nit index 3cd9053..88d0343 100644 --- a/src/parser/parser.nit +++ b/src/parser/parser.nit @@ -102,9 +102,6 @@ special ParserTable var lexer = _lexer while true do var token = lexer.peek - var last_pos = token.location.column_start - var last_line = token.location.line_start - if token isa AError then return new Start(null, token) end @@ -145,8 +142,7 @@ special ParserTable (new ComputeProdLocationVisitor).enter_visit(node) return node else if action_type == 3 then # ERROR - var location = new Location(lexer.filename, last_line, last_line, last_pos, last_pos) - var node2 = new AError.init_error(error_messages[errors[action_value]],location) + var node2 = new AError.init_error("Syntax error: unexpected token.", token.location) var node = new Start(null, node2) return node end diff --git a/src/parser/parser_tables.nit b/src/parser/parser_tables.nit index be2c82f..1e9d1d0 100644 --- a/src/parser/parser_tables.nit +++ b/src/parser/parser_tables.nit @@ -19220,219 +19220,5 @@ abstract class ParserTable ] end - private fun error_messages: Array[String] - do - return once [ - "expecting: eol, comment, 'package', 'import', 'class', 'abstract', 'interface', 'universal', 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, 'package', 'import', 'class', 'abstract', 'interface', 'universal', 'special', 'end', 'fun', 'type', 'init', 'redef', 'is', 'do', 'readable', 'writable', 'var', 'protected', 'private', 'intrude', 'if', 'then', 'else', 'while', 'for', 'in', 'not', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'as', 'with', 'nullable', 'isset', '(', ')', '[', ']', ',', '..', '-', classid, id, attrid, number, float, char, string, start string, mid string, end string, EOF", - "expecting: EOF", - "expecting: eol, comment, 'import', 'class', 'abstract', 'interface', 'universal', 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, 'class', 'abstract', 'interface', 'universal', 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: 'package', 'import', 'class', 'abstract', 'interface', 'universal', 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: 'package', 'import', 'class', 'abstract', 'interface', 'universal', 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: comment, 'package', 'import', 'class', 'abstract', 'interface', 'universal', 'special', 'end', 'fun', 'type', 'init', 'redef', 'is', 'do', 'readable', 'writable', 'var', 'protected', 'private', 'intrude', 'if', 'then', 'else', 'while', 'for', 'in', 'not', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'as', 'with', 'nullable', 'isset', '(', ')', '[', ']', ',', '..', '-', classid, id, attrid, number, float, char, string, start string, mid string, end string, EOF", - "expecting: eol, comment", - "expecting: 'import', 'class', 'abstract', 'interface', 'universal', 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, id", - "expecting: eol, comment, 'end', 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '.', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: 'class', 'abstract', 'interface', 'universal', 'fun', 'protected', 'private', 'intrude'", - "expecting: eol, comment, 'end', 'init', 'do', 'var', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: id", - "expecting: eol, comment, 'import', 'class', 'abstract', 'interface', 'universal', 'fun', 'type', 'init', 'var'", - "expecting: eol, comment, 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, 'end', 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', 'label', '(', '[', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, 'end', EOF", - "expecting: 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'nullable', classid", - "expecting: eol, comment, 'end', 'is', 'do', 'then', 'else', 'and', 'or', 'isa', ')', '[', ']', ',', '..', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: '::'", - "expecting: eol, comment, 'end', 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'with', 'isset', '(', '[', '::', '=', '+=', '-=', '.', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: '[', '=', '+=', '-=', '.'", - "expecting: 'import', 'class', 'abstract', 'interface', 'universal', 'fun'", - "expecting: eol, comment, EOF", - "expecting: '[', '.'", - "expecting: mid string, end string", - "expecting: 'super'", - "expecting: 'super', classid, id", - "expecting: eol, comment, 'import', 'class', 'abstract', 'interface', 'universal', 'end', 'fun', 'type', 'init', 'redef', 'do', 'readable', 'writable', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: 'class', 'abstract', 'interface', 'universal', 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: 'import', 'class', 'abstract', 'interface', 'universal', 'special', 'end', 'fun', 'type', 'init', 'redef', 'is', 'do', 'readable', 'writable', 'var', 'protected', 'private', 'intrude', 'if', 'then', 'else', 'in', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'as', 'with', 'nullable', 'isset', '(', ')', '[', ']', ',', '..', '-', classid, id, attrid, number, float, char, string, start string, mid string, end string", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '(', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'init', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'init', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: 'init', 'new', 'super', 'self', 'true', 'false', 'null', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', ')', '[', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '(', '::', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'end', 'else', 'with', EOF", - "expecting: eol, comment, 'end', 'else', 'and', 'or', 'with', EOF", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '+', '-', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: 'class', 'abstract', 'interface', 'universal', 'fun'", - "expecting: eol, comment, 'end', 'label', EOF", - "expecting: 'end', 'init', 'do', 'var', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', ':', '=', EOF", - "expecting: 'import', 'class', 'abstract', 'interface', 'universal', 'fun', 'type', 'init', 'var'", - "expecting: eol, comment, 'end', 'is', 'do', 'then', 'else', 'and', 'or', 'isa', '(', ')', '[', ']', ',', '..', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: eol, comment, 'init', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'init', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: 'init', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', 'is', 'and', 'or', 'isa', 'with', '(', '[', '::', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'end', 'do', 'then', 'else', 'and', 'or', ')', ']', ',', '..', mid string, end string, EOF", - "expecting: eol, comment, 'end', 'is', 'do', 'then', 'else', 'and', 'or', 'isa', ')', ']', ',', '..', '+', '-', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: eol, comment, 'end', 'is', 'do', 'then', 'else', 'and', 'or', 'isa', ')', ']', ',', '..', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: eol, comment, 'end', 'is', 'and', 'or', 'isa', '[', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'end', 'is', 'and', 'or', 'isa', 'with', '(', '[', ':', '::', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: 'nullable', classid", - "expecting: eol, comment, 'end', 'is', 'do', 'then', 'else', 'and', 'or', 'isa', '(', ')', '[', ']', ',', '::', '..', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: ')'", - "expecting: eol, comment, 'super'", - "expecting: eol, comment, 'super', classid, id", - "expecting: eol, comment, 'end', 'with', EOF", - "expecting: eol, comment, 'end', id", - "expecting: eol, comment, classid", - "expecting: 'class'", - "expecting: '[', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', id", - "expecting: 'init', 'do', 'var', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, 'init', 'as', id, attrid", - "expecting: eol, comment, 'end', 'is', 'do', 'then', 'else', 'and', 'or', 'isa', 'with', ')', '[', ']', ',', '..', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: 'fun', 'init', 'redef', 'do', 'var', 'protected', 'private', 'intrude', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: 'init', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: 'init', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: '.'", - "expecting: 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', ')', '[', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', '=', EOF", - "expecting: eol, comment, 'then'", - "expecting: eol, comment, 'do'", - "expecting: eol, comment, 'in'", - "expecting: 'init', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: 'init', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', 'is', 'and', 'or', 'isa', 'with', '[', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'end', 'init', 'if', 'else', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: classid", - "expecting: eol, comment, 'special', 'end', 'fun', 'type', 'init', 'redef', 'is', 'do', 'readable', 'writable', 'var', 'protected', 'private', 'intrude', 'then', 'else', 'and', 'or', 'isa', 'with', '(', ')', '[', ']', ',', '=', '...', '..', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: eol, comment, ']', ',', '..'", - "expecting: 'do', id", - "expecting: 'with'", - "expecting: 'end', id", - "expecting: ']'", - "expecting: eol, comment, 'is', 'do', 'with', '(', ':'", - "expecting: eol, comment, 'is', 'do', 'with', '(', ':', '='", - "expecting: 'init', 'as', id, attrid", - "expecting: eol, comment, mid string, end string", - "expecting: 'fun', 'protected', 'private', 'intrude'", - "expecting: 'fun'", - "expecting: eol, comment, 'end', 'else', 'with', '[', '=', '+=', '-=', '.', EOF", - "expecting: eol, comment, ')', ','", - "expecting: 'then'", - "expecting: 'do'", - "expecting: 'in'", - "expecting: eol, comment, 'end', 'is', 'do', 'then', 'else', 'and', 'or', 'isa', '(', ')', ']', ',', '..', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: ']', ',', '..'", - "expecting: eol, comment, 'do', ','", - "expecting: eol, comment, ')', id", - "expecting: 'is', 'do'", - "expecting: eol, comment, 'is', 'do', 'with', ':'", - "expecting: eol, comment, 'is', 'do', 'with'", - "expecting: 'is', 'do', 'with'", - "expecting: eol, comment, 'special', 'end', 'fun', 'type', 'init', 'redef', 'readable', 'writable', 'var', 'protected', 'private', 'intrude', '['", - "expecting: eol, comment, ']', ','", - "expecting: eol, comment, '('", - "expecting: eol, comment, 'end', 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'with', 'isset', '(', '[', '=', '+=', '-=', '.', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: ')', ','", - "expecting: eol, comment, 'end', 'else', 'and', 'or', 'with', '+', '-', EOF", - "expecting: eol, comment, 'end', 'is', 'do', 'else', 'with', ')', ']', ',', '=', '...', EOF", - "expecting: eol, comment, 'end', 'init', 'do', 'var', 'if', 'else', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', 'do', 'then', 'else', 'and', 'or', ')', ']', ',', '..', '+', '-', mid string, end string, EOF", - "expecting: eol, comment, 'end', 'is', 'and', 'or', 'isa', 'with', '(', '[', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'end', 'is', 'do', 'then', 'else', 'and', 'or', 'isa', 'with', ')', '[', ']', ',', '=', '+=', '-=', '..', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: eol, comment, 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: ')', ']', ','", - "expecting: ']', ','", - "expecting: 'end', 'init', 'do', 'var', 'if', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', 'with', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: ','", - "expecting: ')', id", - "expecting: 'extern'", - "expecting: eol, comment, 'break', id", - "expecting: eol, comment, 'special', 'end', 'fun', 'type', 'init', 'redef', 'readable', 'writable', 'var', 'protected', 'private', 'intrude'", - "expecting: 'special', 'end', 'fun', 'type', 'init', 'redef', 'readable', 'writable', 'var', 'protected', 'private', 'intrude'", - "expecting: '('", - "expecting: eol, comment, 'end', 'init', 'if', 'else', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '[', '.', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, 'end', 'init', 'if', 'else', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', 'label', '(', '[', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, 'end', 'else', EOF", - "expecting: eol, comment, 'end', 'init', 'if', 'else', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'with', 'isset', '(', '[', '::', '=', '+=', '-=', '.', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: 'end', 'init', 'do', 'var', 'if', 'else', 'while', 'for', 'return', 'continue', 'break', 'abort', 'assert', 'new', 'super', 'self', 'true', 'false', 'null', '(', '[', classid, id, attrid, number, float, char, string, start string", - "expecting: 'else'", - "expecting: eol, comment, ']'", - "expecting: 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, ')', ',', ':'", - "expecting: eol, comment, string", - "expecting: eol, comment, 'end'", - "expecting: eol, comment, 'end', 'fun', 'type', 'init', 'redef', 'readable', 'writable', 'var', 'protected', 'private', 'intrude'", - "expecting: 'fun', 'type', 'init', 'readable', 'writable', 'var', 'protected', 'private', 'intrude'", - "expecting: 'redef', 'writable', 'var', 'protected', 'private', 'intrude'", - "expecting: 'redef', 'var', 'protected', 'private', 'intrude'", - "expecting: 'fun', 'type', 'init', 'var'", - "expecting: eol, comment, 'not', 'nullable', classid", - "expecting: eol, comment, 'end', 'else', 'label', EOF", - "expecting: eol, comment, 'end', 'else', ':', '=', EOF", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '(', '[', '::', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', '[', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '(', '[', ':', '::', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, ')', ']', ','", - "expecting: eol, comment, 'is', 'and', 'or', 'isa', '(', '[', ']', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>'", - "expecting: eol, comment, 'init', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'init', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'is', 'and', 'or', 'isa', '[', ']', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>'", - "expecting: 'init', 'new', 'super', 'self', 'true', 'false', 'null', '(', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'is', 'and', 'or', 'isa', '(', '[', ']', '::', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>'", - "expecting: eol, comment, '[', ']'", - "expecting: eol, comment, 'and', 'or', '[', ']'", - "expecting: eol, comment, 'is', 'and', 'or', 'isa', '[', ']', '+', '-', '==', '!=', '<', '<=', '>', '>=', '<=>'", - "expecting: eol, comment, 'is', 'and', 'or', 'isa', '[', ']', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>'", - "expecting: eol, comment, ')', ',', '...'", - "expecting: eol, comment, 'do', '(', ':'", - "expecting: eol, comment, ']', ',', ':'", - "expecting: 'end', 'fun', 'type', 'init', 'redef', 'readable', 'writable', 'var', 'protected', 'private', 'intrude'", - "expecting: 'writable', 'var', 'protected', 'private', 'intrude'", - "expecting: 'var'", - "expecting: 'var', 'protected', 'private', 'intrude'", - "expecting: eol, comment, 'do', 'with', '(', '[', ':', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', id", - "expecting: attrid", - "expecting: 'not', 'nullable', classid", - "expecting: eol, comment, 'else'", - "expecting: eol, comment, 'end', 'else', '=', EOF", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '[', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'special', 'end', 'fun', 'type', 'init', 'redef', 'is', 'do', 'readable', 'writable', 'var', 'protected', 'private', 'intrude', 'then', 'else', 'and', 'or', 'isa', 'with', '(', ')', ']', ',', '=', '...', '..', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', mid string, end string, EOF", - "expecting: 'init', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: 'init', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '(', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: '[', ']'", - "expecting: eol, comment, 'do', ':'", - "expecting: ':'", - "expecting: eol, comment, 'do', 'with', '(', ':'", - "expecting: eol, comment, ':', '='", - "expecting: eol, comment, 'null'", - "expecting: eol, comment, ')'", - "expecting: eol, comment, 'end', 'init', 'if', 'else', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'with', 'isset', '(', '[', '=', '+=', '-=', '.', '-', classid, id, attrid, number, float, char, string, start string, EOF", - "expecting: eol, comment, '='", - "expecting: 'null'", - "expecting: eol, comment, 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', 'is', 'else', 'and', 'or', 'isa', 'with', '(', '[', '.', '+', '-', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '<=>', EOF", - "expecting: eol, comment, 'and', 'or', '[', ']', '+', '-'", - "expecting: 'abstract', 'intern', 'extern'", - "expecting: 'init', 'if', 'not', 'new', 'once', 'super', 'self', 'true', 'false', 'null', 'isset', '-', classid, id, attrid, number, float, char, string, start string", - "expecting: eol, comment, 'end', 'do', 'then', 'else', ')', ']', ',', '..', mid string, end string, EOF" - ] - end - - private fun errors: Array[Int] - do - return once [ - 0,1,1,2,3,3,2,2,4,5,6,7,8,3,4,1,1,2,9,8,3,4,10,11,12,13,14,15,15,15,16,16,10,17,18,18,19,20,21,11,22,22,22,22,20,16,23,24,25,22,22,22,22,16,26,27,19,19,19,19,19,19,19,28,22,29,16,22,30,31,30,31,1,32,32,33,3,2,8,4,2,4,34,8,1,1,1,33,2,8,4,2,8,35,14,36,16,37,21,38,36,39,39,39,39,40,41,38,42,39,39,39,39,39,39,22,19,30,43,44,44,44,45,46,46,46,39,47,48,19,49,50,51,51,51,20,20,14,52,16,53,21,54,52,55,54,56,22,19,19,57,57,57,58,59,59,59,60,30,14,17,19,17,19,61,20,19,62,22,19,63,64,22,20,65,66,25,67,20,20,20,20,68,69,70,69,69,71,69,27,72,2,27,16,73,25,16,74,29,16,74,29,20,11,23,31,30,1,2,75,33,8,33,33,2,8,47,33,2,33,33,2,8,33,8,41,39,20,76,62,77,39,21,39,78,79,77,39,36,37,37,38,21,38,38,38,38,38,38,38,38,38,38,38,38,73,71,69,19,48,8,21,16,80,81,82,83,20,84,62,85,22,28,85,86,53,53,54,21,54,54,54,54,54,54,54,54,54,54,54,54,73,86,52,87,19,19,20,19,88,89,78,22,22,73,22,90,30,31,20,20,91,19,19,92,19,19,93,69,94,95,95,95,95,95,95,95,95,95,95,95,95,96,95,88,27,27,2,20,97,20,20,20,29,74,98,22,19,99,100,33,2,33,2,33,33,2,33,2,2,33,33,2,33,3,79,81,44,36,46,62,73,101,102,46,39,76,76,77,62,77,77,77,77,77,77,77,77,77,77,77,77,97,95,88,19,49,8,62,20,16,103,104,105,81,57,106,59,73,59,19,84,84,85,62,85,85,85,85,85,85,85,85,85,85,85,85,97,19,89,21,10,97,107,19,19,13,108,108,19,8,8,96,95,109,110,111,110,112,113,114,115,11,116,117,25,19,19,98,29,100,2,2,33,2,2,2,33,2,74,102,103,10,46,78,97,118,44,44,119,44,46,46,119,119,119,119,119,119,119,46,46,46,36,116,36,39,110,114,48,49,120,19,20,121,13,16,103,59,97,57,57,122,57,59,59,122,122,122,122,122,122,122,59,59,59,52,123,22,21,62,14,52,124,16,125,126,127,48,19,128,13,129,3,3,95,130,131,13,110,112,113,110,113,132,113,113,69,133,133,8,134,133,127,22,19,135,25,67,20,20,29,2,2,118,16,14,39,101,118,39,135,39,131,13,133,8,134,133,19,48,19,19,136,13,14,16,13,16,10,87,137,137,138,20,136,139,25,19,19,28,30,140,141,141,141,141,141,141,141,141,48,19,49,20,16,22,86,62,115,142,52,22,20,143,124,126,19,48,8,48,19,128,10,111,144,102,145,19,146,19,49,110,113,10,14,113,88,8,134,133,147,21,4,148,149,150,151,133,8,134,152,20,20,19,19,19,74,118,20,36,101,152,145,146,8,134,133,147,4,8,134,19,138,153,49,141,154,20,19,20,14,155,138,156,141,87,141,87,141,157,20,141,138,25,43,20,20,73,25,136,8,19,13,19,48,8,82,20,19,142,21,115,115,94,22,158,159,16,160,21,161,159,162,162,162,162,163,20,161,164,162,162,162,162,162,162,30,165,166,166,166,167,168,168,168,162,19,128,8,19,48,8,14,169,10,102,64,102,8,8,19,8,14,170,171,115,147,4,8,134,147,8,172,147,62,149,150,151,173,150,174,175,174,71,88,176,177,147,4,178,19,19,74,179,39,178,8,8,147,4,8,134,172,147,147,4,138,153,8,16,180,81,82,83,181,73,181,141,141,141,20,20,91,92,141,141,141,141,97,20,20,138,140,8,19,19,49,8,104,179,94,62,115,182,126,162,20,183,62,184,162,21,162,78,64,184,162,159,185,160,160,161,21,161,161,161,161,161,161,161,161,161,161,161,161,73,48,128,19,128,8,108,102,14,111,102,64,49,8,170,82,186,82,115,69,115,94,115,172,147,147,4,147,4,147,172,133,173,150,174,175,174,71,88,176,177,150,174,175,174,177,174,177,95,187,188,104,189,172,147,190,191,141,190,191,172,147,147,4,4,172,172,147,138,49,8,20,16,103,104,105,141,97,141,141,141,13,108,141,136,192,25,141,141,19,140,48,49,13,141,182,115,81,166,88,159,159,168,62,73,162,168,162,22,22,183,183,184,62,184,184,184,184,184,184,184,184,184,184,184,184,97,19,48,48,128,102,111,19,49,82,13,113,82,88,133,115,94,4,172,172,147,4,150,174,175,174,177,174,177,95,187,188,104,189,175,174,177,174,177,189,177,189,110,8,104,13,16,193,4,172,194,64,195,194,64,4,172,172,147,4,4,172,153,49,141,20,121,13,16,196,153,128,141,13,138,25,43,20,20,19,19,48,48,19,49,16,103,159,10,168,78,97,166,166,197,166,168,168,197,197,197,197,197,197,197,168,168,168,159,116,159,162,19,19,48,19,13,113,8,115,133,4,4,172,175,174,177,174,177,189,177,189,110,8,104,13,16,193,174,177,189,177,189,16,193,189,16,193,198,13,13,146,20,16,4,191,22,199,191,39,4,4,172,4,138,153,141,141,153,49,141,20,181,138,153,8,153,128,141,20,20,141,141,141,19,19,48,8,20,16,14,162,162,135,162,19,8,113,4,174,177,189,177,189,16,193,189,16,193,198,13,13,146,20,16,177,189,16,193,189,16,193,20,16,16,193,20,16,8,8,145,146,146,8,8,20,64,43,64,4,138,13,138,153,8,82,141,138,128,8,138,153,8,141,141,19,49,8,200,20,159,152,113,177,189,16,193,189,16,193,20,16,16,193,20,16,8,8,145,146,146,8,8,20,189,16,193,20,16,16,193,20,16,8,20,20,16,8,20,8,8,8,8,22,39,138,49,141,141,138,49,8,104,153,128,138,128,8,48,49,179,162,178,189,16,193,20,16,16,193,20,16,8,20,20,16,8,20,8,8,8,8,16,193,20,16,8,20,20,16,8,20,8,8,20,8,138,8,153,49,13,138,153,153,128,19,48,141,190,191,16,193,20,16,8,20,20,16,8,20,8,8,20,8,20,16,8,20,8,8,20,8,8,49,8,138,153,153,49,141,138,138,153,19,125,194,64,20,16,8,20,8,8,20,8,8,8,20,8,8,138,49,138,138,153,8,138,143,191,162,8,20,8,8,8,138,138,49,8,165,64,8,153,49,162,138,153,138 - ] - end - init do end end diff --git a/src/parser/xss/lexer.xss b/src/parser/xss/lexer.xss index b2ffd9b..3e8a246 100644 --- a/src/parser/xss/lexer.xss +++ b/src/parser/xss/lexer.xss @@ -213,9 +213,9 @@ $ end end $ end foreach else - var location = new Location(_filename, start_line + 1, accept_line + 1, start_pos + 1, accept_pos) + var location = new Location(_filename, start_line + 1, start_line + 1, start_pos + 1, start_pos + 1) if text.length > 0 then - var token = new PError.init_error("Unknown token: {text}", location) + var token = new PError.init_error("Syntax error: unknown token {text}.", location) return token else var token = new EOF(location) diff --git a/src/parser/xss/parser.xss b/src/parser/xss/parser.xss index 38b3603..ca42350 100644 --- a/src/parser/xss/parser.xss +++ b/src/parser/xss/parser.xss @@ -114,9 +114,6 @@ special ParserTable var lexer = _lexer while true do var token = lexer.peek - var last_pos = token.location.column_start - var last_line = token.location.line_start - if token isa PError then return new Start(null, token) end @@ -157,8 +154,7 @@ special ParserTable (new ComputeProdLocationVisitor).enter_visit(node) return node else if action_type == 3 then # ERROR - var location = new Location(lexer.filename, last_line, last_line, last_pos, last_pos) - var node2 = new PError.init_error(error_messages[errors[action_value]],location) + var node2 = new PError.init_error("Syntax error: unexpected token.", token.location) var node = new Start(null, node2) return node end @@ -383,22 +379,6 @@ $ end foreach ] end - private fun error_messages: Array[String] - do - return once [ -$ foreach {parser_data/error_messages/msg} - "${sablecc:string2escaped_unicode(.)}"[-sep ','-] -$ end - ] - end - - private fun errors: Array[Int] - do - return once [ - [-foreach {parser_data/errors/i}-]${.}[-sep ','-][-end-] - ] - end - init do end end $ end template diff --git a/tests/error_syntax.nit b/tests/error_syntax.nit new file mode 100644 index 0000000..104aa6b --- /dev/null +++ b/tests/error_syntax.nit @@ -0,0 +1,20 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2009 Jean Privat +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class A + #alt1#once + ?&* +end diff --git a/tests/sav/base_inline_statement_alt1.sav b/tests/sav/base_inline_statement_alt1.sav index 2907158..094ff85 100644 --- a/tests/sav/base_inline_statement_alt1.sav +++ b/tests/sav/base_inline_statement_alt1.sav @@ -1 +1 @@ -alt/base_inline_statement_alt1.nit:24,23: expecting: EOF +alt/base_inline_statement_alt1.nit:24,23--25: Syntax error: unexpected token. diff --git a/tests/sav/base_inline_statement_alt2.sav b/tests/sav/base_inline_statement_alt2.sav index 60b5d23..34fe353 100644 --- a/tests/sav/base_inline_statement_alt2.sav +++ b/tests/sav/base_inline_statement_alt2.sav @@ -1 +1 @@ -alt/base_inline_statement_alt2.nit:56,59: expecting: EOF +alt/base_inline_statement_alt2.nit:56,59--62: Syntax error: unexpected token. diff --git a/tests/sav/base_inline_statement_alt3.sav b/tests/sav/base_inline_statement_alt3.sav index 27a5c2a..a8513f8 100644 --- a/tests/sav/base_inline_statement_alt3.sav +++ b/tests/sav/base_inline_statement_alt3.sav @@ -1 +1 @@ -alt/base_inline_statement_alt3.nit:60,1: expecting: EOF +alt/base_inline_statement_alt3.nit:60,1--4: Syntax error: unexpected token. diff --git a/tests/sav/error_syntax.sav b/tests/sav/error_syntax.sav new file mode 100644 index 0000000..a22e467 --- /dev/null +++ b/tests/sav/error_syntax.sav @@ -0,0 +1 @@ +./error_syntax.nit:19,2: Syntax error: unknown token ?. diff --git a/tests/sav/error_syntax_alt1.sav b/tests/sav/error_syntax_alt1.sav new file mode 100644 index 0000000..0716b24 --- /dev/null +++ b/tests/sav/error_syntax_alt1.sav @@ -0,0 +1 @@ +alt/error_syntax_alt1.nit:18,2--5: Syntax error: unexpected token.