Skip to content

Commit

Permalink
Do not output invalid UTF-8 for some lexer errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed May 7, 2020
1 parent 19c4128 commit 37ce5aa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion OMCompiler/Parser/BaseModelica_Lexer.g
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,19 @@ SESCAPE : esc='\\' ('\\' | '"' | '\'' | '?' | 'a' | 'b' | 'f' | 'n' | 'r' | 't'
char chars[2] = {LA(1),'\0'};
const char *str = chars;
int len = strlen((char*)$text->chars);
c_add_source_message(NULL,2, ErrorType_syntax, ErrorLevel_warning, "Lexer treating \\ as \\\\, since \\\%s is not a valid Modelica escape sequence.",
if ((chars[0] & 0xE0) == 0xD0) {

This comment has been minimized.

Copy link
@hkiel

hkiel Mar 9, 2021

Member

@sjoelund This bitwise arithmetic always evaluates to false. Can you fix that please?

This comment has been minimized.

Copy link
@hkiel

hkiel Mar 10, 2021

Member

I commited a fix in #7284 that correctly checks for utf8-multibyte sequences

c_add_source_message(NULL,2, ErrorType_syntax, ErrorLevel_warning, "Lexer treating \\ as \\\\, since the next byte is the start of a UTF-8 character and thus not a valid Modelica escape sequence.",
&str, 0, $line, $pos+1, $line, $pos+len+1,
ModelicaParser_readonly, ModelicaParser_filename_C_testsuiteFriendly);
} else if ((chars[0] & 0x80)) {
c_add_source_message(NULL,2, ErrorType_syntax, ErrorLevel_warning, "Lexer treating \\ as \\\\, since the next byte is an invalid UTF-8 character and thus not a valid Modelica escape sequence.",
&str, 0, $line, $pos+1, $line, $pos+len+1,
ModelicaParser_readonly, ModelicaParser_filename_C_testsuiteFriendly);
} else {
c_add_source_message(NULL,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_testsuiteFriendly);
}
});

fragment
Expand Down

0 comments on commit 37ce5aa

Please sign in to comment.