aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-11-04 08:46:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 09:26:22 +0200
commit4b1f902b33d0826ccb2f6d5a1ceb8db7bdd2defe (patch)
tree9f0fcddb0b6cad34965a7ca330c3cd8b033c195d
parent08aba2ee7cf407c9c25233ebbf43d0310e0f1b5e (diff)
Change token type 'name' to more general 'word'
-rw-r--r--build2/context.cxx6
-rw-r--r--build2/file.cxx2
-rw-r--r--build2/lexer8
-rw-r--r--build2/lexer.cxx18
-rw-r--r--build2/parser.cxx42
-rw-r--r--build2/token14
-rw-r--r--build2/token.cxx2
7 files changed, 48 insertions, 44 deletions
diff --git a/build2/context.cxx b/build2/context.cxx
index 1527cc8..c783832 100644
--- a/build2/context.cxx
+++ b/build2/context.cxx
@@ -110,14 +110,14 @@ namespace build2
//
lexer l (is, path ("<cmdline>"), "\'\"\\$(");
- // The first token should be a name, either the variable name or the
+ // The first token should be a word, either the variable name or the
// scope qualification.
//
token t (l.next ());
token_type tt (l.next ().type);
dir_path dir;
- if (t.type == token_type::name && tt == token_type::colon)
+ if (t.type == token_type::word && tt == token_type::colon)
{
if (!path::traits::is_separator (t.value.back ()))
fail << "expected directory (with trailing slash) instead of "
@@ -136,7 +136,7 @@ namespace build2
// This should be the variable name followed by =, +=, or =+.
//
- if (t.type != token_type::name || t.value.empty () ||
+ if (t.type != token_type::word || t.value.empty () ||
(tt != token_type::assign &&
tt != token_type::prepend &&
tt != token_type::append))
diff --git a/build2/file.cxx b/build2/file.cxx
index 7e94e03..478722f 100644
--- a/build2/file.cxx
+++ b/build2/file.cxx
@@ -282,7 +282,7 @@ namespace build2
token t (lex.next ());
token_type tt;
- if (t.type != token_type::name || t.value != name ||
+ if (t.type != token_type::word || t.value != name ||
((tt = lex.next ().type) != token_type::assign &&
tt != token_type::prepend &&
tt != token_type::append))
diff --git a/build2/lexer b/build2/lexer
index c6a6f5b..c5c3857 100644
--- a/build2/lexer
+++ b/build2/lexer
@@ -24,12 +24,12 @@ namespace build2
// eval mode is used in the evaluation context. Quoted are internal modes
// and should not be set explicitly.
//
- // Note that the normal, value, and eval modes split names separated by the
+ // Note that the normal, value, and eval modes split words separated by the
// pair character (to disable pairs one can pass '\0' as a pair character).
//
// The alternnative modes must be set manually. The value mode is
// automatically reset after the end of the line. The variable mode is reset
- // after the name token. And the eval mode is reset after the closing ')'.
+ // after the word token. And the eval mode is reset after the closing ')'.
//
// Extendable/inheritable enum-like class.
@@ -115,7 +115,7 @@ namespace build2
next_quoted ();
virtual token
- name (bool separated);
+ word (bool separated);
// Return true if we have seen any spaces. Skipped empty lines
// don't count. In other words, we are only interested in spaces
@@ -168,7 +168,7 @@ namespace build2
char sep_pair;
bool sep_space; // Are whitespaces separators (see skip_spaces())?
- // Name separator characters. For two-character sequence put the first
+ // Word separator characters. For two-character sequence put the first
// one in sep_first and the second one in the corresponding position of
// sep_second. If it's a single-character sequence, then put space in
// sep_second. If there are multiple sequences that start with the same
diff --git a/build2/lexer.cxx b/build2/lexer.cxx
index 148b7c2..b188396 100644
--- a/build2/lexer.cxx
+++ b/build2/lexer.cxx
@@ -66,7 +66,7 @@ namespace build2
// Fall through.
case lexer_mode::variable:
{
- // These are handled in an ad hoc way in name().
+ // These are handled in an ad hoc way in word().
break;
}
default: assert (false); // Unhandled custom mode.
@@ -165,10 +165,10 @@ namespace build2
}
}
- // Otherwise it is a name.
+ // Otherwise it is a word.
//
unget (c);
- return name (sep);
+ return word (sep);
}
token lexer::
@@ -239,10 +239,10 @@ namespace build2
}
}
- // Otherwise it is a name.
+ // Otherwise it is a word.
//
unget (c);
- return name (sep);
+ return word (sep);
}
token lexer::
@@ -261,14 +261,14 @@ namespace build2
case '(': return token (type::lparen, false, ln, cn, token_printer);
}
- // Otherwise it is a name.
+ // Otherwise it is a word.
//
unget (c);
- return name (false);
+ return word (false);
}
token lexer::
- name (bool sep)
+ word (bool sep)
{
lexer_mode m (state_.top ().mode);
@@ -439,7 +439,7 @@ namespace build2
if (eos (c) && m == lexer_mode::double_quoted)
fail (c) << "unterminated double-quoted sequence";
- // Expire variable mode at the end of the name.
+ // Expire variable mode at the end of the word.
//
if (m == lexer_mode::variable)
state_.pop ();
diff --git a/build2/parser.cxx b/build2/parser.cxx
index 30c5ff3..24558ea 100644
--- a/build2/parser.cxx
+++ b/build2/parser.cxx
@@ -244,7 +244,7 @@ namespace build2
// We always start with one or more names.
//
- if (tt != type::name &&
+ if (tt != type::word &&
tt != type::lcbrace && // Untyped name group: '{foo ...'
tt != type::dollar && // Variable expansion: '$foo ...'
tt != type::lparen && // Eval context: '(foo) ...'
@@ -267,7 +267,7 @@ namespace build2
// See if this is one of the directives.
//
- if (tt == type::name && keyword (t))
+ if (tt == type::word && keyword (t))
{
const string& n (t.value);
void (parser::*f) (token&, token_type&) = nullptr;
@@ -436,7 +436,7 @@ namespace build2
attributes& a (attributes_push (t, tt));
- if (tt == type::name ||
+ if (tt == type::word ||
tt == type::lcbrace ||
tt == type::dollar ||
tt == type::lparen ||
@@ -1000,7 +1000,7 @@ namespace build2
//
attributes& a (attributes_push (t, tt));
- if (tt == type::name)
+ if (tt == type::word)
{
// Split the token into the variable name and value at position (p) of
// '=', taking into account leading/trailing '+'. The variable name is
@@ -1047,7 +1047,7 @@ namespace build2
//
// This could still be the 'foo =...' case.
//
- else if (peek () == type::name)
+ else if (peek () == type::word)
{
const string& v (peeked ().value);
size_t n (v.size ());
@@ -1243,7 +1243,7 @@ namespace build2
//
// See tests/define.
//
- if (next (t, tt) != type::name)
+ if (next (t, tt) != type::word)
fail (t) << "expected name instead of " << t << " in target type "
<< "definition";
@@ -1256,7 +1256,7 @@ namespace build2
next (t, tt);
- if (tt == type::name)
+ if (tt == type::word)
{
// Target.
//
@@ -1389,7 +1389,7 @@ namespace build2
// See if we have another el* keyword.
//
- if (k != "else" && tt == type::name && keyword (t))
+ if (k != "else" && tt == type::word && keyword (t))
{
const string& n (t.value);
@@ -2035,14 +2035,14 @@ namespace build2
{
// If the accumulating buffer is not empty, then we have two options:
// continue accumulating or inject. We inject if the next token is
- // not a name, var expansion, or eval context or if it is separated.
+ // not a word, var expansion, or eval context or if it is separated.
//
if (!concat.empty () &&
- ((tt != type::name &&
+ ((tt != type::word &&
tt != type::dollar &&
tt != type::lparen) || peeked ().separated))
{
- tt = type::name;
+ tt = type::word;
t = token (move (concat), true, false, t.line, t.column);
concat.clear ();
}
@@ -2058,7 +2058,7 @@ namespace build2
// Name.
//
- if (tt == type::name)
+ if (tt == type::word)
{
string name (t.value); //@@ move?
tt = peek ();
@@ -2222,7 +2222,7 @@ namespace build2
auto set_null = [first, &tt] ()
{
return first &&
- tt != type::name &&
+ tt != type::word &&
tt != type::dollar &&
tt != type::lparen &&
tt != type::lcbrace &&
@@ -2237,7 +2237,7 @@ namespace build2
{
// Switch to the variable name mode. We want to use this mode for
// $foo but not for $(foo). Since we don't know whether the next
- // token is a paren or a name, we turn it on and switch to the eval
+ // token is a paren or a word, we turn it on and switch to the eval
// mode if what we get next is a paren.
//
mode (lexer_mode::variable);
@@ -2247,7 +2247,7 @@ namespace build2
name qual;
string name;
- if (tt == type::name)
+ if (tt == type::word)
name = t.value;
else if (tt == type::lparen)
{
@@ -2392,11 +2392,11 @@ namespace build2
// Should we accumulate? If the buffer is not empty, then
// we continue accumulating (the case where we are separated
// should have been handled by the injection code above). If
- // the next token is a name or var expansion and it is not
+ // the next token is a word or var expansion and it is not
// separated, then we need to start accumulating.
//
if (!concat.empty () || // Continue.
- ((tt == type::name || // Start.
+ ((tt == type::word || // Start.
tt == type::dollar ||
tt == type::lparen) && !peeked ().separated))
{
@@ -2639,7 +2639,7 @@ namespace build2
keyword (token& t)
{
assert (replay_ == replay::stop); // Can't be used in a replay.
- assert (t.type == type::name);
+ assert (t.type == type::word);
// The goal here is to allow using keywords as variable names and
// target types without imposing ugly restrictions/decorators on
@@ -2749,10 +2749,10 @@ namespace build2
while (tt != tt_end)
{
- // We always start with one or more names. Eval context
- // (lparen) only allowed if quoted.
+ // We always start with one or more names. Eval context (lparen) only
+ // allowed if quoted.
//
- if (tt != type::name &&
+ if (tt != type::word &&
tt != type::lcbrace && // Untyped name group: '{foo ...'
tt != type::dollar && // Variable expansion: '$foo ...'
!(tt == type::lparen && mode () == lexer_mode::double_quoted) &&
diff --git a/build2/token b/build2/token
index 18d377d..d172e0d 100644
--- a/build2/token
+++ b/build2/token
@@ -14,6 +14,10 @@ namespace build2
{
// Extendable/inheritable enum-like class.
//
+ // A line consists of a sequence of words separated by separators and
+ // terminated with the newline. If whitespace is a separator, then it is
+ // ignored.
+ //
struct token_type
{
enum
@@ -21,8 +25,8 @@ namespace build2
// NOTE: remember to update token_printer()!
eos,
- name,
newline,
+ word,
pair_separator,
colon,
lcbrace, // {
@@ -64,9 +68,9 @@ namespace build2
token_type type;
bool separated; // Whitespace-separated from the previous token.
- bool quoted; // Name (or some part of it) was quoted.
+ bool quoted; // Word (or some part of it) was quoted.
- string value; // Only valid for name.
+ string value; // Only valid for word.
uint64_t line;
uint64_t column;
@@ -82,8 +86,8 @@ namespace build2
line (l), column (c),
printer (p) {}
- token (string n, bool s, bool q, uint64_t l, uint64_t c)
- : type (token_type::name), separated (s), quoted (q), value (move (n)),
+ token (string v, bool s, bool q, uint64_t l, uint64_t c)
+ : type (token_type::word), separated (s), quoted (q), value (move (v)),
line (l), column (c),
printer (&token_printer) {}
};
diff --git a/build2/token.cxx b/build2/token.cxx
index bf2249f..df0d8ce 100644
--- a/build2/token.cxx
+++ b/build2/token.cxx
@@ -20,7 +20,7 @@ namespace build2
case token_type::eos: os << "<end of file>"; break;
case token_type::newline: os << "<newline>"; break;
case token_type::pair_separator: os << "<pair separator>"; break;
- case token_type::name: os << '\'' << t.value << '\''; break;
+ case token_type::word: os << '\'' << t.value << '\''; break;
case token_type::colon: os << q << ':' << q; break;
case token_type::lcbrace: os << q << '{' << q; break;