Prechádzať zdrojové kódy

Merge branch 'fixLexerRecover' of LInE/ivprog into master

Lucas de Souza 4 rokov pred
rodič
commit
0f04b6bed5

+ 2 - 1
i18n/pt/error.json

@@ -93,5 +93,6 @@
   "inform_valid_global_duplicated": "Já existe uma variável global com o nome <span class='ivprog-error-varname'>$0</span>, você precisa de nomes distintos.",
   "inform_valid_variable_duplicated" : "Já existe uma variável com o nome <span class='ivprog-error-varname'>$0</span> na função <span class='ivprog-error-varname'>$1</span>, você precisa de nomes distintos.",
   "inform_valid_function_duplicated" : "Já existe uma função com o nome <span class='ivprog-error-varname'>$0</span>, você precisa de nomes distintos.",
-  "inform_valid_param_duplicated" : "Já existe um parâmetro com o nome <span class='ivprog-error-varname'>$0</span> na função <span class='ivprog-error-varname'>$1</span>, você precisa de nomes distintos."
+  "inform_valid_param_duplicated" : "Já existe um parâmetro com o nome <span class='ivprog-error-varname'>$0</span> na função <span class='ivprog-error-varname'>$1</span>, você precisa de nomes distintos.",
+  "invalid_character": "O caractere $0 na linha $1 não pode ser utilizado neste contexto."
 }

+ 4 - 0
js/ast/error/syntaxErrorFactory.js

@@ -68,5 +68,9 @@ export const SyntaxErrorFactory = Object.freeze({
   duplicate_variable: (token) => {
     const context = [token.text, token.line, token.column];
     return new SyntaxError(LocalizedStrings.getError("duplicate_variable", context));
+  },
+  invalid_character: (text, line, column) => {
+    const context = [text, line];
+    return new SyntaxError(LocalizedStrings.getError("invalid_character", context));
   }
 });

+ 11 - 0
js/ast/ivprogLexer.js

@@ -0,0 +1,11 @@
+import { SyntaxErrorFactory } from "./error/syntaxErrorFactory";
+
+export function recover (_) {
+    const start = this._tokenStartCharIndex;
+    const stop = this._input.index;
+    let text = this._input.getText(start, stop);
+    text = this.getErrorDisplay(text);
+    const line = this._tokenStartLine;
+    const column = this._tokenStartColumn;
+    throw SyntaxErrorFactory.invalid_character(text, line, column);
+}

+ 2 - 0
js/ast/ivprogParser.js

@@ -1,6 +1,7 @@
 import { CommonTokenStream, InputStream } from 'antlr4/index';
 import * as Expressions from './expressions/';
 import * as Commands from './commands/';
+import { recover } from "./ivprogLexer";
 import { toInt, toString, toBool, toReal } from './../typeSystem/parsers';
 import { Types } from "./../typeSystem/types";
 import { CompoundType } from "./../typeSystem/compoundType";
@@ -35,6 +36,7 @@ export class IVProgParser {
   constructor (input, lexerClass) {
     this.lexerClass = lexerClass;
     this.lexer = new lexerClass(new InputStream(input));
+    this.lexer.recover = recover.bind(this.lexer);
     this.tokenStream = new CommonTokenStream(this.lexer);
     this.tokenStream.fill();
     this.pos = 1;