summaryrefslogtreecommitdiffstats
path: root/eshtrans/main.esh
diff options
context:
space:
mode:
Diffstat (limited to 'eshtrans/main.esh')
-rw-r--r--eshtrans/main.esh101
1 files changed, 101 insertions, 0 deletions
diff --git a/eshtrans/main.esh b/eshtrans/main.esh
new file mode 100644
index 0000000..2a80504
--- /dev/null
+++ b/eshtrans/main.esh
@@ -0,0 +1,101 @@
+# Eggshell Compiler entry point
+#
+# Copyright (C) 2016 Patrick "P. J." McDermott
+#
+# This file is part of the Eggshell Compiler.
+#
+# The Eggshell Compiler is free software: you can redistribute it
+# and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# The Eggshell Compiler is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the Eggshell Compiler. If not, see
+# <http://www.gnu.org/licenses/>.
+
+try()
+{
+ local tokens=
+ local t=
+
+ printf 'Trying script:\n'
+ printf '\t%s\n' "${@}"
+ if tokens="$(printf '%s\n' "${@}" | esh_parse -)"; then
+ printf 'Tokens: %s\n' "${tokens}" | sed "
+ s/${SOH}/<SOH>/g; s/${STX}/<STX>/g; s/${ETX}/<ETX>/g;
+ s/${RS}/<RS>/g; s/${US}/<US>/g;
+ "
+ IFS="${RS}"
+ for t in ${tokens}; do
+ printf 'Token: %s\n' "$(tokname "${t}")"
+ case "${t%${US}*}" in T_NAME|T_FNAME|T_CMDNAME|T_WORD)
+ printf ' "%s"\n' "${t#*${US}}"
+ ;;
+ esac
+ done
+ printf 'Generated code:\n'
+ IFS="${LF}"
+ printf '\t%s\n' $(sh_codegen "${tokens}")
+ unset IFS
+ else
+ printf 'FAIL\n'
+ fi
+ printf '\n\n'
+}
+
+main()
+{
+#try '"foo bar" && $baz || qux' '${quux%uux quuux'
+#try '"foo bar" && $baz || qux' '${quux%uux } quuux'
+#try 'foo ${bar}'
+#try 'foo ${#bar}'
+#try 'foo ${bar#baz}'
+#try 'foo ${#bar#}'
+#try 'foo ${^}'
+#try 'foo `bar`'
+#try 'foo &&'
+#try '{ foo; }'
+#try '( foo )'
+#try 'for i in 1 2 3; do stuff; done'
+#try 'if foo; then bar; fi'
+#try 'if foo; then bar; elif baz; then qux; else quux; fi'
+#try 'if ; then ; fi'
+#try 'while foo; do bar; done'
+#try 'while ; do ; done'
+#try 'foo(){ bar; }'
+#try 'case foo in bar) baz;; (qux) quux;; quux);; esac'
+#try 'foo bar ( baz )'
+#try 'foo $(bar)'
+#try 'foo $(bar); baz'
+#try 'foo $(bar)' 'baz'
+#try 'foo $(bar) baz'
+#try 'foo$(bar$(baz))qux'
+#try 'foo $((1 + 1))'
+#try '$((1 + 1))'
+#try '$((1 + (1 + 1)))'
+#try '$((1 + $(foo) + 1))'
+#try '$((1'
+#try 'foo <<EOF' 'bar' 'EOF'
+#try 'foo <<-EOF' "${HT}bar" "${HT}EOF"
+#try 'foo <<EOF' '$(bar)' 'EOF'
+#try 'foo <<E"O"F' '$(bar)' 'EOF'
+#try 'foo <<"EOF"' '$(bar)' 'EOF'
+#try 'foo <<E\OF' '$(bar)' 'EOF'
+#try 'foo <<\EOF' '$(bar)' 'EOF'
+#try 'foo <<EOF1; bar <<EOF2' 'baz' 'EOF1' 'qux' 'EOF2'
+#try '\foo'
+#try '"foo bar" baz'
+#try '"foo'
+#try 'foo\" bar'
+#try 'foo\'
+#try "foo'"
+#try 'foo\' 'bar'
+try 'v=foo'
+#try 'if &&'
+#try 'if true; do'
+}