Skip to content

Commit

Permalink
Merge pull request #15 from carocad/perf
Browse files Browse the repository at this point in the history
Performance improvements
  • Loading branch information
carocad committed Oct 14, 2019
2 parents b1d2141 + c0066d3 commit cce5f73
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 214 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
- lein trampoline test
- nvm install 10.10 && nvm use 10.10 && lein trampoline cljsbuild test

# only run the benchmark is we are on master
# only run the benchmark if we are trying to merge to master
# otherwise the build takes too long
- stage: Benchmark
if: head_branch = master
if: branch = master
script:
- lein trampoline test :benchmark

Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,29 @@ full explanation of the options available for a parser please visit Instaparse w
[:symbol "parcera.core"]
[:whitespace " "]
[:list
[:simple-keyword "require"]
[:simple-keyword ":require"]
[:whitespace " "]
[:vector
[:symbol "instaparse.core"]
[:whitespace " "]
[:simple-keyword "as"]
[:simple-keyword ":as"]
[:whitespace " "]
[:symbol "instaparse"]]
[:whitespace " "]
[:vector [:symbol "clojure.data"] [:whitespace " "] [:simple-keyword "as"] [:whitespace " "] [:symbol "data"]]
[:vector [:symbol "clojure.data"] [:whitespace " "] [:simple-keyword ":as"] [:whitespace " "] [:symbol "data"]]
[:whitespace " "]
[:vector [:symbol "clojure.string"] [:whitespace " "] [:simple-keyword "as"] [:whitespace " "] [:symbol "str"]]]]]
[:vector [:symbol "clojure.string"] [:whitespace " "] [:simple-keyword ":as"] [:whitespace " "] [:symbol "str"]]]]]

;; convert an AST back into a string
(parcera/code [:symbol "ns"])
;; "ns"
```

### notes
There are some restrictions as to how much can a parser do. In my experience, these restrictions
are related to some [semantic context-sensitivity](http://blog.reverberate.org/2013/09/ll-and-lr-in-context-why-parsing-tools.html).
which the Clojure reader has embedded into itself. In general I have found the following ones:
- `parcera` doesnt check that a map contains an even number of elements. This is specially difficult
to do since Clojure supports the discard macro `#_ form` which is a valid element but "doesnt count as one"
- `parcera` doesnt check if a map has repeated keys
- `parcera` doesnt check if a set has repeated elements
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject carocad/parcera "0.2.1"
(defproject carocad/parcera "0.3.0"
:description "Grammar-based Clojure(script) parser"
:url "https://github.com/carocad/parcera"
:license {:name "LGPLv3"
Expand Down
Loading

0 comments on commit cce5f73

Please sign in to comment.