diff --git a/mpw/environ.rl b/mpw/environ.rl index f2501f9..796df78 100644 --- a/mpw/environ.rl +++ b/mpw/environ.rl @@ -4,22 +4,18 @@ machine lexer; - ws = [ \t\r\n]; + ws = [ \t]; word = [A-Za-z0-9_]; action emplace { //printf("emplacing %s\n", name.c_str()); // trim any whitespace. - while (value.length() && isspace(value.back())) - value.pop_back(); + //while (value.length() && isspace(value.back())) + // value.pop_back(); env[std::move(name)] = std::move(value); } - action error { - fprintf(stderr, "Bad environment: %.*s\n", (int)length, line); - } - value := |* '$' word+ => { @@ -40,10 +36,13 @@ value.push_back('$'); }; - any $eof(emplace) => { + '\n' => emplace; + + any - '\n' => { value.push_back(fc); } ; + *|; @@ -51,17 +50,22 @@ comment := any* ${ fbreak; }; - assignment = - word+ ${ name.push_back(fc); } - ws* %eof(error) - '=' - ws* - (any - ws)? ${ fhold; fgoto value; } - %eof(emplace) + assignment := + word+ ${ name.push_back(fc); } + ws* + '=' + ws* + # ws does not include '\n', so that will be handled + # as a value. + (any - ws)? ${ fhold; fgoto value; } ; - main := ws* ( '#' ${ fgoto comment; } | assignment); - + main := |* + ws; # leading space + '\n'; # blank line. + '#' => { fgoto comment; }; + word => { fhold; fgoto assignment; }; + *|; }%% #include @@ -82,6 +86,14 @@ void LoadEnvironment(std::string &envfile, std::unordered_map