summaryrefslogtreecommitdiffstats
path: root/eshtrans
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-21 14:43:40 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-21 14:43:40 (EST)
commit89ee6884b4d825d1d47b62380bdde93dd1842fa5 (patch)
treeef7da058f859fc54e7a83d3d1a11f4d024f0bd3e /eshtrans
parent89268e7fae95bd6e215ca03f2b5276691ef31166 (diff)
downloadeggshell-89ee6884b4d825d1d47b62380bdde93dd1842fa5.zip
eggshell-89ee6884b4d825d1d47b62380bdde93dd1842fa5.tar.gz
eggshell-89ee6884b4d825d1d47b62380bdde93dd1842fa5.tar.bz2
eshtrans/frontend: Handle T_IO_NUMBERs
Also fix a couple bugs in accept().
Diffstat (limited to 'eshtrans')
-rw-r--r--eshtrans/backend/codegen.esh13
-rw-r--r--eshtrans/frontend/lexer.esh18
-rw-r--r--eshtrans/frontend/parser.esh1
-rw-r--r--eshtrans/main.esh5
4 files changed, 34 insertions, 3 deletions
diff --git a/eshtrans/backend/codegen.esh b/eshtrans/backend/codegen.esh
index 1b2d168..8d77ce9 100644
--- a/eshtrans/backend/codegen.esh
+++ b/eshtrans/backend/codegen.esh
@@ -30,9 +30,19 @@ codegen_sub()
{
local array="${1}"
shift 1
+ local ionum=
+ ionum=false
IFS="${RS}"
for t in ${array}; do
+ if ${ionum}; then
+ case "${t%${US}*}" in
+ T_WORD|T_CMDNAME|T_FNAME)
+ printf ' '
+ ;;
+ esac
+ ionum=false
+ fi
toktext "${t}"
case "${t%${US}*}" in
T_NEWLINE|T_LPAREN)
@@ -41,6 +51,9 @@ codegen_sub()
# definitions (on zsh at least, while other
# shells accept the space).
;;
+ T_IO_NUMBER)
+ ionum=true
+ ;;
*)
printf ' '
;;
diff --git a/eshtrans/frontend/lexer.esh b/eshtrans/frontend/lexer.esh
index ec80ac3..069f36b 100644
--- a/eshtrans/frontend/lexer.esh
+++ b/eshtrans/frontend/lexer.esh
@@ -938,7 +938,7 @@ accept()
return 1
fi
# Validate name.
- case "${tok%%${US}*}" in
+ case "${tok#*${US}}" in
[A-Za-z_][0-9A-Za-z_]*)
;;
*)
@@ -953,7 +953,7 @@ accept()
return 1
fi
# Validate name.
- case "${tok%%${US}*}" in
+ case "${tok#*${US}}" in
[A-Za-z_][0-9A-Za-z_]*)
;;
*)
@@ -989,6 +989,20 @@ accept()
return 1
fi
done
+ tok="T_CMDNAME${US}${tok#T_WORD${US}}"
+ ;;
+ T_IO_NUMBER)
+ # I/O numbers are recognized as literal T_WORDs.
+ if ! [ "x${tok%%${US}*}" = 'xT_WORD' ]; then
+ return 1
+ fi
+ # Validate number.
+ case "${tok#*${US}}" in
+ *[!0-9]*)
+ return 1
+ ;;
+ esac
+ tok="T_IO_NUMBER${US}${tok#T_WORD${US}}"
;;
*)
if ! [ "x${tok%%${US}*}" = "x${t}" ]; then
diff --git a/eshtrans/frontend/parser.esh b/eshtrans/frontend/parser.esh
index 4757d76..449c5ba 100644
--- a/eshtrans/frontend/parser.esh
+++ b/eshtrans/frontend/parser.esh
@@ -494,6 +494,7 @@ redirect_list()
io_redirect()
{
ptrace_begn io_redirect
+ accept T_IO_NUMBER
if io_file || io_here; then
ptrace_pass io_redirect
return 0
diff --git a/eshtrans/main.esh b/eshtrans/main.esh
index 81d002b..c27ad2f 100644
--- a/eshtrans/main.esh
+++ b/eshtrans/main.esh
@@ -112,5 +112,8 @@ main()
#try 'foo <<EOF' '$(bar baz)' 'EOF'
#try '$foo'
#try '${foo%bar baz}'
-try '$(($(foo bar) + 1))'
+#try '$(($(foo bar) + 1))'
+try 'foo 2>bar'
+try '2>bar'
+try '2 foo'
}