-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.lisp
23 lines (23 loc) · 1012 Bytes
/
path.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(defpackage path
(:use :cl :gen-machine)
(:import-from :utils :ident-p)
(:export :make-machine :parse :valid :value :leftover))
(in-package path)
(defclass machine (gen-machine) ())
(defun make-machine (chars) (make-instance 'machine :leftover chars))
(defmethod parse ((m machine))
(consume m)
(cond ((delta m "slash" 'ident-p) (move m "path"))
((delta m "path" 'ident-p) (move m "path"))
((delta m "separator" 'ident-p) (move m "path"))
((delta-final m #\/ "empty") (move m "slash"))
((delta-final m #\/ "path") (move m "separator"))
((delta-final m #\? "slash" "path") (move m "final*"))
((delta-final m #\# "slash" "path") (move m "final*"))
((final m "empty" "slash" "path") (move m "final"))
(t (move m "error")))
(cond ((string= (state m) "error") nil)
((string= (state m) "final") t)
((string= (state m) "final*") (unconsume m) t)
((string= (state m) "slash") (parse m))
(t (save m) (parse m))))