diff options
author | P. J. McDermott <pj@pehjota.net> | 2016-02-19 17:36:43 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2016-02-19 17:41:15 (EST) |
commit | b77d7967e9cf00002c6bc9fd1bbcf891a197115e (patch) | |
tree | 996ebdb5f0cd2a1e30b25fd9bf0dad6a9a28acd1 /parsing/parse.sh | |
parent | f6e55a026abf33867141896b1e227e791942c2a3 (diff) | |
download | eggshell-b77d7967e9cf00002c6bc9fd1bbcf891a197115e.zip eggshell-b77d7967e9cf00002c6bc9fd1bbcf891a197115e.tar.gz eggshell-b77d7967e9cf00002c6bc9fd1bbcf891a197115e.tar.bz2 |
Add error handling to lexer
Diffstat (limited to 'parsing/parse.sh')
-rw-r--r-- | parsing/parse.sh | 63 |
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`' |