Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix error message to say that a ')' and not a ',' is expected at the …
…end of rules.
  • Loading branch information
VittGam committed Apr 15, 2018
1 parent 65f1d6f commit 9a32492
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/TuringMachine.js
Expand Up @@ -104,20 +104,23 @@ var TuringMachine = function(obj){
var openpIdx = unescapedIndexOf(input, '(');
var commaIdx;
var closeIdx;
var commaError;
if (currtype === 4) { // parsing movement, it's the last part of the 5-uple
commaIdx = unescapedIndexOf(input, ')');
closeIdx = -1;
commaError = 'READ_ERROR_EXPECTED_END_OF_RULE';
} else {
commaIdx = unescapedIndexOf(input, ',');
closeIdx = unescapedIndexOf(input, ')');
commaError = 'READ_ERROR_EXPECTED_COMMA';
}
var nlineIdx = input.indexOf('\n');
if (openpIdx !== -1 && openpIdx < commaIdx) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
} else if (closeIdx !== -1 && closeIdx < commaIdx) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
} else if (nlineIdx !== -1 && nlineIdx < commaIdx) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
var part = input.substring(0, commaIdx).replace(new RegExp('^\\s\\s*'), '').replace(new RegExp('\\s\\s*$'), '');
input = input.substring(commaIdx + 1);
Expand Down Expand Up @@ -145,47 +148,47 @@ var TuringMachine = function(obj){
throw new TMError('READ_ERROR_WRONG_CHARACTER_CLASS');
}
if (open2Idx !== -1 || clos2Idx !== -1) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
if (caretIdx !== -1 && caretIdx !== open1Idx + 1) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
if (currtype !== 0 && currtype !== 2 && ((open1Idx !== 0) || (clos1Idx !== part.length - 1))) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
if ((currtype === 0 || currtype === 2) && unescapedIndexOf(part, '[', open1Idx + 1) !== -1) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
if ((currtype === 0 || currtype === 2) && unescapedIndexOf(part, ']', clos1Idx + 1) !== -1) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
return parsegroup(0, grplength, part.substring(open1Idx + 1, clos1Idx), part.substring(0, open1Idx), part.substring(clos1Idx + 1));
} else if (open2Idx !== -1) {
if (clos2Idx === -1) {
throw new TMError('READ_ERROR_WRONG_CHARACTER_CLASS');
}
if (open1Idx !== -1 || clos1Idx !== -1) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
if (caretIdx !== -1 && caretIdx !== open2Idx + 1) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
if (currtype !== 0 && currtype !== 2 && ((open2Idx !== 0) || (clos2Idx !== part.length - 1))) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
if ((currtype === 0 || currtype === 2) && unescapedIndexOf(part, '{', open2Idx + 1) !== -1) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
if ((currtype === 0 || currtype === 2) && unescapedIndexOf(part, '}', clos2Idx + 1) !== -1) {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
return parsegroup(1, grplength, part.substring(open2Idx + 1, clos2Idx), part.substring(0, open2Idx), part.substring(clos2Idx + 1));
}
if (currtype !== 0 && currtype !== 2) { // not the states
return parsegroup((part.length > 1 ? 2 : 3), grplength, part, '', '');
}
if (part.charAt(part.length - 1) === '\\' && part.charAt(part.length - 2) !== '\\') {
throw new TMError('READ_ERROR_EXPECTED_COMMA');
throw new TMError(commaError);
}
return normalizestate(part);
};
Expand Down
2 changes: 2 additions & 0 deletions lib/i18n.js
Expand Up @@ -19,6 +19,7 @@ lang.en = {
SYNTAX_ERROR_LABEL: 'Syntax error at line %d:',
READ_ERROR: 'A read error occurred',
READ_ERROR_EXPECTED_COMMA: 'A "," was expected as separator',
READ_ERROR_EXPECTED_END_OF_RULE: 'A ")" was expected at the end of the rule',
READ_ERROR_EMPTY_SOURCE_STATUS: 'A read error occurred while reading the source status',
READ_ERROR_EMPTY_SOURCE_SYMBOL: 'A read error occurred while reading the source symbol',
READ_ERROR_EMPTY_DESTINATION_STATUS: 'A read error occurred while reading the destination status',
Expand Down Expand Up @@ -52,6 +53,7 @@ lang.it = {
SYNTAX_ERROR_LABEL: 'Errore di sintassi (linea %d):',
READ_ERROR: 'Errore nella lettura',
READ_ERROR_EXPECTED_COMMA: 'Era attesa la "," come separatore',
READ_ERROR_EXPECTED_END_OF_RULE: 'Era attesa la ")" a chiusura della regola',
READ_ERROR_EMPTY_SOURCE_STATUS: 'Errore nella lettura dello stato di partenza',
READ_ERROR_EMPTY_SOURCE_SYMBOL: 'Errore nella lettura del simbolo da leggere',
READ_ERROR_EMPTY_DESTINATION_STATUS: 'Errore nella lettura dello stato di destinazione',
Expand Down

0 comments on commit 9a32492

Please sign in to comment.