summaryrefslogtreecommitdiffstats
path: root/parsing/parse.sh
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2016-02-20 14:54:49 (EST)
committer P. J. McDermott <pj@pehjota.net>2016-02-20 15:10:18 (EST)
commitff264a09cdf373ed2f9e14757ebd03317bb1955c (patch)
tree22a9a87f32a6e7a1f7997481a1efd46541a640b6 /parsing/parse.sh
parente978b31de0d40fe2054327f9adfc78b9d3fc0e1d (diff)
downloadeggshell-ff264a09cdf373ed2f9e14757ebd03317bb1955c.zip
eggshell-ff264a09cdf373ed2f9e14757ebd03317bb1955c.tar.gz
eggshell-ff264a09cdf373ed2f9e14757ebd03317bb1955c.tar.bz2
Move parse_sub() logic into lexer
Now the parser starts the lexer, which in turn starts the parser. Previously, the parser started both the lexer and itself and then asked the lexer all kinds of personal questions, like "Where are you?", "Whatcha doin'?", and "What are you wearing?". No one wants to know what their lexer is wearing. Seriously, don't ask. Parsers should mind their own business. Social interactions and personal questions between code modules should be kept to a minimum.
Diffstat (limited to 'parsing/parse.sh')
-rw-r--r--parsing/parse.sh45
1 files changed, 4 insertions, 41 deletions
diff --git a/parsing/parse.sh b/parsing/parse.sh
index d9fb6a1..196ad84 100644
--- a/parsing/parse.sh
+++ b/parsing/parse.sh
@@ -5,10 +5,11 @@ ETX="$(printf '\003.')"; ETX="${ETX%.}"
RS="$(printf '\036.')"; RS="${RS%.}"
US="$(printf '\037.')"; US="${US%.}"
+dbg=true
+dbg=false
+
dbg()
{
- dbg=true
- dbg=false
if ${dbg}; then
printf 'DEBUG: %s\n' "${@}" >&2
fi
@@ -583,50 +584,12 @@ sequential_sep()
return 1
}
-# Maybe parse() should just tell the lexer what the starting production (parser
-# entry point) is.
-parse_sub()
-{
- local fn="${1}"
- local ln="${2}"
- local lexer_char="${3}"
- local complete="${4}"
- shift 3
-
- init_lexer "${fn}" ${ln} "${lexer_char}"
-
- # If this returns (does not exit), there are no errors.
- complete_command
- if ${complete} && ! accept T_EOF; then
- synexp ''
- fi
- if ! ${complete}; then
- case "${tok%${US}*}" in
- T_RPAREN)
- ;;
- *)
- synerr 'Missing ")"'
- ;;
- esac
- fi
-
- get_lineno
- printf '%c' "${RS}"
- get_lexer_char
- printf '%c' "${RS}"
- get_tokens
-
- return 0
-}
-
parse()
{
local fn="${1}"
shift 1
- local toks=
- if toks="$(parse_sub "${fn}" 1 '' true)"; then
- printf '%s\n' "${toks#*${RS}*${RS}}"
+ if run_lexer "${fn}" complete_command; then
return 0
fi
return 1