fix parenthesis processing. left-paren is only a command when it's argv0. Otherwise it's a normal character. (but must be balanced with right-paren to know when right-paren is a separator. ).
This commit is contained in:
parent
84b24e6379
commit
b4db751cbe
1
phase2.h
1
phase2.h
|
@ -82,6 +82,7 @@ private:
|
|||
|
||||
std::string scratch;
|
||||
int type = 0;
|
||||
int pcount = 0;
|
||||
|
||||
pipe_function pipe_to;
|
||||
|
||||
|
|
22
phase2.rl
22
phase2.rl
|
@ -72,20 +72,33 @@
|
|||
|
||||
# ( evaluate (1+2) ) is lparen, eval, rparen.
|
||||
# need to balance parens here and terminate a special token when it goes negative.
|
||||
|
||||
#
|
||||
# counterpoint: '(
|
||||
# echo (hello) == echo "(hello)"
|
||||
# echo ; (echo) == echo ; LPAREN echo RPAREN
|
||||
# ( echo ( ) ==> error (needs second closing rparen )
|
||||
# ( echo ())) --> error (MPW Shell - Extra ) command.
|
||||
|
||||
'(' => {
|
||||
if (special()) {
|
||||
|
||||
// if type == 0, this is the start and LPAREN is a token.
|
||||
// otherwise, LPAREN is a normal character (but is balanced)
|
||||
classify();
|
||||
if (type) {
|
||||
pcount++;
|
||||
scratch.push_back(fc);
|
||||
} else {
|
||||
// start of command.
|
||||
flush();
|
||||
parse(LPAREN, std::string(ts, te));
|
||||
}
|
||||
};
|
||||
|
||||
')' => {
|
||||
if (special() && pcount-- > 0) scratch.push_back(fc);
|
||||
if (pcount) {
|
||||
scratch.push_back(fc);
|
||||
--pcount;
|
||||
}
|
||||
else {
|
||||
flush();
|
||||
scratch.push_back(fc);
|
||||
|
@ -181,6 +194,7 @@ void phase2::flush() {
|
|||
}
|
||||
|
||||
type = 0;
|
||||
pcount = 0;
|
||||
scratch.clear();
|
||||
}
|
||||
|
||||
|
@ -223,7 +237,7 @@ void phase2::process(const std::string &line) {
|
|||
|
||||
if (line.empty()) { finish(); return; }
|
||||
|
||||
int pcount = 0; // special form parens cannot cross lines.
|
||||
//int pcount = 0; // special form parens cannot cross lines.
|
||||
|
||||
int cs;
|
||||
int act;
|
||||
|
|
Loading…
Reference in New Issue