Skip to content

Commit

Permalink
- Some fixes to the parser. Will baseline tests after this.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15103 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 8, 2013
1 parent 860606c commit ded5128
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Parser/BaseModelica_Lexer.g
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ STRING : '"' STRING_GUTS '"'
" To change it in a package: add a file package.encoding at the top-level.\n"
" Note: The Modelica Language Specification only allows files encoded in UTF-8.",
strs, 2, $line, $pos+1, $line, $pos+len+1,
ModelicaParser_readonly, ModelicaParser_filename_C);
ModelicaParser_readonly, ModelicaParser_filename_C_testsuiteFriendly);
free(buf);
ModelicaParser_lexerError = ANTLR3_TRUE;
}
Expand All @@ -356,7 +356,7 @@ SESCAPE : esc='\\' ('\\' | '"' | '\'' | '?' | 'a' | 'b' | 'f' | 'n' | 'r' | 't'
int len = strlen((char*)$text->chars);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_warning, "Lexer treating \\ as \\\\, since \\\%s is not a valid Modelica escape sequence.",
&str, 1, $line, $pos+1, $line, $pos+len+1,
ModelicaParser_readonly, ModelicaParser_filename_C);
ModelicaParser_readonly, ModelicaParser_filename_C_testsuiteFriendly);
});

fragment
Expand Down Expand Up @@ -410,7 +410,7 @@ UNSIGNED_INTEGER :
$type = UNSIGNED_REAL;
c_add_source_message(2, ErrorType_syntax, ErrorLevel_warning, "Treating \%s as 0\%s. This is not standard Modelica and only done for compatibility with old code. Support for this feature may be removed in the future.",
strs, 2, $line, $pos+1, $line, $pos+len+1,
ModelicaParser_readonly, ModelicaParser_filename_C);
ModelicaParser_readonly, ModelicaParser_filename_C_testsuiteFriendly);
}
| /* Modelica 3.0 element-wise operators! */
(('+' { $type = PLUS_EW; })
Expand Down
16 changes: 8 additions & 8 deletions Parser/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ static void handleLexerError(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *
line = lexer->getLine(lexer);
offset = lexer->getCharPositionInLine(lexer)+1;
if (*chars[1])
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Lexer got '%s' but failed to recognize the rest: '%s'", (const char**) chars, 2, line, offset, line, offset, false, ModelicaParser_filename_C);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Lexer got '%s' but failed to recognize the rest: '%s'", (const char**) chars, 2, line, offset, line, offset, false, ModelicaParser_filename_C_testsuiteFriendly);
else
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Lexer failed to recognize '%s'", (const char**) chars, 1, line, offset, line, offset, false, ModelicaParser_filename_C);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Lexer failed to recognize '%s'", (const char**) chars, 1, line, offset, line, offset, false, ModelicaParser_filename_C_testsuiteFriendly);
ModelicaParser_lexerError = ANTLR3_TRUE;
free(chars[0]);
free(chars[1]);
Expand Down Expand Up @@ -229,22 +229,22 @@ static void handleParseError(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *
token_text[0] = lookupTokenName(token->type,tokenNames);
token_text[1] = token->type == ANTLR3_TOKEN_EOF ? "" : (const char*) str->chars;
token_text[2] = lookupTokenName(ex->expecting,tokenNames);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Expected token of type %s, got '%s' of type %s", token_text, 3, p_line, p_offset, n_line, n_offset, false, ModelicaParser_filename_C);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Expected token of type %s, got '%s' of type %s", token_text, 3, p_line, p_offset, n_line, n_offset, false, ModelicaParser_filename_C_testsuiteFriendly);
break;
}
case ANTLR3_MISSING_TOKEN_EXCEPTION:
token_text[0] = lookupTokenName(ex->expecting,tokenNames);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Missing token: %s", token_text, 1, p_line, p_offset, p_line, p_offset, false, ModelicaParser_filename_C);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Missing token: %s", token_text, 1, p_line, p_offset, p_line, p_offset, false, ModelicaParser_filename_C_testsuiteFriendly);
break;
case ANTLR3_NO_VIABLE_ALT_EXCEPTION:
token_text[0] = preToken->type == ANTLR3_TOKEN_EOF ? "<EOF>" : (const char*)preToken->getText(preToken)->chars;
if (preToken->type == ANTLR3_TOKEN_EOF) n_offset = p_offset;
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "No viable alternative near token: %s", token_text, 1, p_line, p_offset, n_line, n_offset, false, ModelicaParser_filename_C);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "No viable alternative near token: %s", token_text, 1, p_line, p_offset, n_line, n_offset, false, ModelicaParser_filename_C_testsuiteFriendly);
break;
case ModelicaParserException:
{
fileinfo* info = (fileinfo*) ex->custom;
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Parse error: %s", token_text+1, 1, info->line1, info->offset1, info->line2, info->offset2, false, ModelicaParser_filename_C);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Parse error: %s", token_text+1, 1, info->line1, info->offset1, info->line2, info->offset2, false, ModelicaParser_filename_C_testsuiteFriendly);
free(info);
ex->custom = 0;
break;
Expand All @@ -257,7 +257,7 @@ static void handleParseError(pANTLR3_BASE_RECOGNIZER recognizer, pANTLR3_UINT8 *
token_text[1] = preToken->type == ANTLR3_TOKEN_EOF ? "" : (const char*)preToken->getText(preToken)->chars;
token_text[0] = lookupTokenName(preToken->type,tokenNames);
if (preToken->type == ANTLR3_TOKEN_EOF) n_offset = p_offset;
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Parser error: %s near: %s (%s)", token_text, 3, p_line, p_offset, n_line, n_offset, false, ModelicaParser_filename_C);
c_add_source_message(2, ErrorType_syntax, ErrorLevel_error, "Parser error: %s near: %s (%s)", token_text, 3, p_line, p_offset, n_line, n_offset, false, ModelicaParser_filename_C_testsuiteFriendly);
break;
}

Expand Down Expand Up @@ -390,7 +390,7 @@ static void* parseFile(const char* fileName, const char* infoName, int flags, co
ModelicaParser_encoding = encoding;
ModelicaParser_filename_C = fileName;
ModelicaParser_filename_C_testsuiteFriendly = infoName;
ModelicaParser_flags = flags;
ModelicaParser_flags = flags;
isReadOnly = !SystemImpl__regularFileWritable(ModelicaParser_filename_C);
omc_first_comment = 0;

Expand Down

0 comments on commit ded5128

Please sign in to comment.