summaryrefslogtreecommitdiffstats
path: root/parsing
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-19 18:28:09 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-19 18:28:09 (EST)
commit6a6c376a64c14d820298671481ceaf5dcaaac4a6 (patch)
treee75500934b0fb08e518a6025a2038710c62e7937 /parsing
parent872012edc169d128e721b20ecaf5f3875776db37 (diff)
downloadeggshell-6a6c376a64c14d820298671481ceaf5dcaaac4a6.zip
eggshell-6a6c376a64c14d820298671481ceaf5dcaaac4a6.tar.gz
eggshell-6a6c376a64c14d820298671481ceaf5dcaaac4a6.tar.bz2
Recognize reserved words
Diffstat (limited to 'parsing')
-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()