Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 88.47 KB | None | 0 0
  1. diff --git a/runner/cljs/runner/runner.cljs b/runner/cljs/runner/runner.cljs
  2. index e1b2f97..74bc9f6 100644
  3. --- a/runner/cljs/runner/runner.cljs
  4. +++ b/runner/cljs/runner/runner.cljs
  5. @@ -1,13 +1,13 @@
  6. (ns instaparse.runner.runner
  7. (:require [cljs.nodejs :as nodejs]
  8. - [instaparse.abnf-test]
  9. - [instaparse.auto-flatten-seq-test]
  10. - [instaparse.core-test]
  11. - [instaparse.defparser-test]
  12. - [instaparse.grammars]
  13. - [instaparse.repeat-test]
  14. - [instaparse.specs]
  15. - [cljs.test :as test :refer-macros [run-tests]]))
  16. + [instaparse.abnf-test]
  17. + [instaparse.auto-flatten-seq-test]
  18. + [instaparse.core-test]
  19. + [instaparse.defparser-test]
  20. + [instaparse.grammars]
  21. + [instaparse.repeat-test]
  22. + [instaparse.specs]
  23. + [cljs.test :as test :refer-macros [run-tests]]))
  24.  
  25. (nodejs/enable-util-print!)
  26.  
  27. diff --git a/src/instaparse/abnf.cljc b/src/instaparse/abnf.cljc
  28. index a740413..3838f35 100644
  29. --- a/src/instaparse/abnf.cljc
  30. +++ b/src/instaparse/abnf.cljc
  31. @@ -2,15 +2,15 @@
  32. "This is the context free grammar that recognizes ABNF notation."
  33. (:refer-clojure :exclude [cat])
  34. (:require [instaparse.transform :as t]
  35. - [instaparse.cfg :as cfg]
  36. - [instaparse.gll :as gll]
  37. - [instaparse.reduction :as red]
  38. - [instaparse.util :refer [throw-runtime-exception]]
  39. - [instaparse.combinators-source :refer
  40. - [Epsilon opt plus star rep alt ord cat string-ci string
  41. - string-ci regexp nt look neg hide hide-tag unicode-char]]
  42. - #?(:cljs [goog.string.format])
  43. - [clojure.walk :as walk])
  44. + [instaparse.cfg :as cfg]
  45. + [instaparse.gll :as gll]
  46. + [instaparse.reduction :as red]
  47. + [instaparse.util :refer [throw-runtime-exception]]
  48. + [instaparse.combinators-source :refer
  49. + [Epsilon opt plus star rep alt ord cat string-ci string
  50. + string-ci regexp nt look neg hide hide-tag unicode-char]]
  51. + #?(:cljs [goog.string.format])
  52. + [clojure.walk :as walk])
  53. #?(:cljs (:require-macros [instaparse.abnf :refer [precompile-cljs-grammar]])))
  54.  
  55. (def ^:dynamic *case-insensitive*
  56. @@ -204,17 +204,17 @@ regexp = #\"#'[^'\\\\]*(?:\\\\.[^'\\\\]*)*'\"
  57.  
  58. :repetition (fn
  59. ([repeat element]
  60. - (cond
  61. - (empty? repeat) (star element)
  62. - (= (count repeat) 2) (rep (:low repeat) (:high repeat) element)
  63. - (= (:low repeat) 1) (plus element)
  64. - (= (:high repeat) 1) (opt element)
  65. - :else (rep (or (:low repeat) 0)
  66. - (or (:high repeat) #?(:clj Double/POSITIVE_INFINITY
  67. - :cljs js/Infinity))
  68. - element)))
  69. + (cond
  70. + (empty? repeat) (star element)
  71. + (= (count repeat) 2) (rep (:low repeat) (:high repeat) element)
  72. + (= (:low repeat) 1) (plus element)
  73. + (= (:high repeat) 1) (opt element)
  74. + :else (rep (or (:low repeat) 0)
  75. + (or (:high repeat) #?(:clj Double/POSITIVE_INFINITY
  76. + :cljs js/Infinity))
  77. + element)))
  78. ([element]
  79. - element))
  80. + element))
  81. :option opt
  82. :hide hide
  83. :look look
  84. diff --git a/src/instaparse/auto_flatten_seq.cljc b/src/instaparse/auto_flatten_seq.cljc
  85. index 7de638c..14b0bd9 100644
  86. --- a/src/instaparse/auto_flatten_seq.cljc
  87. +++ b/src/instaparse/auto_flatten_seq.cljc
  88. @@ -78,164 +78,164 @@
  89. (flat-seq v (delve v [0]))
  90. nil))
  91. ([v index]
  92. - (lazy-seq
  93. - (cons (get-in v index)
  94. - (when-let [next-index (advance v index)]
  95. - (flat-seq v next-index))))))
  96. + (lazy-seq
  97. + (cons (get-in v index)
  98. + (when-let [next-index (advance v index)]
  99. + (flat-seq v next-index))))))
  100.  
  101. #?(:clj
  102. -(deftype AutoFlattenSeq [^PersistentVector v ^int premix-hashcode ^int hashcode
  103. - ^int cnt ^boolean dirty
  104. - ^:unsynchronized-mutable ^clojure.lang.ISeq cached-seq]
  105. - Object
  106. - (toString [self] (.toString (seq self)))
  107. - (hashCode [self] hashcode)
  108. - (equals [self other]
  109. - (and (instance? AutoFlattenSeq other)
  110. - (== hashcode (.hashcode ^AutoFlattenSeq other))
  111. - (== cnt (.cnt ^AutoFlattenSeq other))
  112. - (= dirty (.dirty ^AutoFlattenSeq other))
  113. - (= v (.v ^AutoFlattenSeq other))))
  114. - clojure.lang.IHashEq
  115. - (hasheq [self] hashcode)
  116. - java.util.Collection
  117. - (iterator [self]
  118. - (if-let [^java.util.Collection s (seq self)]
  119. - (.iterator s)
  120. - (let [^java.util.Collection e ()]
  121. - (.iterator e))))
  122. - (size [self]
  123. - cnt)
  124. - (toArray [self]
  125. - (let [^java.util.Collection s (seq self)]
  126. - (.toArray s)))
  127. - clojure.lang.Sequential
  128. - clojure.lang.ISeq
  129. - (equiv [self other]
  130. - (and (== hashcode (hash other))
  131. - (== cnt (count other))
  132. - (or (== cnt 0)
  133. - (= (seq self) other))))
  134. - (empty [self] (with-meta EMPTY (meta self)))
  135. - (first [self] (first (seq self)))
  136. - (next [self] (next (seq self)))
  137. - (more [self] (rest (seq self)))
  138. - (cons [self obj]
  139. - (cons obj self))
  140. - ConjFlat
  141. - (conj-flat [self obj]
  142. - (cond
  143. - (nil? obj) self
  144. - (afs? obj)
  145. - (cond
  146. - (zero? cnt) obj
  147. - (<= (count obj) threshold)
  148. - (let [phc (hash-cat self obj)
  149. - new-cnt (+ cnt (count obj))]
  150. - (AutoFlattenSeq. (into v obj) phc (mix-collection-hash-bc phc new-cnt) new-cnt
  151. - (or dirty (.dirty ^AutoFlattenSeq obj)) nil))
  152. - :else
  153. - (let [phc (hash-cat self obj)
  154. - new-cnt (+ cnt (count obj))]
  155. - (AutoFlattenSeq. (conj v obj) phc (mix-collection-hash-bc phc new-cnt) new-cnt
  156. - true nil)))
  157. - :else
  158. - (let [phc (hash-conj premix-hashcode obj)
  159. - new-cnt (inc cnt)]
  160. - (AutoFlattenSeq. (conj v obj) phc (mix-collection-hash-bc phc new-cnt) new-cnt dirty nil))))
  161. - (cached? [self] cached-seq)
  162. - clojure.lang.Counted
  163. - (count [self] cnt)
  164. - clojure.lang.ILookup
  165. - (valAt [self key]
  166. - (.valAt v key))
  167. - (valAt [self key not-found]
  168. - (.valAt v key not-found))
  169. - clojure.lang.IObj
  170. - (withMeta [self metamap]
  171. - (AutoFlattenSeq. (with-meta v metamap) premix-hashcode hashcode cnt dirty nil))
  172. - clojure.lang.IMeta
  173. - (meta [self]
  174. - (meta v))
  175. - clojure.lang.Seqable
  176. - (seq [self]
  177. - (if cached-seq cached-seq
  178. - (do
  179. - (set! cached-seq (if dirty (flat-seq v) (seq v)))
  180. - cached-seq))))
  181. -:cljs
  182. -(deftype AutoFlattenSeq [^PersistentVector v ^number premix-hashcode ^number hashcode ^number cnt ^boolean dirty
  183. - ^:unsynchronized-mutable ^ISeq cached-seq]
  184. - Object
  185. - (toString [self] (pr-str* (seq self)))
  186. - IHash
  187. - (-hash [self] hashcode)
  188. - ISequential
  189. - ISeq
  190. - (-first [self] (first (seq self)))
  191. - (-rest [self] (rest (seq self)))
  192. - IEquiv
  193. - (-equiv [self other]
  194. - (and ;(instance? AutoFlattenSeq other)
  195. + (deftype AutoFlattenSeq [^PersistentVector v ^int premix-hashcode ^int hashcode
  196. + ^int cnt ^boolean dirty
  197. + ^:unsynchronized-mutable ^clojure.lang.ISeq cached-seq]
  198. + Object
  199. + (toString [self] (.toString (seq self)))
  200. + (hashCode [self] hashcode)
  201. + (equals [self other]
  202. + (and (instance? AutoFlattenSeq other)
  203. + (== hashcode (.hashcode ^AutoFlattenSeq other))
  204. + (== cnt (.cnt ^AutoFlattenSeq other))
  205. + (= dirty (.dirty ^AutoFlattenSeq other))
  206. + (= v (.v ^AutoFlattenSeq other))))
  207. + clojure.lang.IHashEq
  208. + (hasheq [self] hashcode)
  209. + java.util.Collection
  210. + (iterator [self]
  211. + (if-let [^java.util.Collection s (seq self)]
  212. + (.iterator s)
  213. + (let [^java.util.Collection e ()]
  214. + (.iterator e))))
  215. + (size [self]
  216. + cnt)
  217. + (toArray [self]
  218. + (let [^java.util.Collection s (seq self)]
  219. + (.toArray s)))
  220. + clojure.lang.Sequential
  221. + clojure.lang.ISeq
  222. + (equiv [self other]
  223. + (and (== hashcode (hash other))
  224. + (== cnt (count other))
  225. + (or (== cnt 0)
  226. + (= (seq self) other))))
  227. + (empty [self] (with-meta EMPTY (meta self)))
  228. + (first [self] (first (seq self)))
  229. + (next [self] (next (seq self)))
  230. + (more [self] (rest (seq self)))
  231. + (cons [self obj]
  232. + (cons obj self))
  233. + ConjFlat
  234. + (conj-flat [self obj]
  235. + (cond
  236. + (nil? obj) self
  237. + (afs? obj)
  238. + (cond
  239. + (zero? cnt) obj
  240. + (<= (count obj) threshold)
  241. + (let [phc (hash-cat self obj)
  242. + new-cnt (+ cnt (count obj))]
  243. + (AutoFlattenSeq. (into v obj) phc (mix-collection-hash-bc phc new-cnt) new-cnt
  244. + (or dirty (.dirty ^AutoFlattenSeq obj)) nil))
  245. + :else
  246. + (let [phc (hash-cat self obj)
  247. + new-cnt (+ cnt (count obj))]
  248. + (AutoFlattenSeq. (conj v obj) phc (mix-collection-hash-bc phc new-cnt) new-cnt
  249. + true nil)))
  250. + :else
  251. + (let [phc (hash-conj premix-hashcode obj)
  252. + new-cnt (inc cnt)]
  253. + (AutoFlattenSeq. (conj v obj) phc (mix-collection-hash-bc phc new-cnt) new-cnt dirty nil))))
  254. + (cached? [self] cached-seq)
  255. + clojure.lang.Counted
  256. + (count [self] cnt)
  257. + clojure.lang.ILookup
  258. + (valAt [self key]
  259. + (.valAt v key))
  260. + (valAt [self key not-found]
  261. + (.valAt v key not-found))
  262. + clojure.lang.IObj
  263. + (withMeta [self metamap]
  264. + (AutoFlattenSeq. (with-meta v metamap) premix-hashcode hashcode cnt dirty nil))
  265. + clojure.lang.IMeta
  266. + (meta [self]
  267. + (meta v))
  268. + clojure.lang.Seqable
  269. + (seq [self]
  270. + (if cached-seq cached-seq
  271. + (do
  272. + (set! cached-seq (if dirty (flat-seq v) (seq v)))
  273. + cached-seq))))
  274. + :cljs
  275. + (deftype AutoFlattenSeq [^PersistentVector v ^number premix-hashcode ^number hashcode ^number cnt ^boolean dirty
  276. + ^:unsynchronized-mutable ^ISeq cached-seq]
  277. + Object
  278. + (toString [self] (pr-str* (seq self)))
  279. + IHash
  280. + (-hash [self] hashcode)
  281. + ISequential
  282. + ISeq
  283. + (-first [self] (first (seq self)))
  284. + (-rest [self] (rest (seq self)))
  285. + IEquiv
  286. + (-equiv [self other]
  287. + (and ;(instance? AutoFlattenSeq other)
  288. (= hashcode (hash other))
  289. (= cnt (count other))
  290. (or (= cnt 0)
  291. (= (seq self) other))))
  292. - ICollection
  293. - (-conj [self o] (cons o self))
  294. - IEmptyableCollection
  295. - (-empty [self] (with-meta EMPTY (meta self)))
  296. - INext
  297. - (-next [self] (next (seq self)))
  298. - ConjFlat
  299. - (conj-flat [self obj]
  300. - (cond
  301. - (nil? obj) self
  302. - (afs? obj)
  303. - (cond
  304. - (zero? cnt) obj
  305. - (<= (count obj) threshold)
  306. - (let [phc (hash-cat self obj)
  307. - new-cnt (+ cnt (count obj))]
  308. - (AutoFlattenSeq. (into v obj) phc (mix-collection-hash phc new-cnt) new-cnt
  309. - (or dirty (.-dirty ^AutoFlattenSeq obj)) nil))
  310. - :else
  311. - (let [phc (hash-cat self obj)
  312. - new-cnt (+ cnt (count obj))]
  313. - (AutoFlattenSeq. (conj v obj) phc (mix-collection-hash phc new-cnt) new-cnt
  314. - true nil)))
  315. - :else
  316. - (let [phc (hash-conj premix-hashcode obj)
  317. - new-cnt (inc cnt)]
  318. - (AutoFlattenSeq. (conj v obj) phc (mix-collection-hash phc new-cnt) new-cnt dirty nil))))
  319. - (cached? [self] cached-seq)
  320. - ICounted
  321. - (-count [self] cnt)
  322. - ILookup
  323. - (-lookup [self key]
  324. - (-lookup v key))
  325. - (-lookup [self key not-found]
  326. - (-lookup v key not-found))
  327. - IWithMeta
  328. - (-with-meta [self metamap]
  329. - (AutoFlattenSeq. (with-meta v metamap) premix-hashcode hashcode cnt dirty nil))
  330. - IMeta
  331. - (-meta [self]
  332. - (meta v))
  333. - ISeqable
  334. - (-seq [self]
  335. - (if cached-seq cached-seq
  336. - (do
  337. - (set! cached-seq (if dirty (flat-seq v) (seq v)))
  338. - cached-seq)))))
  339. + ICollection
  340. + (-conj [self o] (cons o self))
  341. + IEmptyableCollection
  342. + (-empty [self] (with-meta EMPTY (meta self)))
  343. + INext
  344. + (-next [self] (next (seq self)))
  345. + ConjFlat
  346. + (conj-flat [self obj]
  347. + (cond
  348. + (nil? obj) self
  349. + (afs? obj)
  350. + (cond
  351. + (zero? cnt) obj
  352. + (<= (count obj) threshold)
  353. + (let [phc (hash-cat self obj)
  354. + new-cnt (+ cnt (count obj))]
  355. + (AutoFlattenSeq. (into v obj) phc (mix-collection-hash phc new-cnt) new-cnt
  356. + (or dirty (.-dirty ^AutoFlattenSeq obj)) nil))
  357. + :else
  358. + (let [phc (hash-cat self obj)
  359. + new-cnt (+ cnt (count obj))]
  360. + (AutoFlattenSeq. (conj v obj) phc (mix-collection-hash phc new-cnt) new-cnt
  361. + true nil)))
  362. + :else
  363. + (let [phc (hash-conj premix-hashcode obj)
  364. + new-cnt (inc cnt)]
  365. + (AutoFlattenSeq. (conj v obj) phc (mix-collection-hash phc new-cnt) new-cnt dirty nil))))
  366. + (cached? [self] cached-seq)
  367. + ICounted
  368. + (-count [self] cnt)
  369. + ILookup
  370. + (-lookup [self key]
  371. + (-lookup v key))
  372. + (-lookup [self key not-found]
  373. + (-lookup v key not-found))
  374. + IWithMeta
  375. + (-with-meta [self metamap]
  376. + (AutoFlattenSeq. (with-meta v metamap) premix-hashcode hashcode cnt dirty nil))
  377. + IMeta
  378. + (-meta [self]
  379. + (meta v))
  380. + ISeqable
  381. + (-seq [self]
  382. + (if cached-seq cached-seq
  383. + (do
  384. + (set! cached-seq (if dirty (flat-seq v) (seq v)))
  385. + cached-seq)))))
  386.  
  387. #?(:clj
  388. (defn- hash-cat ^long [^AutoFlattenSeq v1 ^AutoFlattenSeq v2]
  389. (let [c (count v2)
  390. e (int (expt 31 c))]
  391. (unchecked-add-int
  392. - (unchecked-multiply-int e (.premix-hashcode v1))
  393. - (unchecked-subtract-int (.premix-hashcode v2) e))))
  394. + (unchecked-multiply-int e (.premix-hashcode v1))
  395. + (unchecked-subtract-int (.premix-hashcode v2) e))))
  396. :cljs
  397. (defn- hash-cat ^number [^AutoFlattenSeq v1 ^AutoFlattenSeq v2]
  398. (let [c (count v2)
  399. @@ -251,8 +251,8 @@
  400. (loop [acc (int 1) i (int 0)]
  401. (if (< i cnt)
  402. (recur (unchecked-add-int
  403. - (unchecked-multiply-int thirty-one acc)
  404. - (hash (v i)))
  405. + (unchecked-multiply-int thirty-one acc)
  406. + (hash (v i)))
  407. (inc i))
  408. acc)))
  409. (hash v)))
  410. @@ -311,195 +311,195 @@
  411. (^PersistentVector get-vec [self]))
  412.  
  413. #?(:clj
  414. -(deftype FlattenOnDemandVector [v ; ref containing PersistentVector or nil
  415. - ^int hashcode
  416. - ^int cnt
  417. - flat] ; ref containing PersistentVector or nil
  418. - GetVec
  419. - (get-vec [self]
  420. - (when (not @flat)
  421. - (dosync
  422. - (when (not @flat)
  423. - (ref-set flat (with-meta (flat-vec @v) (meta @v)))
  424. - (ref-set v nil)))) ; clear out v so it can be garbage collected
  425. - @flat)
  426. + (deftype FlattenOnDemandVector [v ; ref containing PersistentVector or nil
  427. + ^int hashcode
  428. + ^int cnt
  429. + flat] ; ref containing PersistentVector or nil
  430. + GetVec
  431. + (get-vec [self]
  432. + (when (not @flat)
  433. + (dosync
  434. + (when (not @flat)
  435. + (ref-set flat (with-meta (flat-vec @v) (meta @v)))
  436. + (ref-set v nil)))) ; clear out v so it can be garbage collected
  437. + @flat)
  438.  
  439. - Object
  440. - (toString [self] (.toString (get-vec self)))
  441. - (hashCode [self] hashcode)
  442. - (equals [self other]
  443. - (and (instance? FlattenOnDemandVector other)
  444. - (== hashcode (.hashcode ^FlattenOnDemandVector other))
  445. - (== cnt (.cnt ^FlattenOnDemandVector other))
  446. - (= v (.v ^FlattenOnDemandVector other))
  447. - (= flat (.flat ^FlattenOnDemandVector other))))
  448. - clojure.lang.IHashEq
  449. - (hasheq [self] hashcode)
  450. - java.util.Collection
  451. - (iterator [self]
  452. - (.iterator (get-vec self)))
  453. - (size [self]
  454. - cnt)
  455. - (toArray [self]
  456. - (.toArray (get-vec self)))
  457. - clojure.lang.IPersistentCollection
  458. - (equiv [self other]
  459. - (or
  460. - (and (== hashcode (hash other))
  461. - (== cnt (count other))
  462. - (= (get-vec self) other))))
  463. - (empty [self] (with-meta [] (meta self)))
  464. - clojure.lang.Counted
  465. - (count [self] cnt)
  466. - clojure.lang.IPersistentVector
  467. - (assoc [self i val]
  468. - (assoc (get-vec self) i val))
  469. - (assocN [self i val]
  470. - (.assocN (get-vec self) i val))
  471. - (length [self]
  472. - cnt)
  473. - (cons [self obj]
  474. - (conj (get-vec self) obj))
  475. - clojure.lang.IObj
  476. - (withMeta [self metamap]
  477. - (if @flat
  478. - (FlattenOnDemandVector. (ref @v) hashcode cnt (ref (with-meta @flat metamap)))
  479. - (FlattenOnDemandVector. (ref (with-meta @v metamap)) hashcode cnt (ref @flat))))
  480. - clojure.lang.IMeta
  481. - (meta [self]
  482. - (if @flat (meta @flat) (meta @v)))
  483. - clojure.lang.Seqable
  484. - (seq [self]
  485. - (seq (get-vec self)))
  486. - clojure.lang.ILookup
  487. - (valAt [self key]
  488. - (.valAt (get-vec self) key))
  489. - (valAt [self key not-found]
  490. - (.valAt (get-vec self) key not-found))
  491. - clojure.lang.Indexed
  492. - (nth [self i]
  493. - (.nth (get-vec self) i))
  494. - (nth [self i not-found]
  495. - (.nth (get-vec self) i not-found))
  496. - clojure.lang.IFn
  497. - (invoke [self arg]
  498. - (.invoke (get-vec self) arg))
  499. - (applyTo [self arglist]
  500. - (.applyTo (get-vec self) arglist))
  501. - clojure.lang.Reversible
  502. - (rseq [self]
  503. - (if (pos? cnt)
  504. - (rseq (get-vec self))
  505. - nil))
  506. - clojure.lang.IPersistentStack
  507. - (peek [self]
  508. - (peek (get-vec self)))
  509. - (pop [self]
  510. - (pop (get-vec self)))
  511. - clojure.lang.Associative
  512. - (containsKey [self k]
  513. - (.containsKey (get-vec self) k))
  514. - (entryAt [self k]
  515. - (.entryAt (get-vec self) k))
  516. - IKVReduce
  517. - (kv-reduce [self f init]
  518. - (.kvreduce (get-vec self) f init))
  519. - java.lang.Comparable
  520. - (compareTo [self that]
  521. - (.compareTo (get-vec self) that))
  522. - java.util.List
  523. - (get [self i] (nth (get-vec self) i))
  524. - (indexOf [self o] (.indexOf (get-vec self) o))
  525. - (lastIndexOf [self o] (.lastIndexOf (get-vec self) o))
  526. - (listIterator [self]
  527. - (.listIterator (get-vec self) 0))
  528. - (listIterator [self i]
  529. - (.listIterator (get-vec self) i))
  530. - (subList [self a z]
  531. - (.subList (get-vec self) a z))
  532. - )
  533. -:cljs
  534. -(deftype FlattenOnDemandVector [v ; atom containing PersistentVector or nil
  535. - ^number hashcode
  536. - ^number cnt
  537. - flat] ; atom containing PersistentVector or nil
  538. - GetVec
  539. - (get-vec [self]
  540. - (when (not @flat)
  541. - (swap! flat (fn [_] (with-meta (flat-vec @v) (meta @v))))
  542. - (swap! v (fn [_] nil))) ; clear out v so it can be garbage collected
  543. - @flat)
  544. + Object
  545. + (toString [self] (.toString (get-vec self)))
  546. + (hashCode [self] hashcode)
  547. + (equals [self other]
  548. + (and (instance? FlattenOnDemandVector other)
  549. + (== hashcode (.hashcode ^FlattenOnDemandVector other))
  550. + (== cnt (.cnt ^FlattenOnDemandVector other))
  551. + (= v (.v ^FlattenOnDemandVector other))
  552. + (= flat (.flat ^FlattenOnDemandVector other))))
  553. + clojure.lang.IHashEq
  554. + (hasheq [self] hashcode)
  555. + java.util.Collection
  556. + (iterator [self]
  557. + (.iterator (get-vec self)))
  558. + (size [self]
  559. + cnt)
  560. + (toArray [self]
  561. + (.toArray (get-vec self)))
  562. + clojure.lang.IPersistentCollection
  563. + (equiv [self other]
  564. + (or
  565. + (and (== hashcode (hash other))
  566. + (== cnt (count other))
  567. + (= (get-vec self) other))))
  568. + (empty [self] (with-meta [] (meta self)))
  569. + clojure.lang.Counted
  570. + (count [self] cnt)
  571. + clojure.lang.IPersistentVector
  572. + (assoc [self i val]
  573. + (assoc (get-vec self) i val))
  574. + (assocN [self i val]
  575. + (.assocN (get-vec self) i val))
  576. + (length [self]
  577. + cnt)
  578. + (cons [self obj]
  579. + (conj (get-vec self) obj))
  580. + clojure.lang.IObj
  581. + (withMeta [self metamap]
  582. + (if @flat
  583. + (FlattenOnDemandVector. (ref @v) hashcode cnt (ref (with-meta @flat metamap)))
  584. + (FlattenOnDemandVector. (ref (with-meta @v metamap)) hashcode cnt (ref @flat))))
  585. + clojure.lang.IMeta
  586. + (meta [self]
  587. + (if @flat (meta @flat) (meta @v)))
  588. + clojure.lang.Seqable
  589. + (seq [self]
  590. + (seq (get-vec self)))
  591. + clojure.lang.ILookup
  592. + (valAt [self key]
  593. + (.valAt (get-vec self) key))
  594. + (valAt [self key not-found]
  595. + (.valAt (get-vec self) key not-found))
  596. + clojure.lang.Indexed
  597. + (nth [self i]
  598. + (.nth (get-vec self) i))
  599. + (nth [self i not-found]
  600. + (.nth (get-vec self) i not-found))
  601. + clojure.lang.IFn
  602. + (invoke [self arg]
  603. + (.invoke (get-vec self) arg))
  604. + (applyTo [self arglist]
  605. + (.applyTo (get-vec self) arglist))
  606. + clojure.lang.Reversible
  607. + (rseq [self]
  608. + (if (pos? cnt)
  609. + (rseq (get-vec self))
  610. + nil))
  611. + clojure.lang.IPersistentStack
  612. + (peek [self]
  613. + (peek (get-vec self)))
  614. + (pop [self]
  615. + (pop (get-vec self)))
  616. + clojure.lang.Associative
  617. + (containsKey [self k]
  618. + (.containsKey (get-vec self) k))
  619. + (entryAt [self k]
  620. + (.entryAt (get-vec self) k))
  621. + IKVReduce
  622. + (kv-reduce [self f init]
  623. + (.kvreduce (get-vec self) f init))
  624. + java.lang.Comparable
  625. + (compareTo [self that]
  626. + (.compareTo (get-vec self) that))
  627. + java.util.List
  628. + (get [self i] (nth (get-vec self) i))
  629. + (indexOf [self o] (.indexOf (get-vec self) o))
  630. + (lastIndexOf [self o] (.lastIndexOf (get-vec self) o))
  631. + (listIterator [self]
  632. + (.listIterator (get-vec self) 0))
  633. + (listIterator [self i]
  634. + (.listIterator (get-vec self) i))
  635. + (subList [self a z]
  636. + (.subList (get-vec self) a z))
  637. + )
  638. + :cljs
  639. + (deftype FlattenOnDemandVector [v ; atom containing PersistentVector or nil
  640. + ^number hashcode
  641. + ^number cnt
  642. + flat] ; atom containing PersistentVector or nil
  643. + GetVec
  644. + (get-vec [self]
  645. + (when (not @flat)
  646. + (swap! flat (fn [_] (with-meta (flat-vec @v) (meta @v))))
  647. + (swap! v (fn [_] nil))) ; clear out v so it can be garbage collected
  648. + @flat)
  649.  
  650. - Object
  651. - (toString [self]
  652. - (pr-str* (get-vec self)))
  653. - IHash
  654. - (-hash [self] hashcode)
  655. - IEquiv
  656. - (-equiv [self other]
  657. - (or
  658. - (and (= hashcode (hash other))
  659. - (= cnt (count other))
  660. - (= (get-vec self) other))))
  661. - IEmptyableCollection
  662. - (-empty [self] (with-meta [] (meta self)))
  663. - ICounted
  664. - (-count [self] cnt)
  665. - IVector
  666. - (-assoc-n [self i val]
  667. - (-assoc-n (get-vec self) i val))
  668. - ICollection
  669. - (-conj [self obj]
  670. - (conj (get-vec self) obj))
  671. - IWithMeta
  672. - (-with-meta [self metamap]
  673. - (if @flat
  674. - (FlattenOnDemandVector. (atom @v) hashcode cnt (atom (with-meta @flat metamap)))
  675. - (FlattenOnDemandVector. (atom (with-meta @v metamap)) hashcode cnt (atom @flat))))
  676. - IMeta
  677. - (-meta [self]
  678. - (if @flat (meta @flat) (meta @v)))
  679. - ISequential
  680. - ISeqable
  681. - (-seq [self]
  682. - (seq (get-vec self)))
  683. - ILookup
  684. - (-lookup [self key]
  685. - (-lookup (get-vec self) key))
  686. - (-lookup [self key not-found]
  687. - (-lookup (get-vec self) key not-found))
  688. - IIndexed
  689. - (-nth [self i]
  690. - (-nth (get-vec self) i))
  691. - (-nth [self i not-found]
  692. - (-nth (get-vec self) i not-found))
  693. - IFn
  694. - (-invoke [self arg]
  695. - (-invoke (get-vec self) arg))
  696. - (-invoke [self arg not-found]
  697. - (-invoke (get-vec self) arg not-found))
  698. - IReversible
  699. - (-rseq [self]
  700. - (if (pos? cnt)
  701. - (rseq (get-vec self))
  702. - nil))
  703. - IStack
  704. - (-peek [self]
  705. - (-peek (get-vec self)))
  706. - (-pop [self]
  707. - (-pop (get-vec self)))
  708. - IAssociative
  709. - (-assoc [self i val]
  710. - (assoc (get-vec self) i val))
  711. - (-contains-key? [self k]
  712. - (-contains-key? (get-vec self) k))
  713. - IKVReduce
  714. - (-kv-reduce [self f init]
  715. - (-kv-reduce (get-vec self) f init))
  716. - IComparable
  717. - (-compare [self that]
  718. - (-compare (get-vec self) that))
  719. - ))
  720. + Object
  721. + (toString [self]
  722. + (pr-str* (get-vec self)))
  723. + IHash
  724. + (-hash [self] hashcode)
  725. + IEquiv
  726. + (-equiv [self other]
  727. + (or
  728. + (and (= hashcode (hash other))
  729. + (= cnt (count other))
  730. + (= (get-vec self) other))))
  731. + IEmptyableCollection
  732. + (-empty [self] (with-meta [] (meta self)))
  733. + ICounted
  734. + (-count [self] cnt)
  735. + IVector
  736. + (-assoc-n [self i val]
  737. + (-assoc-n (get-vec self) i val))
  738. + ICollection
  739. + (-conj [self obj]
  740. + (conj (get-vec self) obj))
  741. + IWithMeta
  742. + (-with-meta [self metamap]
  743. + (if @flat
  744. + (FlattenOnDemandVector. (atom @v) hashcode cnt (atom (with-meta @flat metamap)))
  745. + (FlattenOnDemandVector. (atom (with-meta @v metamap)) hashcode cnt (atom @flat))))
  746. + IMeta
  747. + (-meta [self]
  748. + (if @flat (meta @flat) (meta @v)))
  749. + ISequential
  750. + ISeqable
  751. + (-seq [self]
  752. + (seq (get-vec self)))
  753. + ILookup
  754. + (-lookup [self key]
  755. + (-lookup (get-vec self) key))
  756. + (-lookup [self key not-found]
  757. + (-lookup (get-vec self) key not-found))
  758. + IIndexed
  759. + (-nth [self i]
  760. + (-nth (get-vec self) i))
  761. + (-nth [self i not-found]
  762. + (-nth (get-vec self) i not-found))
  763. + IFn
  764. + (-invoke [self arg]
  765. + (-invoke (get-vec self) arg))
  766. + (-invoke [self arg not-found]
  767. + (-invoke (get-vec self) arg not-found))
  768. + IReversible
  769. + (-rseq [self]
  770. + (if (pos? cnt)
  771. + (rseq (get-vec self))
  772. + nil))
  773. + IStack
  774. + (-peek [self]
  775. + (-peek (get-vec self)))
  776. + (-pop [self]
  777. + (-pop (get-vec self)))
  778. + IAssociative
  779. + (-assoc [self i val]
  780. + (assoc (get-vec self) i val))
  781. + (-contains-key? [self k]
  782. + (-contains-key? (get-vec self) k))
  783. + IKVReduce
  784. + (-kv-reduce [self f init]
  785. + (-kv-reduce (get-vec self) f init))
  786. + IComparable
  787. + (-compare [self that]
  788. + (-compare (get-vec self) that))
  789. + ))
  790.  
  791. #?(:cljs
  792. (extend-protocol IPrintWithWriter
  793. @@ -514,15 +514,15 @@
  794. (vec (seq afs))
  795. #?(:clj
  796. (FlattenOnDemandVector.
  797. - (ref (.-v afs))
  798. - (.-hashcode afs)
  799. - (.-cnt afs)
  800. - (ref nil))
  801. + (ref (.-v afs))
  802. + (.-hashcode afs)
  803. + (.-cnt afs)
  804. + (ref nil))
  805. :cljs
  806. (FlattenOnDemandVector.
  807. - (atom (.-v afs))
  808. - (.-hashcode afs)
  809. - (.-cnt afs)
  810. - (atom nil))))
  811. + (atom (.-v afs))
  812. + (.-hashcode afs)
  813. + (.-cnt afs)
  814. + (atom nil))))
  815. :else
  816. (.-v afs)))
  817. diff --git a/src/instaparse/cfg.cljc b/src/instaparse/cfg.cljc
  818. index 36aabd8..7bb684b 100644
  819. --- a/src/instaparse/cfg.cljc
  820. +++ b/src/instaparse/cfg.cljc
  821. @@ -4,13 +4,13 @@
  822. (:require [instaparse.combinators-source :refer
  823. [Epsilon opt plus star rep alt ord cat string-ci string
  824. string-ci regexp nt look neg hide hide-tag]]
  825. - [instaparse.reduction :refer [apply-standard-reductions]]
  826. - [instaparse.gll :refer [parse]]
  827. - [instaparse.util :refer [throw-illegal-argument-exception
  828. - throw-runtime-exception]]
  829. - [clojure.string :as str]
  830. - #?(:cljs [cljs.tools.reader :as reader])
  831. - #?(:cljs [cljs.tools.reader.reader-types :as readers])))
  832. + [instaparse.reduction :refer [apply-standard-reductions]]
  833. + [instaparse.gll :refer [parse]]
  834. + [instaparse.util :refer [throw-illegal-argument-exception
  835. + throw-runtime-exception]]
  836. + [clojure.string :as str]
  837. + #?(:cljs [cljs.tools.reader :as reader])
  838. + #?(:cljs [cljs.tools.reader.reader-types :as readers])))
  839.  
  840. (def ^:dynamic *case-insensitive-literals*
  841. "Sets whether all string literal terminals in a built grammar
  842. @@ -78,87 +78,87 @@
  843. (neg (nt :epsilon))
  844. (regexp
  845. (regex-doc "[^, \\r\\t\\n<>(){}\\[\\]+*?:=|'\"#&!;./]+" "Non-terminal")))
  846. - :hide-nt (cat (hide (string "<"))
  847. - opt-whitespace
  848. - (nt :nt)
  849. - opt-whitespace
  850. - (hide (string ">")))
  851. - :alt-or-ord (hide-tag (alt (nt :alt) (nt :ord)))
  852. - :alt (cat (nt :cat)
  853. - (star
  854. - (cat
  855. - opt-whitespace
  856. - (hide (string "|"))
  857. - opt-whitespace
  858. - (nt :cat))))
  859. - :ord (cat (nt :cat)
  860. - (plus
  861. - (cat
  862. - opt-whitespace
  863. - (hide (string "/"))
  864. - opt-whitespace
  865. - (nt :cat))))
  866. - :paren (cat (hide (string "("))
  867. - opt-whitespace
  868. - (nt :alt-or-ord)
  869. - opt-whitespace
  870. - (hide (string ")")))
  871. - :hide (cat (hide (string "<"))
  872. - opt-whitespace
  873. - (nt :alt-or-ord)
  874. - opt-whitespace
  875. - (hide (string ">")))
  876. - :cat (plus (cat
  877. - opt-whitespace
  878. - (alt (nt :factor) (nt :look) (nt :neg))
  879. - opt-whitespace))
  880. - :string (alt
  881. - (regexp single-quoted-string)
  882. - (regexp double-quoted-string))
  883. - :regexp (alt
  884. - (regexp single-quoted-regexp)
  885. - (regexp double-quoted-regexp))
  886. - :opt (alt
  887. - (cat (hide (string "["))
  888. - opt-whitespace
  889. - (nt :alt-or-ord)
  890. - opt-whitespace
  891. - (hide (string "]")))
  892. - (cat (nt :factor)
  893. - opt-whitespace
  894. - (hide (string "?"))))
  895. - :star (alt
  896. - (cat (hide (string "{"))
  897. - opt-whitespace
  898. - (nt :alt-or-ord)
  899. - opt-whitespace
  900. - (hide (string "}")))
  901. - (cat (nt :factor)
  902. - opt-whitespace
  903. - (hide (string "*"))))
  904. - :plus (cat (nt :factor)
  905. - opt-whitespace
  906. - (hide (string "+")))
  907. - :look (cat (hide (string "&"))
  908. - opt-whitespace
  909. - (nt :factor))
  910. - :neg (cat (hide (string "!"))
  911. - opt-whitespace
  912. - (nt :factor))
  913. - :epsilon (alt (string "Epsilon")
  914. - (string "epsilon")
  915. - (string "EPSILON")
  916. - (string "eps")
  917. - (string "\u03b5"))
  918. - :factor (hide-tag (alt (nt :nt)
  919. - (nt :string)
  920. - (nt :regexp)
  921. - (nt :opt)
  922. - (nt :star)
  923. - (nt :plus)
  924. - (nt :paren)
  925. - (nt :hide)
  926. - (nt :epsilon)))
  927. + :hide-nt (cat (hide (string "<"))
  928. + opt-whitespace
  929. + (nt :nt)
  930. + opt-whitespace
  931. + (hide (string ">")))
  932. + :alt-or-ord (hide-tag (alt (nt :alt) (nt :ord)))
  933. + :alt (cat (nt :cat)
  934. + (star
  935. + (cat
  936. + opt-whitespace
  937. + (hide (string "|"))
  938. + opt-whitespace
  939. + (nt :cat))))
  940. + :ord (cat (nt :cat)
  941. + (plus
  942. + (cat
  943. + opt-whitespace
  944. + (hide (string "/"))
  945. + opt-whitespace
  946. + (nt :cat))))
  947. + :paren (cat (hide (string "("))
  948. + opt-whitespace
  949. + (nt :alt-or-ord)
  950. + opt-whitespace
  951. + (hide (string ")")))
  952. + :hide (cat (hide (string "<"))
  953. + opt-whitespace
  954. + (nt :alt-or-ord)
  955. + opt-whitespace
  956. + (hide (string ">")))
  957. + :cat (plus (cat
  958. + opt-whitespace
  959. + (alt (nt :factor) (nt :look) (nt :neg))
  960. + opt-whitespace))
  961. + :string (alt
  962. + (regexp single-quoted-string)
  963. + (regexp double-quoted-string))
  964. + :regexp (alt
  965. + (regexp single-quoted-regexp)
  966. + (regexp double-quoted-regexp))
  967. + :opt (alt
  968. + (cat (hide (string "["))
  969. + opt-whitespace
  970. + (nt :alt-or-ord)
  971. + opt-whitespace
  972. + (hide (string "]")))
  973. + (cat (nt :factor)
  974. + opt-whitespace
  975. + (hide (string "?"))))
  976. + :star (alt
  977. + (cat (hide (string "{"))
  978. + opt-whitespace
  979. + (nt :alt-or-ord)
  980. + opt-whitespace
  981. + (hide (string "}")))
  982. + (cat (nt :factor)
  983. + opt-whitespace
  984. + (hide (string "*"))))
  985. + :plus (cat (nt :factor)
  986. + opt-whitespace
  987. + (hide (string "+")))
  988. + :look (cat (hide (string "&"))
  989. + opt-whitespace
  990. + (nt :factor))
  991. + :neg (cat (hide (string "!"))
  992. + opt-whitespace
  993. + (nt :factor))
  994. + :epsilon (alt (string "Epsilon")
  995. + (string "epsilon")
  996. + (string "EPSILON")
  997. + (string "eps")
  998. + (string "\u03b5"))
  999. + :factor (hide-tag (alt (nt :nt)
  1000. + (nt :string)
  1001. + (nt :regexp)
  1002. + (nt :opt)
  1003. + (nt :star)
  1004. + (nt :plus)
  1005. + (nt :paren)
  1006. + (nt :hide)
  1007. + (nt :epsilon)))
  1008. ;; extra entrypoint to be used by the ebnf combinator
  1009. :rules-or-parser (hide-tag (alt (nt :rules) (nt :alt-or-ord)))}))
  1010.  
  1011. @@ -238,7 +238,7 @@
  1012. (escape stripped)
  1013. final-string
  1014. (re-pattern remove-escaped-single-quotes)]
  1015. -; (safe-read-regexp (str remove-escaped-single-quotes \"))]
  1016. + ; (safe-read-regexp (str remove-escaped-single-quotes \"))]
  1017.  
  1018. final-string))
  1019.  
  1020. diff --git a/src/instaparse/combinators.cljc b/src/instaparse/combinators.cljc
  1021. index 964b6fd..52275fa 100644
  1022. --- a/src/instaparse/combinators.cljc
  1023. +++ b/src/instaparse/combinators.cljc
  1024. @@ -5,8 +5,8 @@
  1025. :cljs (:require-macros
  1026. [instaparse.macros :refer [defclone]]))
  1027. (:require [instaparse.combinators-source :as c]
  1028. - [instaparse.cfg :as cfg]
  1029. - [instaparse.abnf :as abnf]))
  1030. + [instaparse.cfg :as cfg]
  1031. + [instaparse.abnf :as abnf]))
  1032.  
  1033. ;; The actual source is in combinators-source.
  1034. ;; This was necessary to avoid a cyclical dependency in the namespaces.
  1035. diff --git a/src/instaparse/combinators_source.cljc b/src/instaparse/combinators_source.cljc
  1036. index 974f50a..3c08adc 100644
  1037. --- a/src/instaparse/combinators_source.cljc
  1038. +++ b/src/instaparse/combinators_source.cljc
  1039. @@ -4,7 +4,7 @@
  1040. (:require [instaparse.reduction :refer [singleton? red
  1041. raw-non-terminal-reduction
  1042. reduction-types]]
  1043. - [instaparse.util :refer [throw-illegal-argument-exception #?(:cljs regexp-flags)]]))
  1044. + [instaparse.util :refer [throw-illegal-argument-exception #?(:cljs regexp-flags)]]))
  1045.  
  1046. ;; Ways to build parsers
  1047.  
  1048. @@ -44,12 +44,12 @@
  1049. (defn ord "Ordered choice, i.e., parser1 / parser2"
  1050. ([] Epsilon)
  1051. ([parser1 & parsers]
  1052. - (let [parsers (if (= parser1 Epsilon)
  1053. - (remove #{Epsilon} parsers)
  1054. - parsers)]
  1055. - (if (seq parsers)
  1056. - (ord2 parser1 (apply ord parsers))
  1057. - parser1))))
  1058. + (let [parsers (if (= parser1 Epsilon)
  1059. + (remove #{Epsilon} parsers)
  1060. + parsers)]
  1061. + (if (seq parsers)
  1062. + (ord2 parser1 (apply ord parsers))
  1063. + parser1))))
  1064.  
  1065. (defn cat "Concatenation, i.e., parser1 parser2 ..."
  1066. [& parsers]
  1067. diff --git a/src/instaparse/core.cljc b/src/instaparse/core.cljc
  1068. index b88f951..657b574 100644
  1069. --- a/src/instaparse/core.cljc
  1070. +++ b/src/instaparse/core.cljc
  1071. @@ -1,20 +1,20 @@
  1072. (ns instaparse.core
  1073. (#?(:clj :require :cljs :require-macros)
  1074. - [instaparse.macros :refer [defclone
  1075. - set-global-var!]])
  1076. + [instaparse.macros :refer [defclone
  1077. + set-global-var!]])
  1078. (:require [clojure.walk :as walk]
  1079. - [instaparse.gll :as gll]
  1080. - [instaparse.cfg :as cfg]
  1081. - [instaparse.failure :as fail]
  1082. - [instaparse.print :as print]
  1083. - [instaparse.reduction :as red]
  1084. - [instaparse.transform :as t]
  1085. - [instaparse.abnf :as abnf]
  1086. - [instaparse.repeat :as repeat]
  1087. - [instaparse.combinators-source :as c]
  1088. - [instaparse.line-col :as lc]
  1089. - [instaparse.viz :as viz]
  1090. - [instaparse.util :refer [throw-illegal-argument-exception]]))
  1091. + [instaparse.gll :as gll]
  1092. + [instaparse.cfg :as cfg]
  1093. + [instaparse.failure :as fail]
  1094. + [instaparse.print :as print]
  1095. + [instaparse.reduction :as red]
  1096. + [instaparse.transform :as t]
  1097. + [instaparse.abnf :as abnf]
  1098. + [instaparse.repeat :as repeat]
  1099. + [instaparse.combinators-source :as c]
  1100. + [instaparse.line-col :as lc]
  1101. + [instaparse.viz :as viz]
  1102. + [instaparse.util :refer [throw-illegal-argument-exception]]))
  1103.  
  1104. (def ^:dynamic *default-output-format* :hiccup)
  1105. (defn set-default-output-format!
  1106. @@ -136,27 +136,27 @@
  1107. #?(:clj (gll/bind-trace trace?)))))
  1108.  
  1109. (defrecord Parser [grammar start-production output-format]
  1110. -#?@(:clj
  1111. - [clojure.lang.IFn
  1112. - (invoke [parser text] (parse parser text))
  1113. - (invoke [parser text key1 val1] (parse parser text key1 val1))
  1114. - (invoke [parser text key1 val1 key2 val2] (parse parser text key1 val1 key2 val2))
  1115. - (invoke [parser text key1 val1 key2 val2 key3 val3] (parse parser text key1 val1 key2 val2 key3 val3))
  1116. - (applyTo [parser args] (apply parse parser args))]
  1117. -
  1118. - :cljs
  1119. - [IFn
  1120. - (-invoke [parser text] (parse parser text))
  1121. - (-invoke [parser text key1 val1] (parse parser text key1 val1))
  1122. - (-invoke [parser text key1 val1 key2 val2] (parse parser text key1 val1 key2 val2))
  1123. - (-invoke [parser text key1 val1 key2 val2 key3 val3] (parse parser text key1 val1 key2 val2 key3 val3))
  1124. - (-invoke [parser text a b c d e f g h] (parse parser text a b c d e f g h))
  1125. - (-invoke [parser text a b c d e f g h i j] (parse parser text a b c d e f g h i j))
  1126. - (-invoke [parser text a b c d e f g h i j k l] (parse parser text a b c d e f g h i j k l))
  1127. - (-invoke [parser text a b c d e f g h i j k l m n] (parse parser text a b c d e f g h i j k l m n))
  1128. - (-invoke [parser text a b c d e f g h i j k l m n o p] (parse parser text a b c d e f g h i j k l m n o p))
  1129. - (-invoke [parser text a b c d e f g h i j k l m n o p q r] (parse parser text a b c d e f g h i j k l m n o p))
  1130. - (-invoke [parser text a b c d e f g h i j k l m n o p q r s more] (apply parse parser text a b c d e f g h i j k l m n o p q r s more))]))
  1131. + #?@(:clj
  1132. + [clojure.lang.IFn
  1133. + (invoke [parser text] (parse parser text))
  1134. + (invoke [parser text key1 val1] (parse parser text key1 val1))
  1135. + (invoke [parser text key1 val1 key2 val2] (parse parser text key1 val1 key2 val2))
  1136. + (invoke [parser text key1 val1 key2 val2 key3 val3] (parse parser text key1 val1 key2 val2 key3 val3))
  1137. + (applyTo [parser args] (apply parse parser args))]
  1138. +
  1139. + :cljs
  1140. + [IFn
  1141. + (-invoke [parser text] (parse parser text))
  1142. + (-invoke [parser text key1 val1] (parse parser text key1 val1))
  1143. + (-invoke [parser text key1 val1 key2 val2] (parse parser text key1 val1 key2 val2))
  1144. + (-invoke [parser text key1 val1 key2 val2 key3 val3] (parse parser text key1 val1 key2 val2 key3 val3))
  1145. + (-invoke [parser text a b c d e f g h] (parse parser text a b c d e f g h))
  1146. + (-invoke [parser text a b c d e f g h i j] (parse parser text a b c d e f g h i j))
  1147. + (-invoke [parser text a b c d e f g h i j k l] (parse parser text a b c d e f g h i j k l))
  1148. + (-invoke [parser text a b c d e f g h i j k l m n] (parse parser text a b c d e f g h i j k l m n))
  1149. + (-invoke [parser text a b c d e f g h i j k l m n o p] (parse parser text a b c d e f g h i j k l m n o p))
  1150. + (-invoke [parser text a b c d e f g h i j k l m n o p q r] (parse parser text a b c d e f g h i j k l m n o p))
  1151. + (-invoke [parser text a b c d e f g h i j k l m n o p q r s more] (apply parse parser text a b c d e f g h i j k l m n o p q r s more))]))
  1152.  
  1153. #?(:clj
  1154. (defmethod clojure.core/print-method Parser [x writer]
  1155. @@ -256,8 +256,8 @@
  1156. (map->Parser parser))
  1157. :cljs
  1158. (throw-illegal-argument-exception
  1159. - "Expected string, map, or vector as grammar specification, got "
  1160. - (pr-str grammar-specification))))]
  1161. + "Expected string, map, or vector as grammar specification, got "
  1162. + (pr-str grammar-specification))))]
  1163.  
  1164. (let [auto-whitespace (get options :auto-whitespace)
  1165. ; auto-whitespace is keyword, parser, or nil
  1166. @@ -293,36 +293,36 @@
  1167. (if (string? grammar)
  1168. `(def ~name
  1169. (map->Parser
  1170. - ~(binding [abnf/*case-insensitive* (:instaparse.abnf/case-insensitive opts false)]
  1171. - (let [macro-time-opts (select-keys opts [:input-format
  1172. - :output-format
  1173. - :string-ci
  1174. - :no-slurp])
  1175. - runtime-opts (dissoc opts :start)
  1176. - macro-time-parser (apply parser grammar (apply concat macro-time-opts))
  1177. - pre-processed-grammar (:grammar macro-time-parser)
  1178. -
  1179. - grammar-producing-code
  1180. - (->> pre-processed-grammar
  1181. - (walk/postwalk
  1182. - (fn [form]
  1183. - (cond
  1184. - ;; Lists cannot be evaluated verbatim
  1185. - (seq? form)
  1186. - (list* 'list form)
  1187. -
  1188. - ;; Regexp terminals are handled differently in cljs
  1189. - (= :regexp (:tag form))
  1190. - `(merge (c/regexp ~(str (:regexp form)))
  1191. - ~(dissoc form :tag :regexp))
  1192. -
  1193. - :else form))))
  1194. -
  1195. - start-production
  1196. - (or (:start opts) (:start-production macro-time-parser))]
  1197. - `(parser ~grammar-producing-code
  1198. - :start ~start-production
  1199. - ~@(apply concat runtime-opts))))))
  1200. + ~(binding [abnf/*case-insensitive* (:instaparse.abnf/case-insensitive opts false)]
  1201. + (let [macro-time-opts (select-keys opts [:input-format
  1202. + :output-format
  1203. + :string-ci
  1204. + :no-slurp])
  1205. + runtime-opts (dissoc opts :start)
  1206. + macro-time-parser (apply parser grammar (apply concat macro-time-opts))
  1207. + pre-processed-grammar (:grammar macro-time-parser)
  1208. +
  1209. + grammar-producing-code
  1210. + (->> pre-processed-grammar
  1211. + (walk/postwalk
  1212. + (fn [form]
  1213. + (cond
  1214. + ;; Lists cannot be evaluated verbatim
  1215. + (seq? form)
  1216. + (list* 'list form)
  1217. +
  1218. + ;; Regexp terminals are handled differently in cljs
  1219. + (= :regexp (:tag form))
  1220. + `(merge (c/regexp ~(str (:regexp form)))
  1221. + ~(dissoc form :tag :regexp))
  1222. +
  1223. + :else form))))
  1224. +
  1225. + start-production
  1226. + (or (:start opts) (:start-production macro-time-parser))]
  1227. + `(parser ~grammar-producing-code
  1228. + :start ~start-production
  1229. + ~@(apply concat runtime-opts))))))
  1230. `(def ~name (parser ~grammar ~@(apply concat opts))))))
  1231.  
  1232. (defn failure?
  1233. diff --git a/src/instaparse/gll.cljc b/src/instaparse/gll.cljc
  1234. index 0290128..de9675c 100644
  1235. --- a/src/instaparse/gll.cljc
  1236. +++ b/src/instaparse/gll.cljc
  1237. @@ -5,37 +5,37 @@
  1238. listeners and parse commands that are on the stack."
  1239.  
  1240. (:require
  1241. - ;; Incremental vector provides a more performant hashing strategy
  1242. - ;; for this use-case for vectors
  1243. - ;; We use the auto flatten version
  1244. - [instaparse.auto-flatten-seq :as afs]
  1245. + ;; Incremental vector provides a more performant hashing strategy
  1246. + ;; for this use-case for vectors
  1247. + ;; We use the auto flatten version
  1248. + [instaparse.auto-flatten-seq :as afs]
  1249.  
  1250. - ;; failure contains the augment-failure function, which is called to
  1251. - ;; add enough information to the failure object for pretty printing
  1252. - [instaparse.failure :as fail]
  1253. + ;; failure contains the augment-failure function, which is called to
  1254. + ;; add enough information to the failure object for pretty printing
  1255. + [instaparse.failure :as fail]
  1256.  
  1257. - ;; reduction contains code relating to reductions and flattening.
  1258. - [instaparse.reduction :as red]
  1259. + ;; reduction contains code relating to reductions and flattening.
  1260. + [instaparse.reduction :as red]
  1261.  
  1262. - ;; Two of the public combinators are needed.
  1263. - [instaparse.combinators-source :refer [Epsilon nt]]
  1264. + ;; Two of the public combinators are needed.
  1265. + [instaparse.combinators-source :refer [Epsilon nt]]
  1266.  
  1267. - ;; Need a way to convert parsers into strings for printing and error messages.
  1268. - [instaparse.print :as print]
  1269. + ;; Need a way to convert parsers into strings for printing and error messages.
  1270. + [instaparse.print :as print]
  1271.  
  1272. - ;; Utility to preserve RegExp flags
  1273. - #?(:cljs
  1274. - [instaparse.util :refer [regexp-flags]])
  1275. + ;; Utility to preserve RegExp flags
  1276. + #?(:cljs
  1277. + [instaparse.util :refer [regexp-flags]])
  1278.  
  1279. - ;; Unicode utilities for char-range
  1280. - #?(:cljs
  1281. - [goog.i18n.uChar :as u]))
  1282. + ;; Unicode utilities for char-range
  1283. + #?(:cljs
  1284. + [goog.i18n.uChar :as u]))
  1285.  
  1286. #?(:cljs
  1287. (:use-macros
  1288. - [instaparse.gll :only
  1289. - [log profile dprintln dpprint success
  1290. - attach-diagnostic-meta trace-or-false]])))
  1291. + [instaparse.gll :only
  1292. + [log profile dprintln dpprint success
  1293. + attach-diagnostic-meta trace-or-false]])))
  1294.  
  1295. ;; As of Java 7, strings no longer have fast substring operation,
  1296. ;; so we use Segments instead, which implement the CharSequence
  1297. @@ -62,48 +62,48 @@
  1298. ;;;;; SETUP DIAGNOSTIC MACROS AND VARS
  1299. #?(:clj (do
  1300.  
  1301. -(defonce PRINT false)
  1302. -(defmacro dprintln [& body]
  1303. - (when PRINT `(println ~@body)))
  1304. -(defmacro dpprint [& body]
  1305. - (when PRINT `(clojure.pprint/pprint ~@body)))
  1306. -
  1307. -(defonce PROFILE false)
  1308. -(defmacro profile [& body]
  1309. - (when PROFILE
  1310. - `(do ~@body)))
  1311. -
  1312. -;; By default TRACE is set to false, and all these macros are used
  1313. -;; throughout the code to ensure there is absolutely no performance
  1314. -;; penalty from the tracing code. Everything related to tracing
  1315. -;; is compiled away.
  1316. -;;
  1317. -;; We recompile this file with TRACE set to true to activate the
  1318. -;; tracing code.
  1319. -;;
  1320. -;; bind-trace is the one exception where we can't completely compile
  1321. -;; the new code away, because it is used in instaparse.core, which won't be
  1322. -;; recompiled. Still, binding is a relatively slow operation, so by testing
  1323. -;; whether TRACE is true inside the expansion, we can at least avoid
  1324. -;; the performance hit of binding every time.
  1325. -
  1326. -(defonce TRACE false)
  1327. -(def ^:dynamic *trace* false)
  1328. -(defmacro log [tramp & body]
  1329. - (when TRACE
  1330. - `(when (:trace? ~tramp) (println ~@body))))
  1331. -(defmacro attach-diagnostic-meta [f metadata]
  1332. - (if TRACE
  1333. - `(with-meta ~f ~metadata)
  1334. - f))
  1335. -(defmacro bind-trace [trace? body]
  1336. - `(if TRACE
  1337. - (binding [*trace* ~trace?] ~body)
  1338. - ~body))
  1339. -(defmacro trace-or-false []
  1340. - (if TRACE '*trace* false))
  1341. -
  1342. -))
  1343. + (defonce PRINT false)
  1344. + (defmacro dprintln [& body]
  1345. + (when PRINT `(println ~@body)))
  1346. + (defmacro dpprint [& body]
  1347. + (when PRINT `(clojure.pprint/pprint ~@body)))
  1348. +
  1349. + (defonce PROFILE false)
  1350. + (defmacro profile [& body]
  1351. + (when PROFILE
  1352. + `(do ~@body)))
  1353. +
  1354. + ;; By default TRACE is set to false, and all these macros are used
  1355. + ;; throughout the code to ensure there is absolutely no performance
  1356. + ;; penalty from the tracing code. Everything related to tracing
  1357. + ;; is compiled away.
  1358. + ;;
  1359. + ;; We recompile this file with TRACE set to true to activate the
  1360. + ;; tracing code.
  1361. + ;;
  1362. + ;; bind-trace is the one exception where we can't completely compile
  1363. + ;; the new code away, because it is used in instaparse.core, which won't be
  1364. + ;; recompiled. Still, binding is a relatively slow operation, so by testing
  1365. + ;; whether TRACE is true inside the expansion, we can at least avoid
  1366. + ;; the performance hit of binding every time.
  1367. +
  1368. + (defonce TRACE false)
  1369. + (def ^:dynamic *trace* false)
  1370. + (defmacro log [tramp & body]
  1371. + (when TRACE
  1372. + `(when (:trace? ~tramp) (println ~@body))))
  1373. + (defmacro attach-diagnostic-meta [f metadata]
  1374. + (if TRACE
  1375. + `(with-meta ~f ~metadata)
  1376. + f))
  1377. + (defmacro bind-trace [trace? body]
  1378. + `(if TRACE
  1379. + (binding [*trace* ~trace?] ~body)
  1380. + ~body))
  1381. + (defmacro trace-or-false []
  1382. + (if TRACE '*trace* false))
  1383. +
  1384. + ))
  1385.  
  1386. ; In diagnostic messages, how many characters ahead do we want to show.
  1387. (def ^:dynamic *diagnostic-char-lookahead* 10)
  1388. @@ -235,10 +235,10 @@
  1389. ([grammar text segment] (make-tramp grammar text segment -1 nil))
  1390. ([grammar text fail-index node-builder] (make-tramp grammar text (text->segment text) fail-index node-builder))
  1391. ([grammar text segment fail-index node-builder]
  1392. - (Tramp. grammar text segment
  1393. - fail-index node-builder
  1394. - (atom []) (atom []) (atom 0) (atom (sorted-map-by >))
  1395. - (atom {}) (atom {}) (atom nil) (atom (Failure. 0 [])) (trace-or-false))))
  1396. + (Tramp. grammar text segment
  1397. + fail-index node-builder
  1398. + (atom []) (atom []) (atom 0) (atom (sorted-map-by >))
  1399. + (atom {}) (atom {}) (atom nil) (atom (Failure. 0 [])) (trace-or-false))))
  1400.  
  1401. ; A Success record contains the result and the index to continue from
  1402. (defn make-success [result index] {:result result :index index})
  1403. @@ -276,7 +276,7 @@
  1404. f #(listener result)]
  1405. (profile (add! :push-message))
  1406. #_(dprintln "push-message" i c @(:generation tramp) (count @(:stack tramp))
  1407. - (count @(:next-stack tramp)))
  1408. + (count @(:next-stack tramp)))
  1409. #_(dprintln "push-message: listener result" listener result)
  1410. (if (> c @(:generation tramp))
  1411. (swap! (:next-stack tramp) conj f)
  1412. @@ -452,46 +452,46 @@
  1413. "Executes the stack until exhausted"
  1414. ([tramp] (run tramp nil))
  1415. ([tramp found-result?]
  1416. - (let [stack (:stack tramp)]
  1417. - ;_ (dprintln "run" found-result? (count @(:stack tramp)) (count @(:next-stack tramp)))]
  1418. - (cond
  1419. - @(:success tramp)
  1420. - (do (log tramp "Successful parse.\nProfile: " @stats)
  1421. - (cons (:result @(:success tramp))
  1422. - (lazy-seq
  1423. - (do (reset! (:success tramp) nil)
  1424. - (run tramp true)))))
  1425. + (let [stack (:stack tramp)]
  1426. + ;_ (dprintln "run" found-result? (count @(:stack tramp)) (count @(:next-stack tramp)))]
  1427. + (cond
  1428. + @(:success tramp)
  1429. + (do (log tramp "Successful parse.\nProfile: " @stats)
  1430. + (cons (:result @(:success tramp))
  1431. + (lazy-seq
  1432. + (do (reset! (:success tramp) nil)
  1433. + (run tramp true)))))
  1434.  
  1435. - (pos? (count @stack))
  1436. - (do ;(dprintln "stacks" (count @stack) (count @(:next-stack tramp)))
  1437. - (step stack) (recur tramp found-result?))
  1438. -
  1439. - (pos? (count @(:negative-listeners tramp)))
  1440. - (let [[index listeners] (first @(:negative-listeners tramp))
  1441. - listener (peek listeners)]
  1442. - (log tramp (format "Exhausted results for %s at index %d (%s)"
  1443. - (print/combinators->str (((meta listener) :creator) 1))
  1444. - (((meta listener) :creator) 0)
  1445. - (string-context (:text tramp)
  1446. - (((meta listener) :creator) 0))))
  1447. - (listener)
  1448. - (if (= (count listeners) 1)
  1449. - (swap! (:negative-listeners tramp) dissoc index)
  1450. - (swap! (:negative-listeners tramp) update-in [index] pop))
  1451. - (recur tramp found-result?))
  1452. + (pos? (count @stack))
  1453. + (do ;(dprintln "stacks" (count @stack) (count @(:next-stack tramp)))
  1454. + (step stack) (recur tramp found-result?))
  1455. +
  1456. + (pos? (count @(:negative-listeners tramp)))
  1457. + (let [[index listeners] (first @(:negative-listeners tramp))
  1458. + listener (peek listeners)]
  1459. + (log tramp (format "Exhausted results for %s at index %d (%s)"
  1460. + (print/combinators->str (((meta listener) :creator) 1))
  1461. + (((meta listener) :creator) 0)
  1462. + (string-context (:text tramp)
  1463. + (((meta listener) :creator) 0))))
  1464. + (listener)
  1465. + (if (= (count listeners) 1)
  1466. + (swap! (:negative-listeners tramp) dissoc index)
  1467. + (swap! (:negative-listeners tramp) update-in [index] pop))
  1468. + (recur tramp found-result?))
  1469.  
  1470. - found-result?
  1471. - (let [next-stack (:next-stack tramp)]
  1472. - #_(dprintln "Swapping stacks" (count @(:stack tramp))
  1473. - (count @(:next-stack tramp)))
  1474. - (reset! stack @next-stack)
  1475. - (reset! next-stack [])
  1476. - (swap! (:generation tramp) inc)
  1477. - #_(dprintln "Swapped stacks" (count @(:stack tramp))
  1478. - (count @(:next-stack tramp)))
  1479. - (recur tramp nil))
  1480. + found-result?
  1481. + (let [next-stack (:next-stack tramp)]
  1482. + #_(dprintln "Swapping stacks" (count @(:stack tramp))
  1483. + (count @(:next-stack tramp)))
  1484. + (reset! stack @next-stack)
  1485. + (reset! next-stack [])
  1486. + (swap! (:generation tramp) inc)
  1487. + #_(dprintln "Swapped stacks" (count @(:stack tramp))
  1488. + (count @(:next-stack tramp)))
  1489. + (recur tramp nil))
  1490.  
  1491. - :else nil))))
  1492. + :else nil))))
  1493.  
  1494. ;; Listeners
  1495.  
  1496. @@ -517,9 +517,9 @@
  1497.  
  1498. (defn CatListener [results-so-far parser-sequence node-key tramp]
  1499. (dpprint {:tag :CatListener
  1500. - :results-so-far results-so-far
  1501. - :parser-sequence (map :tag parser-sequence)
  1502. - :node-key [(node-key 0) (:tag (node-key 1))]})
  1503. + :results-so-far results-so-far
  1504. + :parser-sequence (map :tag parser-sequence)
  1505. + :node-key [(node-key 0) (:tag (node-key 1))]})
  1506. (fn [result]
  1507. (let [{parsed-result :result continue-index :index} result
  1508. new-results-so-far (afs/conj-flat results-so-far parsed-result)]
  1509. @@ -529,10 +529,10 @@
  1510. (success tramp node-key new-results-so-far continue-index)))))
  1511.  
  1512. (defn CatFullListener [results-so-far parser-sequence node-key tramp]
  1513. -; (dpprint {:tag :CatFullListener
  1514. -; :results-so-far results-so-far
  1515. -; :parser-sequence (map :tag parser-sequence)
  1516. -; :node-key [(node-key 0) (:tag (node-key 1))]})
  1517. + ; (dpprint {:tag :CatFullListener
  1518. + ; :results-so-far results-so-far
  1519. + ; :parser-sequence (map :tag parser-sequence)
  1520. + ; :node-key [(node-key 0) (:tag (node-key 1))]})
  1521. (fn [result]
  1522. (let [{parsed-result :result continue-index :index} result
  1523. new-results-so-far (afs/conj-flat results-so-far parsed-result)]
  1524. diff --git a/src/instaparse/line_col.cljc b/src/instaparse/line_col.cljc
  1525. index 4bb29ab..b38cea7 100644
  1526. --- a/src/instaparse/line_col.cljc
  1527. +++ b/src/instaparse/line_col.cljc
  1528. @@ -1,6 +1,6 @@
  1529. (ns instaparse.line-col
  1530. (:require [instaparse.transform]
  1531. - [instaparse.util :refer [throw-illegal-argument-exception]]))
  1532. + [instaparse.util :refer [throw-illegal-argument-exception]]))
  1533.  
  1534. ; Function to annotate parse-tree with line and column metadata.
  1535.  
  1536. diff --git a/src/instaparse/print.cljc b/src/instaparse/print.cljc
  1537. index 4694026..baef8f2 100644
  1538. --- a/src/instaparse/print.cljc
  1539. +++ b/src/instaparse/print.cljc
  1540. @@ -54,30 +54,30 @@
  1541. "Stringifies a parser built from combinators"
  1542. ([p] (combinators->str p false))
  1543. ([{:keys [parser parser1 parser2 parsers tag] :as p} hidden?]
  1544. - (if (and (not hidden?) (:hide p))
  1545. - (str \< (combinators->str p true) \>)
  1546. - (case tag
  1547. - :epsilon "\u03b5"
  1548. - :opt (str (paren-for-compound hidden? parser) "?")
  1549. - :plus (str (paren-for-compound hidden? parser) "+")
  1550. - :star (str (paren-for-compound hidden? parser) "*")
  1551. - :rep (if (not= (:min p) (:max p))
  1552. - (str (paren-for-compound hidden? parser) \{
  1553. - (:min p) \, (:max p) \})
  1554. - (str (paren-for-compound hidden? parser) \{
  1555. - (:min p)\}))
  1556. - :alt (str/join " | " (map (partial paren-for-tags #{:ord} hidden?) parsers))
  1557. - :ord (str (paren-for-tags #{:alt} hidden? parser1)
  1558. - " / "
  1559. - (paren-for-tags #{:alt} hidden? parser2))
  1560. - :cat (str/join " " (map (partial paren-for-tags #{:alt :ord} hidden?) parsers))
  1561. - :string (with-out-str (pr (:string p)))
  1562. - :string-ci (with-out-str (pr (:string p)))
  1563. - :char (char-range->str p)
  1564. - :regexp (regexp->str (:regexp p))
  1565. - :nt (subs (str (:keyword p)) 1)
  1566. - :look (str "&" (paren-for-compound hidden? parser))
  1567. - :neg (str "!" (paren-for-compound hidden? parser))))))
  1568. + (if (and (not hidden?) (:hide p))
  1569. + (str \< (combinators->str p true) \>)
  1570. + (case tag
  1571. + :epsilon "\u03b5"
  1572. + :opt (str (paren-for-compound hidden? parser) "?")
  1573. + :plus (str (paren-for-compound hidden? parser) "+")
  1574. + :star (str (paren-for-compound hidden? parser) "*")
  1575. + :rep (if (not= (:min p) (:max p))
  1576. + (str (paren-for-compound hidden? parser) \{
  1577. + (:min p) \, (:max p) \})
  1578. + (str (paren-for-compound hidden? parser) \{
  1579. + (:min p)\}))
  1580. + :alt (str/join " | " (map (partial paren-for-tags #{:ord} hidden?) parsers))
  1581. + :ord (str (paren-for-tags #{:alt} hidden? parser1)
  1582. + " / "
  1583. + (paren-for-tags #{:alt} hidden? parser2))
  1584. + :cat (str/join " " (map (partial paren-for-tags #{:alt :ord} hidden?) parsers))
  1585. + :string (with-out-str (pr (:string p)))
  1586. + :string-ci (with-out-str (pr (:string p)))
  1587. + :char (char-range->str p)
  1588. + :regexp (regexp->str (:regexp p))
  1589. + :nt (subs (str (:keyword p)) 1)
  1590. + :look (str "&" (paren-for-compound hidden? parser))
  1591. + :neg (str "!" (paren-for-compound hidden? parser))))))
  1592.  
  1593. (defn rule->str
  1594. "Takes a non-terminal symbol and a parser built from combinators,
  1595. diff --git a/src/instaparse/reduction.cljc b/src/instaparse/reduction.cljc
  1596. index 04637a5..248279e 100644
  1597. --- a/src/instaparse/reduction.cljc
  1598. +++ b/src/instaparse/reduction.cljc
  1599. @@ -1,6 +1,6 @@
  1600. (ns instaparse.reduction
  1601. (:require [instaparse.auto-flatten-seq :as afs]
  1602. - [instaparse.util :refer [throw-illegal-argument-exception]]))
  1603. + [instaparse.util :refer [throw-illegal-argument-exception]]))
  1604.  
  1605. ;; utilities
  1606.  
  1607. @@ -48,9 +48,9 @@
  1608. (defn apply-standard-reductions
  1609. ([grammar] (apply-standard-reductions standard-non-terminal-reduction grammar))
  1610. ([reduction-type grammar]
  1611. - (if-let [reduction (reduction-types reduction-type)]
  1612. - (into {} (for [[k v] grammar]
  1613. - (if (:red v) [k v]
  1614. - [k (assoc v :red (reduction k))])))
  1615. - (throw-illegal-argument-exception
  1616. - "Invalid output format " reduction-type ". Use :enlive or :hiccup."))))
  1617. + (if-let [reduction (reduction-types reduction-type)]
  1618. + (into {} (for [[k v] grammar]
  1619. + (if (:red v) [k v]
  1620. + [k (assoc v :red (reduction k))])))
  1621. + (throw-illegal-argument-exception
  1622. + "Invalid output format " reduction-type ". Use :enlive or :hiccup."))))
  1623. diff --git a/src/instaparse/repeat.cljc b/src/instaparse/repeat.cljc
  1624. index b035201..8d98fc0 100644
  1625. --- a/src/instaparse/repeat.cljc
  1626. +++ b/src/instaparse/repeat.cljc
  1627. @@ -1,11 +1,11 @@
  1628. (ns instaparse.repeat
  1629. (:require [instaparse.gll :as gll
  1630. #?@(:clj [:refer [profile]])]
  1631. - [instaparse.combinators-source :as c]
  1632. - [instaparse.auto-flatten-seq :as afs]
  1633. - [instaparse.viz :as viz]
  1634. - [instaparse.reduction :as red]
  1635. - [instaparse.failure :as fail])
  1636. + [instaparse.combinators-source :as c]
  1637. + [instaparse.auto-flatten-seq :as afs]
  1638. + [instaparse.viz :as viz]
  1639. + [instaparse.reduction :as red]
  1640. + [instaparse.failure :as fail])
  1641. #?(:cljs
  1642. (:require-macros [instaparse.gll :refer [profile]])))
  1643.  
  1644. @@ -19,12 +19,12 @@
  1645. (defn get-end
  1646. (#?(:clj ^long [parse]
  1647. :cljs ^number [parse])
  1648. - (let [[start end] (viz/span parse)]
  1649. - (if end (long end) (count parse))))
  1650. + (let [[start end] (viz/span parse)]
  1651. + (if end (long end) (count parse))))
  1652. (#?(:clj ^long [parse ^long index]
  1653. :cljs ^number [parse ^number index])
  1654. - (let [[start end] (viz/span parse)]
  1655. - (if end (long end) (+ index (count parse))))))
  1656. + (let [[start end] (viz/span parse)]
  1657. + (if end (long end) (+ index (count parse))))))
  1658.  
  1659. (defn parse-from-index [grammar initial-parser text segment index]
  1660. (let [tramp (gll/make-tramp grammar text segment)]
  1661. @@ -53,120 +53,120 @@
  1662.  
  1663. (defn repeat-parse-hiccup
  1664. ([grammar initial-parser root-tag text segment]
  1665. - (repeat-parse-hiccup grammar initial-parser root-tag text segment 0))
  1666. + (repeat-parse-hiccup grammar initial-parser root-tag text segment 0))
  1667. ([grammar initial-parser root-tag text segment index]
  1668. - (let [length (count text)
  1669. - first-result (parse-from-index grammar initial-parser text segment index)]
  1670. - (loop [index (long index)
  1671. - parses (afs/auto-flatten-seq [root-tag])
  1672. + (let [length (count text)
  1673. + first-result (parse-from-index grammar initial-parser text segment index)]
  1674. + (loop [index (long index)
  1675. + parses (afs/auto-flatten-seq [root-tag])
  1676.  
  1677. - [parse end follow-ups :as selection]
  1678. - (select-parse grammar initial-parser text segment index first-result)]
  1679. - (cond
  1680. - (nil? selection) failure-signal
  1681. - (= index end) failure-signal
  1682. - (nil? follow-ups) (gll/safe-with-meta
  1683. - (afs/convert-afs-to-vec
  1684. - (afs/conj-flat parses parse))
  1685. - {:optimize :memory
  1686. - :instaparse.gll/start-index 0
  1687. - :instaparse.gll/end-index length})
  1688. - :else (recur (long end)
  1689. - (afs/conj-flat parses parse)
  1690. - (select-parse grammar initial-parser text segment end follow-ups)))))))
  1691. + [parse end follow-ups :as selection]
  1692. + (select-parse grammar initial-parser text segment index first-result)]
  1693. + (cond
  1694. + (nil? selection) failure-signal
  1695. + (= index end) failure-signal
  1696. + (nil? follow-ups) (gll/safe-with-meta
  1697. + (afs/convert-afs-to-vec
  1698. + (afs/conj-flat parses parse))
  1699. + {:optimize :memory
  1700. + :instaparse.gll/start-index 0
  1701. + :instaparse.gll/end-index length})
  1702. + :else (recur (long end)
  1703. + (afs/conj-flat parses parse)
  1704. + (select-parse grammar initial-parser text segment end follow-ups)))))))
  1705.  
  1706. (defn repeat-parse-enlive
  1707. ([grammar initial-parser root-tag text segment]
  1708. - (repeat-parse-enlive grammar initial-parser root-tag text segment 0))
  1709. + (repeat-parse-enlive grammar initial-parser root-tag text segment 0))
  1710. ([grammar initial-parser root-tag text segment index]
  1711. - (let [length (count text)
  1712. - first-result (parse-from-index grammar initial-parser text segment index)]
  1713. - (loop [index (long index)
  1714. - parses afs/EMPTY
  1715. + (let [length (count text)
  1716. + first-result (parse-from-index grammar initial-parser text segment index)]
  1717. + (loop [index (long index)
  1718. + parses afs/EMPTY
  1719.  
  1720. - [parse end follow-ups :as selection]
  1721. - (select-parse grammar initial-parser text segment index first-result)]
  1722. - (cond
  1723. - (nil? selection) failure-signal
  1724. - (= index end) failure-signal
  1725. - (nil? follow-ups) (gll/safe-with-meta
  1726. - {:tag root-tag
  1727. - :content (seq (afs/conj-flat parses parse))}
  1728. - {:optimize :memory
  1729. - :instaparse.gll/start-index 0
  1730. - :instaparse.gll/end-index length})
  1731. - :else (recur (long end)
  1732. - (afs/conj-flat parses parse)
  1733. - (select-parse grammar initial-parser text segment end follow-ups)))))))
  1734. + [parse end follow-ups :as selection]
  1735. + (select-parse grammar initial-parser text segment index first-result)]
  1736. + (cond
  1737. + (nil? selection) failure-signal
  1738. + (= index end) failure-signal
  1739. + (nil? follow-ups) (gll/safe-with-meta
  1740. + {:tag root-tag
  1741. + :content (seq (afs/conj-flat parses parse))}
  1742. + {:optimize :memory
  1743. + :instaparse.gll/start-index 0
  1744. + :instaparse.gll/end-index length})
  1745. + :else (recur (long end)
  1746. + (afs/conj-flat parses parse)
  1747. + (select-parse grammar initial-parser text segment end follow-ups)))))))
  1748.  
  1749. (defn repeat-parse-no-tag
  1750. ([grammar initial-parser text segment]
  1751. - (repeat-parse-no-tag grammar initial-parser text segment 0))
  1752. + (repeat-parse-no-tag grammar initial-parser text segment 0))
  1753. ([grammar initial-parser text segment index]
  1754. - (let [length (count text)
  1755. - first-result (parse-from-index grammar initial-parser text segment index)]
  1756. - (loop [index (long index)
  1757. - parses afs/EMPTY
  1758. + (let [length (count text)
  1759. + first-result (parse-from-index grammar initial-parser text segment index)]
  1760. + (loop [index (long index)
  1761. + parses afs/EMPTY
  1762.  
  1763. - [parse end follow-ups :as selection]
  1764. - (select-parse grammar initial-parser text segment index first-result)]
  1765. - (cond
  1766. - (nil? selection) failure-signal
  1767. - (= index end) failure-signal
  1768. - (nil? follow-ups) (gll/safe-with-meta
  1769. - (afs/conj-flat parses parse)
  1770. - {:optimize :memory
  1771. - :instaparse.gll/start-index 0
  1772. - :instaparse.gll/end-index length})
  1773. - :else (recur (long end)
  1774. - (afs/conj-flat parses parse)
  1775. - (select-parse grammar initial-parser text segment end follow-ups)))))))
  1776. + [parse end follow-ups :as selection]
  1777. + (select-parse grammar initial-parser text segment index first-result)]
  1778. + (cond
  1779. + (nil? selection) failure-signal
  1780. + (= index end) failure-signal
  1781. + (nil? follow-ups) (gll/safe-with-meta
  1782. + (afs/conj-flat parses parse)
  1783. + {:optimize :memory
  1784. + :instaparse.gll/start-index 0
  1785. + :instaparse.gll/end-index length})
  1786. + :else (recur (long end)
  1787. + (afs/conj-flat parses parse)
  1788. + (select-parse grammar initial-parser text segment end follow-ups)))))))
  1789.  
  1790. (defn repeat-parse
  1791. ([grammar initial-parser output-format text] (repeat-parse-no-tag grammar initial-parser text (gll/text->segment text)))
  1792. ([grammar initial-parser output-format root-tag text]
  1793. - {:pre [(#{:hiccup :enlive} output-format)]}
  1794. - (cond
  1795. - (= output-format :hiccup)
  1796. - (repeat-parse-hiccup grammar initial-parser root-tag text (gll/text->segment text))
  1797. - (= output-format :enlive)
  1798. - (repeat-parse-enlive grammar initial-parser root-tag text (gll/text->segment text)))))
  1799. + {:pre [(#{:hiccup :enlive} output-format)]}
  1800. + (cond
  1801. + (= output-format :hiccup)
  1802. + (repeat-parse-hiccup grammar initial-parser root-tag text (gll/text->segment text))
  1803. + (= output-format :enlive)
  1804. + (repeat-parse-enlive grammar initial-parser root-tag text (gll/text->segment text)))))
  1805.  
  1806. (defn repeat-parse-with-header
  1807. ([grammar header-parser repeating-parser output-format root-tag text]
  1808. - (let [segment (gll/text->segment text)
  1809. - length (count text)
  1810. - header-results (parse-from-index grammar header-parser text segment 0)]
  1811. - (if (or (empty? header-results)
  1812. - (:hide header-parser))
  1813. - failure-signal
  1814. - (let [header-result (apply max-key get-end header-results)
  1815. - end (get-end header-result)
  1816. - repeat-result (repeat-parse-no-tag grammar (:parser repeating-parser) text segment end)
  1817. - span-meta {:optimize :memory
  1818. - :instaparse.gll/start-index 0
  1819. - :instaparse.gll/end-index length}]
  1820. - (if (or (instance? instaparse.gll.Failure repeat-result)
  1821. - (and (= (:tag repeating-parser) :star)
  1822. - (empty-result? repeat-result)))
  1823. - failure-signal
  1824. - (case output-format
  1825. - :enlive
  1826. - (gll/safe-with-meta
  1827. - {:tag root-tag
  1828. - :content
  1829. - (afs/conj-flat (afs/conj-flat afs/EMPTY header-result) repeat-result)}
  1830. - span-meta)
  1831. - :hiccup
  1832. - (gll/safe-with-meta
  1833. - (afs/convert-afs-to-vec
  1834. - (afs/conj-flat (afs/conj-flat (afs/auto-flatten-seq [root-tag])
  1835. - header-result)
  1836. - repeat-result))
  1837. - span-meta)
  1838. - (gll/safe-with-meta
  1839. - (afs/conj-flat (afs/conj-flat afs/EMPTY header-result) repeat-result)
  1840. - span-meta))))))))
  1841. + (let [segment (gll/text->segment text)
  1842. + length (count text)
  1843. + header-results (parse-from-index grammar header-parser text segment 0)]
  1844. + (if (or (empty? header-results)
  1845. + (:hide header-parser))
  1846. + failure-signal
  1847. + (let [header-result (apply max-key get-end header-results)
  1848. + end (get-end header-result)
  1849. + repeat-result (repeat-parse-no-tag grammar (:parser repeating-parser) text segment end)
  1850. + span-meta {:optimize :memory
  1851. + :instaparse.gll/start-index 0
  1852. + :instaparse.gll/end-index length}]
  1853. + (if (or (instance? instaparse.gll.Failure repeat-result)
  1854. + (and (= (:tag repeating-parser) :star)
  1855. + (empty-result? repeat-result)))
  1856. + failure-signal
  1857. + (case output-format
  1858. + :enlive
  1859. + (gll/safe-with-meta
  1860. + {:tag root-tag
  1861. + :content
  1862. + (afs/conj-flat (afs/conj-flat afs/EMPTY header-result) repeat-result)}
  1863. + span-meta)
  1864. + :hiccup
  1865. + (gll/safe-with-meta
  1866. + (afs/convert-afs-to-vec
  1867. + (afs/conj-flat (afs/conj-flat (afs/auto-flatten-seq [root-tag])
  1868. + header-result)
  1869. + repeat-result))
  1870. + span-meta)
  1871. + (gll/safe-with-meta
  1872. + (afs/conj-flat (afs/conj-flat afs/EMPTY header-result) repeat-result)
  1873. + span-meta))))))))
  1874.  
  1875. (defn try-repeating-parse-strategy-with-header
  1876. [grammar text start-production start-rule output-format]
  1877. @@ -213,7 +213,7 @@
  1878. result))
  1879.  
  1880. :else (try-repeating-parse-strategy-with-header
  1881. - grammar text start-production start-rule output-format))))
  1882. + grammar text start-production start-rule output-format))))
  1883.  
  1884. (defn used-memory-optimization? [tree]
  1885. (= :memory (-> tree meta :optimize)))
  1886. \ No newline at end of file
  1887. diff --git a/src/instaparse/transform.cljc b/src/instaparse/transform.cljc
  1888. index 2e08979..7b124a9 100644
  1889. --- a/src/instaparse/transform.cljc
  1890. +++ b/src/instaparse/transform.cljc
  1891. @@ -1,7 +1,7 @@
  1892. (ns instaparse.transform
  1893. "Functions to transform parse trees"
  1894. (:require [instaparse.gll]
  1895. - [instaparse.util :refer [throw-illegal-argument-exception]]))
  1896. + [instaparse.util :refer [throw-illegal-argument-exception]]))
  1897.  
  1898. (defn map-preserving-meta [f l]
  1899. (with-meta (map f l) (meta l)))
  1900. diff --git a/src/instaparse/util.cljc b/src/instaparse/util.cljc
  1901. index b0d1be8..af4a9e6 100644
  1902. --- a/src/instaparse/util.cljc
  1903. +++ b/src/instaparse/util.cljc
  1904. @@ -13,8 +13,8 @@
  1905. throw))
  1906.  
  1907. #?(:cljs
  1908. - (defn regexp-flags [re]
  1909. - (cond-> ""
  1910. - (.-ignoreCase re) (str "i")
  1911. - (.-multiline re) (str "m")
  1912. - (.-unicode re) (str "u"))))
  1913. + (defn regexp-flags [re]
  1914. + (cond-> ""
  1915. + (.-ignoreCase re) (str "i")
  1916. + (.-multiline re) (str "m")
  1917. + (.-unicode re) (str "u"))))
  1918. diff --git a/test/instaparse/abnf_test.cljc b/test/instaparse/abnf_test.cljc
  1919. index 87ee901..fe13024 100644
  1920. --- a/test/instaparse/abnf_test.cljc
  1921. +++ b/test/instaparse/abnf_test.cljc
  1922. @@ -1,14 +1,14 @@
  1923. (ns instaparse.abnf-test
  1924. (:require
  1925. - #?(:clj [instaparse.core :refer [parser parses defparser]]
  1926. - :cljs [instaparse.core :refer [parser parses] :refer-macros [defparser]])
  1927. - [instaparse.core-test :refer [parsers-similar?]]
  1928. - [instaparse.combinators :refer [ebnf abnf]]
  1929. - #?(:clj [clojure.test :refer [deftest are is]]
  1930. - :cljs [cljs.test])
  1931. - #?(:clj [clojure.java.io :as io]))
  1932. + #?(:clj [instaparse.core :refer [parser parses defparser]]
  1933. + :cljs [instaparse.core :refer [parser parses] :refer-macros [defparser]])
  1934. + [instaparse.core-test :refer [parsers-similar?]]
  1935. + [instaparse.combinators :refer [ebnf abnf]]
  1936. + #?(:clj [clojure.test :refer [deftest are is]]
  1937. + :cljs [cljs.test])
  1938. + #?(:clj [clojure.java.io :as io]))
  1939. #?(:cljs (:require-macros
  1940. - [cljs.test :refer [is are deftest]])))
  1941. + [cljs.test :refer [is are deftest]])))
  1942.  
  1943. (defparser uri-parser
  1944. "test/data/abnf_uri.txt"
  1945. @@ -26,19 +26,19 @@
  1946. uri-parser
  1947. (binding [instaparse.abnf/*case-insensitive* true]
  1948. (parser
  1949. - "test/data/abnf_uri.txt"
  1950. - :input-format :abnf
  1951. - :instaparse.abnf/case-insensitive true))
  1952. + "test/data/abnf_uri.txt"
  1953. + :input-format :abnf
  1954. + :instaparse.abnf/case-insensitive true))
  1955. (binding [instaparse.abnf/*case-insensitive* true]
  1956. (parser
  1957. - (io/resource "data/abnf_uri.txt")
  1958. - :input-format :abnf
  1959. - :instaparse.abnf/case-insensitive true))
  1960. + (io/resource "data/abnf_uri.txt")
  1961. + :input-format :abnf
  1962. + :instaparse.abnf/case-insensitive true))
  1963. (binding [instaparse.abnf/*case-insensitive* true]
  1964. (parser
  1965. - (slurp "test/data/abnf_uri.txt")
  1966. - :input-format :abnf
  1967. - :instaparse.abnf/case-insensitive true)))
  1968. + (slurp "test/data/abnf_uri.txt")
  1969. + :input-format :abnf
  1970. + :instaparse.abnf/case-insensitive true)))
  1971. "Verify that defparser, auto-slurp from string filename,
  1972. auto-slurp from resource (URL), and manual slurp all return
  1973. equivalent parsers.")))
  1974. @@ -210,9 +210,9 @@ to test the lookahead"
  1975.  
  1976. (deftest abnf-combinator-test
  1977. (let [p (parser (merge
  1978. - {:S (abnf "A / B")}
  1979. - (abnf "<A> = 1*'a'")
  1980. - {:B (abnf "'='")})
  1981. + {:S (abnf "A / B")}
  1982. + (abnf "<A> = 1*'a'")
  1983. + {:B (abnf "'='")})
  1984. :start :S)]
  1985. (are [x y] (= y x)
  1986. (p "aAaa")
  1987. diff --git a/test/instaparse/auto_flatten_seq_test.cljc b/test/instaparse/auto_flatten_seq_test.cljc
  1988. index bbc74ba..ee8533b 100644
  1989. --- a/test/instaparse/auto_flatten_seq_test.cljc
  1990. +++ b/test/instaparse/auto_flatten_seq_test.cljc
  1991. @@ -1,8 +1,8 @@
  1992. (ns instaparse.auto-flatten-seq-test
  1993. (:require
  1994. - [instaparse.auto-flatten-seq :refer [auto-flatten-seq conj-flat convert-afs-to-vec]]
  1995. - #?(:clj [clojure.test :refer [deftest are is]]
  1996. - :cljs [cljs.test]))
  1997. + [instaparse.auto-flatten-seq :refer [auto-flatten-seq conj-flat convert-afs-to-vec]]
  1998. + #?(:clj [clojure.test :refer [deftest are is]]
  1999. + :cljs [cljs.test]))
  2000. #?(:cljs (:require-macros [cljs.test :refer [deftest are is]])))
  2001.  
  2002. (defn rand-mutation [v iv]
  2003. diff --git a/test/instaparse/core_test.cljc b/test/instaparse/core_test.cljc
  2004. index a8ad3c5..414e428 100644
  2005. --- a/test/instaparse/core_test.cljc
  2006. +++ b/test/instaparse/core_test.cljc
  2007. @@ -1,21 +1,21 @@
  2008. (ns instaparse.core-test
  2009. #?(:clj (:refer-clojure :exclude [cat read-string]))
  2010. (:require
  2011. - #?(:clj [clojure.test :refer [deftest are is]]
  2012. - :cljs [cljs.test :as t])
  2013. - #?(:clj [clojure.edn :refer [read-string]]
  2014. - :cljs [cljs.reader :refer [read-string]])
  2015. - #?(:clj [instaparse.core :as insta :refer [defparser]]
  2016. - :cljs [instaparse.core :as insta :refer-macros [defparser]])
  2017. - [instaparse.cfg :refer [ebnf]]
  2018. - [instaparse.line-col :as lc]
  2019. - [instaparse.combinators-source :refer [Epsilon opt plus star rep
  2020. - alt ord cat string-ci string
  2021. - string-ci regexp nt look neg
  2022. - hide hide-tag]]
  2023. - [clojure.walk :as walk])
  2024. + #?(:clj [clojure.test :refer [deftest are is]]
  2025. + :cljs [cljs.test :as t])
  2026. + #?(:clj [clojure.edn :refer [read-string]]
  2027. + :cljs [cljs.reader :refer [read-string]])
  2028. + #?(:clj [instaparse.core :as insta :refer [defparser]]
  2029. + :cljs [instaparse.core :as insta :refer-macros [defparser]])
  2030. + [instaparse.cfg :refer [ebnf]]
  2031. + [instaparse.line-col :as lc]
  2032. + [instaparse.combinators-source :refer [Epsilon opt plus star rep
  2033. + alt ord cat string-ci string
  2034. + string-ci regexp nt look neg
  2035. + hide hide-tag]]
  2036. + [clojure.walk :as walk])
  2037. #?(:cljs (:require-macros
  2038. - [cljs.test :refer [is are deftest run-tests]])))
  2039. + [cljs.test :refer [is are deftest run-tests]])))
  2040.  
  2041. (defn parsers-similar?
  2042. "Tests if parsers are equal."
  2043. @@ -30,8 +30,8 @@
  2044. (instance? instaparse.core.Parser form)
  2045. (into {} form)
  2046. (instance? #?(:clj java.util.regex.Pattern
  2047. - :cljs js/RegExp)
  2048. - form)
  2049. + :cljs js/RegExp)
  2050. + form)
  2051. [::regex (str form)]
  2052. :else
  2053. form))))
  2054. @@ -366,7 +366,7 @@
  2055. Double = #'[0-9]+\\.[0-9]*|\\.[0-9]+';
  2056. <ConstExpr> = Int | Double;
  2057. Input = ConstExpr <ws> ConstExpr;"
  2058. - :start :Input))
  2059. + :start :Input))
  2060.  
  2061. (def case-insensitive-regexp
  2062. (insta/parser
  2063. @@ -379,25 +379,25 @@
  2064. [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]]
  2065. [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]
  2066.  
  2067. -#?@(:clj [(as-and-bs (StringBuilder. "aaaaabbbaaaabb"))
  2068. - [:S
  2069. - [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]]
  2070. - [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]])
  2071. + #?@(:clj [(as-and-bs (StringBuilder. "aaaaabbbaaaabb"))
  2072. + [:S
  2073. + [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]]
  2074. + [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]])
  2075.  
  2076. (as-and-bs "aaaaabbbaaaabb")
  2077. (as-and-bs "aaaaabbbaaaabb" :optimize :memory)
  2078.  
  2079. (as-and-bs-enlive "aaaaabbbaaaabb")
  2080. '{:tag :S,
  2081. - :content
  2082. - ({:tag :AB,
  2083. - :content
  2084. - ({:tag :A, :content ("a" "a" "a" "a" "a")}
  2085. + :content
  2086. + ({:tag :AB,
  2087. + :content
  2088. + ({:tag :A, :content ("a" "a" "a" "a" "a")}
  2089. {:tag :B, :content ("b" "b" "b")})}
  2090. {:tag :AB,
  2091. - :content
  2092. - ({:tag :A, :content ("a" "a" "a" "a")}
  2093. - {:tag :B, :content ("b" "b")})})}
  2094. + :content
  2095. + ({:tag :A, :content ("a" "a" "a" "a")}
  2096. + {:tag :B, :content ("b" "b")})})}
  2097.  
  2098. (as-and-bs-enlive "aaaaabbbaaaabb")
  2099. (as-and-bs-enlive "aaaaabbbaaaabb" :optimize :memory)
  2100. @@ -454,7 +454,7 @@
  2101.  
  2102. (insta/transform
  2103. {:num read-string
  2104. - :plus +}
  2105. + :plus +}
  2106. (addition-e "1+2+3+4+5"))
  2107. 15
  2108.  
  2109. @@ -499,7 +499,7 @@
  2110.  
  2111. (insta/parses
  2112. (insta/parser
  2113. - "Regex = (CharNonRange | Range) +
  2114. + "Regex = (CharNonRange | Range) +
  2115. Range = Char <'-'> Char
  2116. CharNonRange = Char ! ('-' Char)
  2117. Char = #'[-x]' | 'c' (! 'd') 'x'")
  2118. @@ -518,9 +518,9 @@
  2119.  
  2120. (insta/parses ambiguous-tokenizer "defn my cond")
  2121. '([:sentence
  2122. - [:identifier "defn"]
  2123. - [:identifier "my"]
  2124. - [:identifier "cond"]]
  2125. + [:identifier "defn"]
  2126. + [:identifier "my"]
  2127. + [:identifier "cond"]]
  2128. [:sentence [:keyword "defn"] [:identifier "my"] [:identifier "cond"]]
  2129. [:sentence [:identifier "defn"] [:identifier "my"] [:keyword "cond"]]
  2130. [:sentence [:keyword "defn"] [:identifier "my"] [:keyword "cond"]])
  2131. @@ -547,9 +547,9 @@
  2132. (words-and-numbers-one-character-at-a-time "abc 123 def" :optimize :memory)
  2133.  
  2134. (insta/transform
  2135. - {:word str,
  2136. - :number (comp read-string str)}
  2137. - (words-and-numbers-one-character-at-a-time "abc 123 def"))
  2138. + {:word str,
  2139. + :number (comp read-string str)}
  2140. + (words-and-numbers-one-character-at-a-time "abc 123 def"))
  2141. [:sentence "abc" 123 "def"]
  2142.  
  2143. (->> (words-and-numbers-enlive "abc 123 def")
  2144. @@ -576,9 +576,9 @@
  2145. (arithmetic "1-2/(3-4)+5*6" :optimize :memory)
  2146.  
  2147. (->> (arithmetic "1-2/(3-4)+5*6")
  2148. - (insta/transform
  2149. - {:add +, :sub -, :mul *, :div /,
  2150. - :number read-string :expr identity}))
  2151. + (insta/transform
  2152. + {:add +, :sub -, :mul *, :div /,
  2153. + :number read-string :expr identity}))
  2154. 33
  2155.  
  2156. (paren-ab-hide-both-tags "(aba)")
  2157. @@ -612,7 +612,7 @@
  2158. ((insta/parser "S = ('a'?)+") "" :optimize :memory)
  2159.  
  2160. ((insta/parser
  2161. - "a = b c .
  2162. + "a = b c .
  2163. b = 'b' .
  2164. c = 'c' .") "bc")
  2165. [:a [:b "b"] [:c "c"]]
  2166. diff --git a/test/instaparse/defparser_test.cljc b/test/instaparse/defparser_test.cljc
  2167. index 6246f0b..1c561b8 100644
  2168. --- a/test/instaparse/defparser_test.cljc
  2169. +++ b/test/instaparse/defparser_test.cljc
  2170. @@ -1,11 +1,11 @@
  2171. (ns instaparse.defparser-test
  2172. (:require
  2173. - #?(:clj [clojure.test :as t :refer [deftest are is]]
  2174. - :cljs [cljs.test :as t :refer-macros [deftest are is]])
  2175. - #?(:clj [instaparse.core :as insta :refer [defparser]]
  2176. - :cljs [instaparse.core :as insta :refer-macros [defparser]])
  2177. - [instaparse.combinators :as c]
  2178. - [instaparse.core-test :refer [parsers-similar?]]))
  2179. + #?(:clj [clojure.test :as t :refer [deftest are is]]
  2180. + :cljs [cljs.test :as t :refer-macros [deftest are is]])
  2181. + #?(:clj [instaparse.core :as insta :refer [defparser]]
  2182. + :cljs [instaparse.core :as insta :refer-macros [defparser]])
  2183. + [instaparse.combinators :as c]
  2184. + [instaparse.core-test :refer [parsers-similar?]]))
  2185.  
  2186. (defparser p1 "S = #'a' | 'b'")
  2187.  
  2188. diff --git a/test/instaparse/grammars.cljc b/test/instaparse/grammars.cljc
  2189. index 82dc9b1..78ba482 100644
  2190. --- a/test/instaparse/grammars.cljc
  2191. +++ b/test/instaparse/grammars.cljc
  2192. @@ -2,15 +2,15 @@
  2193. #?(:clj (:refer-clojure :exclude [cat]))
  2194. (:require #?(:clj [clojure.test :refer [deftest are]]
  2195. :cljs [cljs.test :as t])
  2196. - [instaparse.reduction :refer [apply-standard-reductions]]
  2197. - [instaparse.combinators :refer [Epsilon opt plus
  2198. - star rep alt ord
  2199. - cat string string-ci
  2200. - regexp nt look neg
  2201. - hide hide-tag
  2202. - ebnf abnf]]
  2203. - [instaparse.gll :as gll]
  2204. - [instaparse.core :as insta])
  2205. + [instaparse.reduction :refer [apply-standard-reductions]]
  2206. + [instaparse.combinators :refer [Epsilon opt plus
  2207. + star rep alt ord
  2208. + cat string string-ci
  2209. + regexp nt look neg
  2210. + hide hide-tag
  2211. + ebnf abnf]]
  2212. + [instaparse.gll :as gll]
  2213. + [instaparse.core :as insta])
  2214. #?(:cljs (:require-macros [cljs.test :refer [is are deftest run-tests testing]])))
  2215.  
  2216. (defn- parse [grammar start text]
  2217. @@ -40,8 +40,8 @@
  2218. (cat (string "b") (nt :s))
  2219. Epsilon)})
  2220. (def grammar10 {:s (alt (cat (nt :s) (string "a") )
  2221. - (cat (nt :s) (string "b") )
  2222. - Epsilon)})
  2223. + (cat (nt :s) (string "b") )
  2224. + Epsilon)})
  2225. (def grammar11 {:s (alt (cat (nt :s) (string "a")) (string "a"))})
  2226. (def grammar12 {:s (alt (nt :a) (nt :a) (nt :a))
  2227. :a (alt (cat (nt :s) (string "a")) (string "a"))})
  2228. @@ -54,10 +54,10 @@
  2229. (cat (string "(") (nt :s) (string ")"))
  2230. (cat (nt :s) (nt :s)))})
  2231. (def non-ll-grammar {:s (alt (nt :a) (nt :b))
  2232. - :a (alt (cat (string "a") (nt :a) (string "b"))
  2233. - Epsilon)
  2234. - :b (alt (cat (string "a") (nt :b) (string "bb"))
  2235. - Epsilon)})
  2236. + :a (alt (cat (string "a") (nt :a) (string "b"))
  2237. + Epsilon)
  2238. + :b (alt (cat (string "a") (nt :b) (string "bb"))
  2239. + Epsilon)})
  2240. (def grammar14 {:s (cat (opt (string "a")) (string "b"))})
  2241. (def grammar15 {:s (cat (opt (string "a")) (opt (string "b")))})
  2242. (def grammar16 {:s (plus (string "a"))})
  2243. diff --git a/test/instaparse/repeat_test.cljc b/test/instaparse/repeat_test.cljc
  2244. index 4a79538..2eff067 100644
  2245. --- a/test/instaparse/repeat_test.cljc
  2246. +++ b/test/instaparse/repeat_test.cljc
  2247. @@ -1,12 +1,12 @@
  2248. (ns instaparse.repeat-test
  2249. (:require #?(:clj [clojure.test :refer [deftest are]]
  2250. :cljs [cljs.test :as t])
  2251. - [instaparse.core :as insta]
  2252. - [instaparse.repeat :as repeat])
  2253. + [instaparse.core :as insta]
  2254. + [instaparse.repeat :as repeat])
  2255. #?(:cljs (:require-macros [cljs.test :refer [are deftest]])))
  2256.  
  2257. (def user-parser
  2258. -"content = user-block*
  2259. + "content = user-block*
  2260. user-block = (user before-section after-section < blank-line* >)
  2261. user = prefix separator number separator name newline
  2262. before-section = < before > lines error-line*
  2263. @@ -37,8 +37,8 @@ number = #'[0-9]+'
  2264. tree3 (parser-enlive text)
  2265. tree4 (parser-enlive text :optimize :memory)]
  2266. (and (= tree1 tree2) (= tree3 tree4)
  2267. - (= optimize? (repeat/used-memory-optimization? tree2))
  2268. - (= optimize? (repeat/used-memory-optimization? tree4))))
  2269. + (= optimize? (repeat/used-memory-optimization? tree2))
  2270. + (= optimize? (repeat/used-memory-optimization? tree4))))
  2271.  
  2272. ;user-parser text true
  2273. "S = 'ab'*" "ababab" true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement