aphyr / clj-antlr

Clojure bindings for the ANTLR 4 parser
167 stars 32 forks source link

Store Start Token Position in S-Expression Metadata #6

Closed xsc closed 7 years ago

xsc commented 7 years ago

This PR adjusts the coercer to attach positional information about the first token of a subtree to the metadata of the coerced s-expression (using the key :clj-antlr/position) This addresses #1.

Let me know if you prefer a different approach. It's thinkable, for example, to only activate this if the :format option is set to e.g. :sexpr-with-metadata; or to introduce an additional option like :track-position?.

aphyr commented 7 years ago

How's performance?

xsc commented 7 years ago

Here you go:

$ lein version
Leiningen 2.6.1 on Java 1.8.0_45 Java HotSpot(TM) 64-Bit Server VM
$ LEIN_JVM_OPTS= lein test :perf

instaparse (master)

Evaluation count : 1800 in 60 samples of 30 calls.
             Execution time mean : 35.159779 ms
    Execution time std-deviation : 1.603381 ms
   Execution time lower quantile : 33.062177 ms ( 2.5%)
   Execution time upper quantile : 38.310700 ms (97.5%)
                   Overhead used : 1.720364 ns

clj-antlr (master)

Evaluation count : 171900 in 60 samples of 2865 calls.
             Execution time mean : 352.168112 µs
    Execution time std-deviation : 3.888441 µs
   Execution time lower quantile : 345.154815 µs ( 2.5%)
   Execution time upper quantile : 358.637585 µs (97.5%)
                   Overhead used : 1.702145 ns

Found 2 outliers in 60 samples (3.3333 %)
    low-severe   1 (1.6667 %)
    low-mild     1 (1.6667 %)
 Variance from outliers : 1.6389 % Variance is slightly inflated by outliers

clj-antlr (ys/position-in-metadata)

Benchmarking clj-antlr
Evaluation count : 167340 in 60 samples of 2789 calls.
             Execution time mean : 365.891084 µs
    Execution time std-deviation : 4.595089 µs
   Execution time lower quantile : 359.414837 µs ( 2.5%)
   Execution time upper quantile : 376.188071 µs (97.5%)
                   Overhead used : 1.710780 ns

Found 2 outliers in 60 samples (3.3333 %)
    low-severe   2 (3.3333 %)
 Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
aphyr commented 7 years ago

Yeah, that looks great! I'd say let's go for it. :-)