Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rust: Attempt to lex constant idents (#741)
  • Loading branch information
CosmicHorrorDev committed Jan 29, 2023
1 parent 87869f8 commit 55b0e59
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lexers/embedded/rust.xml
Expand Up @@ -294,6 +294,9 @@
<rule pattern="[+\-*/%&amp;|&lt;&gt;^!~@=:?]">
<token type="Operator"/>
</rule>
<rule pattern="\b(r#)?_?([A-Z][A-Z0-9_]*){2,}\b">
<token type="NameConstant"/>
</rule>
<rule pattern="(r#)?[a-zA-Z_]\w*">
<token type="Name"/>
</rule>
Expand Down
10 changes: 10 additions & 0 deletions lexers/testdata/rust/const_idents.actual
@@ -0,0 +1,10 @@
const IM_A_CONST: () = ();

fn main() {
dbg!(IM_A_CONST);
}

// None of this should be considered const
fn foo<T0, T1, U>(_: (T0, T1, U)) {
let _: std::collections::BTreeSet<()> = todo!();
}
74 changes: 74 additions & 0 deletions lexers/testdata/rust/const_idents.expected
@@ -0,0 +1,74 @@
[
{"type":"Keyword","value":"const"},
{"type":"TextWhitespace","value":" "},
{"type":"NameConstant","value":"IM_A_CONST"},
{"type":"Text","value":": "},
{"type":"Punctuation","value":"()"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"();"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"Keyword","value":"fn"},
{"type":"Text","value":" "},
{"type":"NameFunction","value":"main"},
{"type":"Punctuation","value":"()"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"TextWhitespace","value":"\n "},
{"type":"NameFunctionMagic","value":"dbg!"},
{"type":"Punctuation","value":"("},
{"type":"NameConstant","value":"IM_A_CONST"},
{"type":"Punctuation","value":");"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"TextWhitespace","value":"\n\n"},
{"type":"CommentSingle","value":"// None of this should be considered const\n"},
{"type":"Keyword","value":"fn"},
{"type":"Text","value":" "},
{"type":"NameFunction","value":"foo"},
{"type":"Operator","value":"\u003c"},
{"type":"Name","value":"T0"},
{"type":"Punctuation","value":","},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"T1"},
{"type":"Punctuation","value":","},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"U"},
{"type":"Operator","value":"\u003e"},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"_"},
{"type":"Text","value":": "},
{"type":"Punctuation","value":"("},
{"type":"Name","value":"T0"},
{"type":"Punctuation","value":","},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"T1"},
{"type":"Punctuation","value":","},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"U"},
{"type":"Punctuation","value":"))"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"TextWhitespace","value":"\n "},
{"type":"KeywordDeclaration","value":"let"},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"_"},
{"type":"Text","value":": "},
{"type":"NameClass","value":"std"},
{"type":"Text","value":"::"},
{"type":"Name","value":"collections"},
{"type":"Text","value":"::"},
{"type":"Name","value":"BTreeSet"},
{"type":"Operator","value":"\u003c"},
{"type":"Punctuation","value":"()"},
{"type":"Operator","value":"\u003e"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"NameFunctionMagic","value":"todo!"},
{"type":"Punctuation","value":"();"},
{"type":"TextWhitespace","value":"\n"},
{"type":"Punctuation","value":"}"},
{"type":"TextWhitespace","value":"\n"}
]

0 comments on commit 55b0e59

Please sign in to comment.