# 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
# .
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}//g; s/${STX}//g; s/${ETX}//g;
s/${RS}//g; s/${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 <bar'
#try '2>bar'
#try '2 foo'
dbg=true
try 'foo $(bar \' 'baz \' 'qux) &&' # Line number testing
# sh_codegen "$(esh_parse "${1}" <"${1}")"
}