diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-05 15:16:49 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-08-05 15:16:49 +0200 |
commit | b7f1f4f6c23c45745c37e65c7d8bd088e0e1ae95 (patch) | |
tree | ff85c47162c263f11c5fe470dd35a90a6d767ddd | |
parent | 073838d6f0d7846dc537bf1d0308392a79320f06 (diff) |
Merge 'value' and 'pairs' lexer_mode, call it 'value'
We only really used pairs.
-rw-r--r-- | build2/lexer | 30 | ||||
-rw-r--r-- | build2/lexer.cxx | 15 | ||||
-rw-r--r-- | build2/parser | 2 | ||||
-rw-r--r-- | build2/parser.cxx | 48 |
4 files changed, 46 insertions, 49 deletions
diff --git a/build2/lexer b/build2/lexer index 42222e6..7e59ff1 100644 --- a/build2/lexer +++ b/build2/lexer @@ -17,22 +17,20 @@ namespace build2 { - // Context-dependent lexing mode. In the value mode we don't treat - // certain characters (e.g., +, =) as special so that we can use - // them in the variable values, e.g., 'foo = g++'. In contrast, in - // the variable mode, we restrict certain character (e.g., /) from - // appearing in the name. The pairs mode is just like value except - // that we split names separated by the pair character. The eval - // mode is used in the evaluation context. + // Context-dependent lexing mode. In the value mode we don't treat certain + // characters (e.g., '+', '=') as special so that we can use them in the + // variable values, e.g., 'foo = g++'. In contrast, in the variable mode, we + // restrict certain character (e.g., '/') from appearing in the name. The + // eval mode is used in the evaluation context. Quoted is an internal mode + // and should not be set explicitly. // - // The alternnative modes must be set manually. The value and pairs - // modes are 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 ')'. + // Note that the value mode splits names separated by the pair character. // - // Quoted is an internal mode and should not be set explicitly. + // 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 ')'. // - enum class lexer_mode {normal, variable, value, pairs, eval, quoted}; + enum class lexer_mode {normal, variable, value, eval, quoted}; class lexer: protected butl::char_scanner { @@ -57,11 +55,11 @@ namespace build2 const path& name () const {return fail.name_;} - // Note: sets mode for the next token. If mode is pairs, then the second - // argument specifies the separator character. + // Note: sets mode for the next token. For the value mode the second + // argument can be used to specify an alternative separator character. // void - mode (lexer_mode m, char pair_separator = '\0') + mode (lexer_mode m, char pair_separator = '@') { state_.push (state{m, pair_separator}); } diff --git a/build2/lexer.cxx b/build2/lexer.cxx index 84e972e..6b599fd 100644 --- a/build2/lexer.cxx +++ b/build2/lexer.cxx @@ -61,9 +61,9 @@ namespace build2 // case '\n': { - // Expire value/pairs mode at the end of the line. + // Expire value mode at the end of the line. // - if (m == lexer_mode::value || m == lexer_mode::pairs) + if (m == lexer_mode::value) state_.pop (); return token (type::newline, sep, ln, cn); @@ -79,13 +79,12 @@ namespace build2 // Handle pair separator. // - if (m == lexer_mode::pairs && c == ps) + if (m == lexer_mode::value && c == ps) return token (type::pair_separator, sep, ln, cn); - // The following characters are not treated as special in the - // value or pairs mode. + // The following characters are not treated as special in the value mode. // - if (m != lexer_mode::value && m != lexer_mode::pairs) + if (m != lexer_mode::value) { switch (c) { @@ -223,9 +222,9 @@ namespace build2 { bool done (false); - // Handle pair separator. + // Handle the pair separator. // - if (m == lexer_mode::pairs && c == ps) + if (m == lexer_mode::value && c == ps) break; // The following characters are only special in the normal and diff --git a/build2/parser b/build2/parser index af5c500..cc28695 100644 --- a/build2/parser +++ b/build2/parser @@ -264,7 +264,7 @@ namespace build2 } void - mode (lexer_mode m, char ps = '=') + mode (lexer_mode m, char ps = '@') { if (replay_ != replay::play) lexer_->mode (m, ps); diff --git a/build2/parser.cxx b/build2/parser.cxx index bb724aa..009316f 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -721,10 +721,10 @@ namespace build2 { tracer trace ("parser::source", &path_); - // The rest should be a list of buildfiles. Parse them as names - // to get variable expansion and directory prefixes. + // The rest should be a list of buildfiles. Parse them as names in the + // value mode to get variable expansion and directory prefixes. // - mode (lexer_mode::pairs, '@'); + mode (lexer_mode::value); next (t, tt); const location l (get_location (t, &path_)); names_type ns (tt != type::newline && tt != type::eos @@ -797,10 +797,10 @@ namespace build2 if (root_->src_path_ == nullptr) fail (t) << "inclusion during bootstrap"; - // The rest should be a list of buildfiles. Parse them as names - // to get variable expansion and directory prefixes. + // The rest should be a list of buildfiles. Parse them as names in the + // value mode to get variable expansion and directory prefixes. // - mode (lexer_mode::pairs, '@'); + mode (lexer_mode::value); next (t, tt); const location l (get_location (t, &path_)); names_type ns (tt != type::newline && tt != type::eos @@ -951,11 +951,11 @@ namespace build2 // switch to the value mode, get the first token, and then re-parse it // manually looking for =/=+/+=. // - mode (lexer_mode::pairs, '@'); + mode (lexer_mode::value); next (t, tt); // Get variable attributes, if any (note that here we will go into a - // nested pairs mode). + // nested value mode with a different pair character). // attributes& a (attributes_push (t, tt)); @@ -1128,10 +1128,10 @@ namespace build2 if (optional && boot_) fail (t) << "optional module in bootstrap"; - // The rest should be a list of module names. Parse them as names - // to get variable expansion, etc. + // The rest should be a list of module names. Parse them as names in the + // value mode to get variable expansion, etc. // - mode (lexer_mode::pairs, '@'); + mode (lexer_mode::value); next (t, tt); const location l (get_location (t, &path_)); names_type ns (tt != type::newline && tt != type::eos @@ -1429,7 +1429,7 @@ namespace build2 value parser:: variable_value (token& t, type& tt) { - mode (lexer_mode::pairs, '@'); + mode (lexer_mode::value); next (t, tt); // Parse value attributes if any. Note that it's ok not to have anything @@ -1779,10 +1779,10 @@ namespace build2 if (!a.has) return a; - // Using '@' for key-value pairs would be just too ugly. Seeing that we - // control what goes into keys/values, let's use a much nicer '='. + // Using '@' for attribute key-value pairs would be just too ugly. Seeing + // that we control what goes into keys/values, let's use a much nicer '='. // - mode (lexer_mode::pairs, '='); + mode (lexer_mode::value, '='); next (t, tt); if (tt != type::rsbrace && tt != type::newline && tt != type::eos) @@ -1821,10 +1821,10 @@ namespace build2 } } - // Manually expire the pairs mode if we haven't reached newline/eos (where + // Manually expire the value mode if we haven't reached newline/eos (where // it expires automatically). // - if (lexer_->mode () == lexer_mode::pairs) + if (lexer_->mode () == lexer_mode::value) lexer_->expire_mode (); if (tt != type::rsbrace) @@ -1938,7 +1938,7 @@ namespace build2 // @@ TODO: need to handle pairs on lhs. I think all that needs // to be done is skip pair's first elements. Maybe also check // that there are no pairs on the rhs. There is just no easy - // way to enable the pairs mode to test it, yet. + // way to enable the value mode to test it, yet. } } @@ -2495,7 +2495,7 @@ namespace build2 continue; } - // A pair separator (only in the pairs mode). + // A pair separator (only in the value mode). // if (tt == type::pair_separator) { @@ -2666,7 +2666,7 @@ namespace build2 // we will make every opening paren token "separated" (i.e., as if it // was proceeded by a space). This will disable concatenating eval. In // fact, we will even go a step further and only do this if we are in - // the original pairs mode. This will allow us to still use eval + // the original value mode. This will allow us to still use eval // contexts in buildspec, provided that we quote it: '"cle(an)"'. Note // also that function calls still work as usual: '$filter (clean test)'. // To disable a function call and make it instead a var that is expanded @@ -2675,7 +2675,7 @@ namespace build2 static void paren_processor (token& t, const lexer& l) { - if (t.type == type::lparen && l.mode () == lexer_mode::pairs) + if (t.type == type::lparen && l.mode () == lexer_mode::value) t.separated = true; } @@ -2692,10 +2692,10 @@ namespace build2 target_ = nullptr; scope_ = root_ = global_scope; - // Turn on pairs recognition with '@' as the pair separator (e.g., - // src_root/@out_root/exe{foo bar}). + // Turn on the value mode/pairs recognition with '@' as the pair separator + // (e.g., src_root/@out_root/exe{foo bar}). // - mode (lexer_mode::pairs, '@'); + mode (lexer_mode::value); token t (type::eos, false, 0, 0); type tt; |