Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't complete multi-state entries until they're actually done. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions parser.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,25 @@ See: csv-reader "))
(setf (didx te) -1))

(defmethod check-table-entry (table entry c)
"Given the next character in a stream check if the table entry matches
reset if it matches fully or doesnt match"
"Given the next character in a stream check if the table entry
matches reset if it matches fully or doesnt match. Returns the
dispatch function as a primary value if the entry matched and is
complete, or NIL otherwise. A secondary value is returned that
indicates whether this entry matched the input character."
(declare (ignore table))
(incf (didx entry))
(let ((de-char (aref (delimiter entry) (didx entry))))
(cond
((or (eql t de-char)
(char= c de-char))
(when (eql (didx entry) (dlen-1 entry))
(reset-table-entry entry)
t))
(cond
((eql (didx entry) (dlen-1 entry))
(reset-table-entry entry)
(values (dispatch entry) t))
(t (values nil t))))
(t
(reset-table-entry entry)
nil))))
(values nil nil)))))

;; holds the states that the state machine events will drive
(defclass csv-reader (read-dispatch-table)
Expand Down Expand Up @@ -361,9 +366,12 @@ See: csv-reader "))
if it matches, call the function with the table character and entry"
(iter (for entry in-vector (entries table))
(when (typep entry 'read-dispatch-table-entry)
(when (check-table-entry table entry c)
(funcall (dispatch entry) table c :table-entry entry)
(return t)))))
(multiple-value-bind (dispatch matchedp)
(check-table-entry table entry c)
(when dispatch
(funcall dispatch table c :table-entry entry))
(when matchedp
(return t))))))

(defun read-with-dispatch-table (table stream &aux (read-cnt 0))
"A generic function for processing all the characters of a stream until
Expand Down