Skip to content

Commit

Permalink
backpedaling: "grab them all" reductions must have a negative node count
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrand committed Aug 3, 2011
1 parent b8f7ca3 commit b4c451c
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/net/cgrand/parsley/fold.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@
(node! [this tag N]
(let [n (.size offsets)]
(u/cond
(> N n)
(or (> N n) (neg? N))
(do
(doto pending
(.add tag)
(.add (vec nodes))
(.add (- N n)))
(.clear nodes)
(.clear offsets))
(zero? N)
(when tag
(let [children (vec (.toArray nodes))]
(doto nodes .clear (.add (make-node tag children)))
(doto offsets .clear (.add 0))))
:let [m (- n N)
offset (.get offsets m)
_ (-> offsets (.subList (inc m) n) .clear)]
Expand Down Expand Up @@ -74,6 +69,16 @@
(defn cat [a b]
@(cat! (folding-queue a) b))

(defn finish [pfq]
(u/cond
:let [{:keys [pending nodes offsets make-node]} pfq]
(and (seq nodes) (seq pending))
nil
[[x & xs] (seq nodes)]
(when-not xs x)
[[[tag pnodes n] & xs] (seq (partition 3 pending))]
(when (and (not xs) (neg? n) tag) (make-node tag pnodes))))

(defn stitchability
"Returns :full, or a number (the number of states on A stack which remains untouched)
when rebasing is possible or nil."
Expand Down

0 comments on commit b4c451c

Please sign in to comment.