summaryrefslogtreecommitdiffstats
path: root/parsing/lexer.sh
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-19 22:56:37 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-19 22:56:37 (EST)
commit48996f2bfc32321dbd6c22d8fcdd0bb385f611cc (patch)
treea3678945dab97ab9d076029b3603f2a38dddbf44 /parsing/lexer.sh
parent3b934b8e6c9b43b9fb9599bed3ff4e50af3bc77d (diff)
downloadeggshell-48996f2bfc32321dbd6c22d8fcdd0bb385f611cc.zip
eggshell-48996f2bfc32321dbd6c22d8fcdd0bb385f611cc.tar.gz
eggshell-48996f2bfc32321dbd6c22d8fcdd0bb385f611cc.tar.bz2
Improve reserved word recognition
And fix term() to allow do_group() to find T_DONE. Also, ERMAHGERD DEBERG.
Diffstat (limited to 'parsing/lexer.sh')
-rw-r--r--parsing/lexer.sh43
1 files changed, 32 insertions, 11 deletions
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