summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parsing/lexer.sh35
1 files changed, 28 insertions, 7 deletions
diff --git a/parsing/lexer.sh b/parsing/lexer.sh
index bf6ad7d..f92534a 100644
--- a/parsing/lexer.sh
+++ b/parsing/lexer.sh
@@ -456,13 +456,34 @@ accept()
{
local t="${1}"
- if [ "x${tok%%${US}*}" = "x${t}" ]; then
- dbg "accept $t"
- tokens="${tokens}${tok}${RS}"
- next
- return 0
- fi
- return 1
+ case "${t}" in
+ T_IF|T_THEN|T_ELSE|T_ELIF|T_FI|\
+ T_DO|T_DONE|T_CASE|T_ESAC|T_WHILE|T_UNTIL|\
+ T_FOR|T_LBRACE|T_RBRACE|T_BANG|T_IN)
+ # Reserved words are recognized as literal T_WORDs.
+ if ! [ "x${tok%%${US}*}" = T_WORD ]; then
+ return 1
+ fi
+ # T_WORD data unit must match reserved word exactly.
+ if ! [ "x${tok#T_WORD${US}}" = "x$(tokname "${t}")" ]
+ then
+ return 1
+ fi
+ # If the token matches the reserved word, replace it
+ # with the reserved word token.
+ tok="${t}"
+ ;;
+ *)
+ if ! [ "x${tok%%${US}*}" = "x${t}" ]; then
+ return 1
+ fi
+ ;;
+ esac
+
+ dbg "accept $t"
+ tokens="${tokens}${tok}${RS}"
+ next
+ return 0
}
expect()