Skip to content

Commit

Permalink
Merge pull request #20 from telekons/cset
Browse files Browse the repository at this point in the history
Character sets
  • Loading branch information
no-defun-allowed committed Jun 24, 2023
2 parents b2a9ab6 + 84be736 commit 9708962
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 568 deletions.
2 changes: 1 addition & 1 deletion Code/Compiler/code-generation.lisp
Expand Up @@ -162,7 +162,7 @@
for n from 0
collect (alexandria:format-symbol nil "TRANSITION-~d" n))))
`(tagbody
(isum-case value
(csum-case value
,(layout-less *layout*)
,(layout-equal *layout*)
,@(loop for transition in (state-transitions state)
Expand Down
4 changes: 2 additions & 2 deletions Code/DFA-construction/derivative-classes.lisp
Expand Up @@ -5,7 +5,7 @@
(let ((sets (make-hash-table :test 'equal)))
(loop for set1 in sets1
do (loop for set2 in sets2
for intersection = (set-intersection set1 set2)
for intersection = (csum-intersection set1 set2)
do (setf (gethash intersection sets) t)))
(alexandria:hash-table-keys sets)))

Expand All @@ -16,7 +16,7 @@
"Produce a list of the 'classes' (sets) of characters that compiling the regular expression would have to dispatch on."
(with-hash-consing (*derivative-classes* re)
(trivia:ematch re
((literal set) (list set (set-inverse set)))
((literal set) (list set (csum-complement set)))
((or (empty-string)
(tag-set _))
(list +universal-set+))
Expand Down
4 changes: 2 additions & 2 deletions Code/DFA-construction/derivative.lisp
Expand Up @@ -8,7 +8,7 @@
(trivia:ematch re
((or (empty-string) (empty-set) (tag-set _)) (empty-set))
((literal matching-set)
(if (set-null (set-intersection matching-set set))
(if (csum-null-p (csum-intersection matching-set set))
(empty-set)
(empty-string)))
((join r s)
Expand Down Expand Up @@ -69,7 +69,7 @@
do (setf (gethash target variables) value))))
(map 'nil
(lambda (element)
(let* ((new-re (derivative re (symbol-set (char-code element))))
(let* ((new-re (derivative re (singleton-set (char-code element))))
(effects (remove-if (lambda (x) (equal (car x) (cdr x)))
(effects re))))
(format t "~&~a~& ~:c ~a"
Expand Down
6 changes: 3 additions & 3 deletions Code/DFA-construction/make-dfa.lisp
Expand Up @@ -50,8 +50,8 @@
(state-transitions last-state)))
(t
(setf (transition-class same-transition)
(set-union (transition-class same-transition)
class))))))
(csum-union (transition-class same-transition)
class))))))

(trivia:defun-match re-stopped-p (re)
((alpha (empty-set) _) t)
Expand Down Expand Up @@ -104,7 +104,7 @@
(t
(let ((classes (derivative-classes expression)))
(dolist (class classes)
(unless (set-null class)
(unless (csum-null-p class)
(let* ((next-expression (derivative expression class))
(tags-to-set (keep-used-assignments
next-expression
Expand Down
13 changes: 6 additions & 7 deletions Code/DFA-construction/re-types.lisp
Expand Up @@ -14,19 +14,18 @@

(define-rewrites (literal set)
:printer ((literal set)
(print-isum set stream)))
(print-csum set stream)))

(defun kleene (r)
(repeat r 0 nil nil))
(trivia:defpattern kleene (r)
`(repeat ,r 0 nil nil))

(defun empty-set ()
(literal (symbol-set)))
(defun empty-set () (literal +empty-set+))
(trivia:defpattern empty-set ()
(alexandria:with-gensyms (set)
`(trivia:guard (literal ,set)
(set-null ,set))))
(csum-null-p ,set))))

(defun universal-set ()
(repeat (literal +universal-set+) 0 nil nil))
Expand Down Expand Up @@ -94,7 +93,7 @@
((either (empty-set) r) r)
((either r (empty-set)) r)
((either (literal s1) (literal s2))
(literal (set-union s1 s2)))
(literal (csum-union s1 s2)))
((either r (universal-set))
(if (has-tags-p r)
(trivia.next:next) ; Preserve tags then
Expand Down Expand Up @@ -144,7 +143,7 @@
((both (empty-string) (tag-set s))
(tag-set s))
((both (literal s1) (literal s2))
(literal (set-intersection s1 s2))))
(literal (csum-intersection s1 s2))))
:printer ((both r s)
(format stream "(~a) ∩ (~a)" r s)))
(define-rewrites (invert r)
Expand Down Expand Up @@ -186,7 +185,7 @@
(defun text (vector)
(reduce #'join (map 'vector
(lambda (e)
(literal (symbol-set (char-code e))))
(literal (singleton-set (char-code e))))
vector)
:initial-value (empty-string)
:from-end t))
Expand Down

0 comments on commit 9708962

Please sign in to comment.