[lld] [ELF] Add VersionNode lexer state for better version script parsing (PR #174530)
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 6 10:02:48 PST 2026
================
@@ -124,29 +124,37 @@ void ScriptLexer::lex() {
return;
}
- // Some operators form separate tokens.
- if (s.starts_with("<<=") || s.starts_with(">>=")) {
- curTok = s.substr(0, 3);
- s = s.substr(3);
- return;
- }
- if (s.size() > 1 && (s[1] == '=' && strchr("+-*/!&^|", s[0]))) {
- curTok = s.substr(0, 2);
- s = s.substr(2);
- return;
- }
+ // In Script and Expr states, recognize compound assignment operators.
+ auto doAssign = [&]() -> std::optional<StringRef> {
+ if (s.starts_with("<<=") || s.starts_with(">>=")) {
+ curTok = s.substr(0, 3);
+ s = s.substr(3);
+ return s;
+ }
+ if (s.size() > 1 && (s[1] == '=' && strchr("+-*/!&^|", s[0]))) {
+ curTok = s.substr(0, 2);
+ s = s.substr(2);
+ return s;
+ }
+ return {};
+ };
// Unquoted token. The non-expression token is more relaxed than tokens in
// C-like languages, so that you can write "file-name.cpp" as one bare
// token.
size_t pos;
+ constexpr StringRef scriptChars =
----------------
smithp35 wrote:
perhaps `scriptAndVersionChars` or perhaps have a separate
```
constexpr StringRef exprChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789_.$"
```
https://github.com/llvm/llvm-project/pull/174530
More information about the llvm-commits
mailing list