From 48996f2bfc32321dbd6c22d8fcdd0bb385f611cc Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Fri, 19 Feb 2016 22:56:37 -0500 Subject: Improve reserved word recognition And fix term() to allow do_group() to find T_DONE. Also, ERMAHGERD DEBERG. --- (limited to 'parsing/lexer.sh') diff --git a/parsing/lexer.sh b/parsing/lexer.sh index c939d1c..01bc721 100644 --- a/parsing/lexer.sh +++ b/parsing/lexer.sh @@ -82,6 +82,7 @@ next() return ;; esac + dbg T_SEMI tok=T_SEMI return ;; @@ -457,23 +458,28 @@ accept() local t="${1}" local rw= + dbg "looking for $t, current tok ${tok%%${US}*}" 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) dbg "looking for reserved word $t, have '$tok'" - # Reserved words are recognized as literal T_WORDs. - if ! [ "x${tok%%${US}*}" = 'xT_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 + if ! [ "x${tok%%${US}*}" = "x${t}" ]; then + # Reserved words are recognized as literal + # T_WORDs. + if ! [ "x${tok%%${US}*}" = 'xT_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}" fi - # If the token matches the reserved word, replace it - # with the reserved word token. - tok="${t}" ;; T_NAME) # Names are recognized as literal T_WORDs. @@ -516,6 +522,21 @@ accept() done tok="T_FNAME${US}${tok#T_WORD${US}}" ;; + T_WORD) + if ! [ "x${tok%%${US}*}" = "x${t}" ]; then + return 1 + fi + # Verify that the word doesn't match any reserved words. + for rw 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_IN; do + if [ "x${tok#T_WORD${US}}" = \ + "x$(tokname "${rw}")" ]; then + tok="${rw}" + return 1 + fi + done + ;; *) if ! [ "x${tok%%${US}*}" = "x${t}" ]; then return 1 -- cgit v0.9.1