Skip to content

Commit

Permalink
- Transform strings that contain \ not followed by a proper escape ch…
Browse files Browse the repository at this point in the history
…ar with \\

  - We print a warning whenever we do this. It is not in the specification; only for compatibility with Dymola.
  - Fixes bug #1143, add testcase testsuite/parser/DocumentationBackslash.mo


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6098 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Sep 13, 2010
1 parent 8222968 commit 8d99695
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
14 changes: 9 additions & 5 deletions Compiler/runtime/errorext.h
Expand Up @@ -32,10 +32,7 @@
#define __ERROREXT_H

#ifdef __cplusplus
#include <string>
#include <list>

extern "C" {
extern "C" {
#endif

void c_add_message(int errorID,
Expand All @@ -60,8 +57,15 @@ void setCheckpoint(const char* id);
void delCheckpoint(const char* id);
void rollBack(const char* id);
void* rollBackAndPrint(const char* id); // Returns the error string that we rolled back

#ifdef __cplusplus
}
}
#endif

#ifdef ERROREXT_CPLUSPLUS /* Not needed and messes up ANTLR3 parser */

#include <string>
#include <list>

void add_message(int errorID,
const char* type,
Expand Down
15 changes: 14 additions & 1 deletion Parser/BaseModelica_Lexer.g
Expand Up @@ -144,6 +144,11 @@ IDENT;
}
@includes {
#include "ModelicaParserCommon.h"
#include "runtime/errorext.h"
}
T_ALGORITHM : 'algorithm';
T_AND : 'and';
T_ANNOTATION : 'annotation';
Expand Down Expand Up @@ -257,7 +262,15 @@ fragment
SCHAR : NL | '\t' | ~('\n' | '\t' | '\r' | '\\' | '"');
fragment
SESCAPE : '\\' ('\\' | '"' | '\'' | '?' | 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v');
SESCAPE : esc='\\' ('\\' | '"' | '\'' | '?' | 'a' | 'b' | 'f' | 'n' | 'r' | 't' | 'v' |
{
char chars[2] = {LA(1),'\0'};
const char *str = chars;
int len = strlen((char*)$text->chars);
c_add_source_message(2, "SYNTAX", "Warning", "Lexer treating \\ as \\\\, since \\\%s is not a valid Modelica escape sequence.",
&str, 1, $line, len, $line, len+1,
ModelicaParser_readonly, ModelicaParser_filename_C);
});

IDENT : QIDENT | IDENT2;

Expand Down
1 change: 1 addition & 0 deletions Parser/Modelica.g
Expand Up @@ -41,6 +41,7 @@ import MetaModelica_Lexer; /* Makes all tokens defined */
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
Expand Down

0 comments on commit 8d99695

Please sign in to comment.