summaryrefslogtreecommitdiffstats
path: root/parsing/parse.sh
diff options
context:
space:
mode:
Diffstat (limited to 'parsing/parse.sh')
-rw-r--r--parsing/parse.sh63
1 files changed, 45 insertions, 18 deletions
diff --git a/parsing/parse.sh b/parsing/parse.sh
index 2ac4215..d85a42e 100644
--- a/parsing/parse.sh
+++ b/parsing/parse.sh
@@ -3,6 +3,15 @@ LF="$(printf '\n.')"; LF="${LF%.}"
RS="$(printf '\036.')"; RS="${RS%.}"
US="$(printf '\037.')"; US="${US%.}"
+dbg()
+{
+ dbg=true
+ dbg=false
+ if ${dbg}; then
+ printf 'DEBUG: %s\n' "${@}" >&2
+ fi
+}
+
. ./tokens.sh
. ./lexer.sh
@@ -109,25 +118,43 @@ parse()
shift 1
init_lexer "${fn}"
+
+ # If this returns (does not exit), there are no errors.
while complete_command; do :; done
- if :; then # TODO: Test for EOF or errors
- get_tokens
- return 0
+
+ get_tokens
+
+ return 0
+}
+
+try()
+{
+ local tokens=
+ local t=
+
+ printf 'Trying script:\n'
+ printf '\t%s\n' "${@}"
+ if tokens="$(printf '%s\n' "${@}" | parse -)"; then
+ IFS="${RS}"
+ for t in ${tokens}; do
+ printf 'Token: %s\n' "$(tokname "${t}")"
+ case "${t%${US}*}" in T_WORD)
+ printf ' "%s"\n' "${t#T_WORD${US}}"
+ ;;
+ esac
+ done
+ unset IFS
+ else
+ printf 'FAIL\n'
fi
- return 1
+ printf '\n\n'
}
-if tokens="$(printf '%s\n' '"foo bar" && $baz || qux' '${quux%uux } quuux' | \
- parse -)"; then
- IFS="${RS}"
- for t in ${tokens}; do
- printf 'Token: %s\n' "$(tokname "${t}")"
- case "${t%${US}*}" in T_WORD)
- printf ' "%s"\n' "${t#T_WORD${US}}"
- ;;
- esac
- done
- unset IFS
-else
- echo FAIL
-fi
+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`'