This repo contains a grammar and code that reproduces issue antlr/antlr4#1901, which I've opened against the antlr4 repository. In here we have:
./parser
- A grammar for Javascript ES5 with a Go target (I've just PR'ed to the grammars-v4 repo)
- The code generated by
antlr4 -Dlanguage=Go ECMAScript.g4
using the latest master.
jstest.go
- Accepts a filename of a Javascript file
- Prints the text of every rule encountered in the file
- Enables the Go profiler over HTTP port 6060
good.js
- Sample JS code that parses correctly without issue
bad.js
- JS code that eventually parses and works, but not after first allocating almost 8GB RAM
profile001.svg
- Graphical heap profile taken when resident mem was ~2.3GB
- To take your own heap snapshot, run the following while the test is running:
go tool pprof http://localhost:6060/debug/pprof/heap
- In the CLI, run
svg
, or runtop
to see it in text form (svg is more comprehensive)
To reproduce first install dependencies:
go get github.com/antlr/antlr4/runtime/Go/antlr
To run the parser on the good JS file:
go run js.go -file good.js
To run the parser and cause the memory issue:
go run js.go -file bad.js
WARNING- Make sure you run this on a system with plenty of free memory!
The test takes a while- several minutes.