Skip to content

Commit b68d4f2

Browse files
committed
Adding support for quoted identifiers
In BaseModelica, every identifier is quoted..
1 parent 13ce776 commit b68d4f2

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/s0_lexer/tokens.rs

+9
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ pub enum Token {
177177
#[regex("[_a-zA-Z][_0-9a-zA-Z]*", |lex| lex.slice().to_string())]
178178
Identifier(String),
179179

180+
#[regex("'([_0-9a-zA-Z!#$%&\\(\\)*+,-\\./:;<>=\\?@\\[\\]\\^\\{\\}|~ \"]|\\\\'|\\\\\"|\\\\\\?|\\\\\\\\|\\\\a|\\\\b|\\\\f|\\\\n|\\\\r|\\\\t|\\\\v)*'", |lex| {
181+
// Perform downquoting per https://github.com/modelica/ModelicaSpecification/blob/MCP/0031/RationaleMCP/0031/name-mapping.md
182+
// * Strip off the outer quotes
183+
// * Unescape escaped sequences
184+
let quoted = &lex.slice()[1..lex.slice().len()-1];
185+
quoted.to_string().replace("\\'", "'").replace("\\\"", "\"").replace("\\?", "?").replace("\\\\", "\\").replace("\\a", "\x07").replace("\\b", "\x08").replace("\\f", "\x0c").replace("\\n", "\n").replace("\\r", "\r").replace("\\t", "\t").replace("\\v", "\x0b")
186+
})]
187+
QuotedIdentifier(String),
188+
180189
#[regex("\"[\\- _0-9a-zA-Z]*\"", quoted_string_callback)]
181190
String(String),
182191

src/s1_parser/modelica.lalrpop

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ extern {
9999

100100
// other lexical tokens
101101
"IDENT" => Token::Identifier(<String>),
102+
"Q-IDENT" => Token::QuotedIdentifier(<String>),
102103
"STRING" => Token::String(<String>),
103104
"UNSIGNED-INTEGER" => Token::UnsignedInteger(<String>),
104105
"UNSIGNED-REAL" => Token::UnsignedReal(<String>),
@@ -294,6 +295,7 @@ pub ClassSpecifier: fragment::ClassSpecifier = {
294295

295296
pub IDENT: String = {
296297
<ident: "IDENT"> => ident,
298+
<qident: "Q-IDENT"> => qident
297299
}
298300

299301
//✅ long-class-specifier :

0 commit comments

Comments
 (0)