Skip to content

repaired antlr4-lab - #97

Open
michele-fadda wants to merge 1 commit into
antlr:masterfrom
michele-fadda:master
Open

repaired antlr4-lab#97
michele-fadda wants to merge 1 commit into
antlr:masterfrom
michele-fadda:master

Conversation

@michele-fadda

Copy link
Copy Markdown

fix: make antlr4-lab run locally without root or cloud dependencies

Changes to run the server locally without sudo, Maven SNAPSHOT deps, or Google Cloud credentials, with automatic SVG dependency installation.

Core fixes

  • Port 80 → 8080 (configurable via -Dantlrlab.port)
  • Log directory /var/log/antlrlab → /tmp/antlrlab (configurable via -Dantlrlab.log.dir)
  • Removed us.parr:parrtlib:0.5-SNAPSHOT dependency (not in Maven Central); execInDir() and StreamVacuum inlined into GrammarProcessor
  • Replaced deprecated StringBufferInputStream with CharStreams.fromString()
  • execInDir uses ProcessBuilder with /opt/homebrew/bin added to PATH for Apple Silicon Homebrew compatibility

SVG dependency management

  • ensureSVGDeps() auto-installs ps2pdf/pdf2svg via brew (macOS) or sudo apt-get (Linux); returns helpful install instructions in an error SVG for Windows and unsupported OSes
  • toSVG returns error SVG with guidance instead of crashing

Share servlet

  • ShareServlet writes to local filesystem (/tmp/antlrlab/share/) instead of Google Cloud Storage (no GCP credentials required)

Testing

  • Added JUnit 5 dependencies and test source directory
  • 14 unit tests covering interp(), execInDir(), commandExists(), escXml(), makeErrorSVG(), ensureSVGDeps()

Docker

  • Updated ENTRYPOINT to pass -Dantlrlab.port=80 for container use

Documentation and license

  • Updated README.md with local setup, configuration table, test command, and modifications summary
  • Added copyright notice to LICENSE
  • Added code comments documenting all local changes

fix: make antlr4-lab run locally without root or cloud dependencies

Changes to run the server locally without sudo, Maven SNAPSHOT deps, or
Google Cloud credentials, with automatic SVG dependency installation.

## Core fixes
- Port 80 → 8080 (configurable via -Dantlrlab.port)
- Log directory /var/log/antlrlab → /tmp/antlrlab (configurable via
  -Dantlrlab.log.dir)
- Removed us.parr:parrtlib:0.5-SNAPSHOT dependency (not in Maven
  Central); execInDir() and StreamVacuum inlined into GrammarProcessor
- Replaced deprecated StringBufferInputStream with CharStreams.fromString()
- execInDir uses ProcessBuilder with /opt/homebrew/bin added to PATH
  for Apple Silicon Homebrew compatibility

## SVG dependency management
- ensureSVGDeps() auto-installs ps2pdf/pdf2svg via brew (macOS) or
  sudo apt-get (Linux); returns helpful install instructions in an error
  SVG for Windows and unsupported OSes
- toSVG returns error SVG with guidance instead of crashing

## Share servlet
- ShareServlet writes to local filesystem (/tmp/antlrlab/share/) instead
  of Google Cloud Storage (no GCP credentials required)

## Testing
- Added JUnit 5 dependencies and test source directory
- 14 unit tests covering interp(), execInDir(), commandExists(),
  escXml(), makeErrorSVG(), ensureSVGDeps()

## Docker
- Updated ENTRYPOINT to pass -Dantlrlab.port=80 for container use

## Documentation and license
- Updated README.md with local setup, configuration table, test command,
  and modifications summary
- Added copyright notice to LICENSE
- Added code comments documenting all local changes
@parrt

parrt commented May 31, 2026

Copy link
Copy Markdown
Member

Hi unfortunately that's a pretty big change and I don't really have time to see if everything is OK with it. I'm not really maintaining the project anymore except paying for the Google cloud server. sorry!

@NWoodsman

NWoodsman commented Jul 20, 2026

Copy link
Copy Markdown

For those interested, I got this PR working in NixOS by serving it in a nix develop shell. If you want to reproduce:

  • be in a working NixOS system.
  • make a folder, for example ~/antlr4/
  • create ~/antlr4/flake.nix file. Copy and paste this into the file: Antlr4 flake gist
  • start a new shell session
  • an optional step to prep ahead of time, if you want to access the Antlr4 application from a different PC on your local network, run this first:

sudo nixos-firewall-tool open tcp 8080 - this opens the correct port non-persistently

then

mkdir /tmp/antlr-images - my builds were failing until I manually added this folder.
cd ~/antlr4
git clone https://github.com/antlr/antlr4-lab.git
git fetch origin pull/97/head:fix
git checkout fix
nix develop - It should fetch the dependencies without errors.
cd ~/antlr4/antlr4-lab
mvn install - it will run the build and tests.
java -jar target/antlr4-lab-0.4-SNAPSHOT-complete.jar - the terminal will seem to hang, which means the app is running. Leave the terminal window open for the duration of use.

As per the instructions in the PR readme, open a web browser and go to http://localhost:8080/index.html

(If you are on a client PC in your local network, and you did the optional step above of opening the port so the app is running on your server, it will be accessible at the server's ip address: http://192.xxx.xxx.xxx:8080.)

I found that entering an escape key sequence to kill the app does not fully release the port, so attempting to run the java -jar target/antlr4-lab-0.4-SNAPSHOT-complete.jar command subsequent times fails. Closing the terminal window and reopening is the only solution, which of course removes the nix develop environment, so you have to cd back to the project, re-run nix develop, re-run mvn install, and then the java command will work.

Edit: I also got it running in an incus container running Alpine Linux cloud 3.24 which is the lightest weight container possible (20mb) however the build dependencies bulk it up quite a lot in terms of disk space (otherwise it's minimal cpu to run on a small server)...if you want a writeup on the incus container let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants