aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/build/script
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-06-10 10:00:55 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-06-10 10:00:55 +0200
commitd5faeeab1d2115c02a330ac9c95d63ba225faabc (patch)
tree410f9d2b8c70c30c74d799d4fa7695c6f367cd41 /libbuild2/build/script
parent2ee88b6041557beb517b100c3f608ebfc5eb725d (diff)
Handle special variable names in base lexer via mode data
Diffstat (limited to 'libbuild2/build/script')
-rw-r--r--libbuild2/build/script/lexer.cxx39
-rw-r--r--libbuild2/build/script/lexer.hxx3
2 files changed, 9 insertions, 33 deletions
diff --git a/libbuild2/build/script/lexer.cxx b/libbuild2/build/script/lexer.cxx
index a58f794..d849ac9 100644
--- a/libbuild2/build/script/lexer.cxx
+++ b/libbuild2/build/script/lexer.cxx
@@ -80,7 +80,15 @@ namespace build2
}
default:
{
- base_lexer::mode (m, ps, esc);
+ // Recognize special variable names ($>, $<, $~).
+ //
+ if (m == lexer_mode::variable)
+ {
+ assert (data == 0);
+ data = reinterpret_cast<uintptr_t> ("><~");
+ }
+
+ base_lexer::mode (m, ps, esc, data);
return;
}
}
@@ -235,35 +243,6 @@ namespace build2
unget (c);
return word (st, sep);
}
-
- token lexer::
- word (state st, bool sep)
- {
- lexer_mode m (st.mode);
-
- // Customized implementation that handles special variable names ($>,
- // $<, $~).
- //
- // @@ TODO: $(<), $(>): feels like this will have to somehow be
- // handled at the top-level lexer level. Maybe provide a
- // string of one-char special variable names as state::data?
- //
- if (m != lexer_mode::variable)
- return base_lexer::word (st, sep);
-
- xchar c (peek ());
-
- if (c != '>' && c != '<' && c != '~')
- return base_lexer::word (st, sep);
-
- get ();
-
- state_.pop (); // Expire the variable mode.
- return token (string (1, c),
- sep,
- quote_type::unquoted, false,
- c.line, c.column);
- }
}
}
}
diff --git a/libbuild2/build/script/lexer.hxx b/libbuild2/build/script/lexer.hxx
index 7d919e5..646d3b9 100644
--- a/libbuild2/build/script/lexer.hxx
+++ b/libbuild2/build/script/lexer.hxx
@@ -69,9 +69,6 @@ namespace build2
private:
token
next_line ();
-
- virtual token
- word (state, bool) override;
};
}
}