summaryrefslogtreecommitdiffstats
path: root/eshtrans/frontend
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-27 18:29:41 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-27 18:29:41 (EST)
commit56eef91884524dfdfc4e2c227f323150996340dd (patch)
tree512c42ee13fec57a21991583a3d8d447ed93fcff /eshtrans/frontend
parent3fabff2df0215812a042ee70b4708b63be8a4fd0 (diff)
downloadeggshell-56eef91884524dfdfc4e2c227f323150996340dd.zip
eggshell-56eef91884524dfdfc4e2c227f323150996340dd.tar.gz
eggshell-56eef91884524dfdfc4e2c227f323150996340dd.tar.bz2
eshtrans/frontend: Fix ungetc code and run_sublexer()
Diffstat (limited to 'eshtrans/frontend')
-rw-r--r--eshtrans/frontend/lexer.esh63
1 files changed, 24 insertions, 39 deletions
diff --git a/eshtrans/frontend/lexer.esh b/eshtrans/frontend/lexer.esh
index 0b628a6..e0f703c 100644
--- a/eshtrans/frontend/lexer.esh
+++ b/eshtrans/frontend/lexer.esh
@@ -96,12 +96,21 @@ lgetc()
fi
}
+lungetc()
+{
+ lbufi=$((${lbufi} - 2))
+ eval "c=\${lbufv_${lbufi}}"
+ lbufi=$((${lbufi} + 1))
+}
+
lsetc()
{
if [ ${lbufi} -ge ${lbufc} ]; then
c=''
else
+ lbufi=$((${lbufi} - 1))
eval "c=\${lbufv_${lbufi}}"
+ lbufi=$((${lbufi} + 1))
fi
}
@@ -150,7 +159,8 @@ next()
continue
;;
esac
- next_word \\
+ lungetc
+ next_word
return
;;
'#')
@@ -213,7 +223,8 @@ next()
return
;;
*)
- next_word ''
+ lungetc
+ next_word
return
;;
esac
@@ -367,11 +378,9 @@ next_io()
next_word()
{
- local prev_c="${1}"
- shift 1
local res=
- if ! res="$(scan_word false "${prev_c}")"; then
+ if ! res="$(scan_word false)"; then
exit 1
fi
ln_off=${res%%${RS}*}
@@ -406,8 +415,7 @@ next_word()
scan_word()
{
local in_param="${1}"
- local prev_c="${2}"
- shift 2
+ shift 1
local lines=
local word=
local quoted=
@@ -418,15 +426,6 @@ scan_word()
word=''
quoted=false
- # Sort of a localized ungetc().
- case "${prev_c}" in
- '') ;;
- *)
- tmp_c="${c}"
- c="${prev_c}"
- ;;
- esac
-
while :; do
#dbg "parsing word char '$c' at lineno $lineno"
case "${c}" in
@@ -458,10 +457,7 @@ scan_word()
fi
;;
esac
- case "${prev_c}" in
- '') lgetc;;
- *) c="${tmp_c}"; prev_c='';;
- esac
+ lgetc
if ! res="$(scan_wordexp)"; then
exit 1
fi
@@ -488,10 +484,7 @@ scan_word()
\\)
#dbg 'first backslash in word'
word="${word}${c}"
- case "${prev_c}" in
- '') lgetc;;
- *) c="${tmp_c}"; prev_c='';;
- esac
+ lgetc
#dbg "next char: '$c'"
case "${c}" in '')
# Bash, ksh93, mksh, and zsh ignore a
@@ -510,17 +503,11 @@ scan_word()
\')
word="${word}${c}"
if ${quoted}; then
- case "${prev_c}" in
- '') lgetc;;
- *) c="${tmp_c}"; prev_c='';;
- esac
+ lgetc
continue
fi
while :; do
- case "${prev_c}" in
- '') lgetc;;
- *) c="${tmp_c}"; prev_c='';;
- esac
+ lgetc
word="${word}${c}"
case "${c}" in
'')
@@ -556,10 +543,7 @@ scan_word()
word="${word}${c}"
;;
esac
- case "${prev_c}" in
- '') lgetc;;
- *) c="${tmp_c}"; prev_c='';;
- esac
+ lgetc
done
if ${quoted}; then
@@ -592,7 +576,7 @@ scan_wordexp()
# Command substitution
if ! res="$(run_sublexer "sub${fname}" \
${lineno} "${start}" \
- "${c}")"; then
+ ${lbufi})"; then
exit 1
fi
lbufi="${res##*${RS}}"
@@ -859,7 +843,7 @@ run_sublexer()
local fn="${1}"
local ln="${2}"
local st="${3}"
- local ch="${4}"
+ local i="${4}"
shift 4
# Initialize global variables.
@@ -870,7 +854,8 @@ run_sublexer()
here_awaiting_end=false
here_awaiting_word=false
- c="${ch}"
+ lbufi="${i}"
+ lsetc
next
#dbg=true