Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Typescript target #3870

Closed
wants to merge 182 commits into from
Closed
Show file tree
Hide file tree
Changes from 165 commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
8f9ec1f
Update C# release instructions
ericvergnaud Sep 4, 2022
8347aff
Fix CMake syntax for variable expansion
hs-apotell Jul 6, 2022
de0efeb
initial commit
ericvergnaud Jul 17, 2022
e611332
renamed for clarity
ericvergnaud Jul 17, 2022
e8f59d6
renamed for clarity
ericvergnaud Jul 17, 2022
a4aa1fb
able to locate antlr4 runtime using ts-node, missing types
ericvergnaud Jul 17, 2022
6915202
progressing
ericvergnaud Jul 17, 2022
c0fd00f
able to 'run' a test. It fails but it compiles and resolves!
ericvergnaud Sep 3, 2022
b4f9e93
reflect refactored runtime
ericvergnaud Sep 3, 2022
971645f
able to run RecursiveLexerRuleRefWithWildcardPlus_1 test locally
ericvergnaud Sep 3, 2022
4c80ae1
passes LexerExec tests in IntelliJ
ericvergnaud Sep 3, 2022
16b121a
make ATN private
ericvergnaud Sep 3, 2022
009107c
ignore same tests as JavaScript
ericvergnaud Sep 3, 2022
66144f8
compiles Parser and Lexer bu local run fails
ericvergnaud Sep 4, 2022
484cc5a
ParserExec.TokenOffset test successful in IntelliJ !
ericvergnaud Sep 4, 2022
e34c664
Progressing, passing 131 of 348 tests
ericvergnaud Sep 5, 2022
9aca326
pass 327 tests out of 348
ericvergnaud Sep 5, 2022
a9b058f
more successful tests
ericvergnaud Sep 6, 2022
dcff0b0
333 successful tests out of 348
ericvergnaud Sep 6, 2022
06fd2d9
all tests pass except 7 caused by #3868
ericvergnaud Sep 6, 2022
0a5f10e
update getting-started doc
Nicksxs Jun 14, 2022
291d974
add blank github action file for hosted CI
parrt Jul 15, 2022
d7c6681
update getting started document to say java 11
parrt Jul 22, 2022
1fab453
Revert "update getting started document to say java 11"
parrt Jul 22, 2022
ac470cb
add C# book code links
parrt Jul 22, 2022
3fb98a3
Add Jim/Ken to readme
parrt Aug 13, 2022
20d6f35
Update Swift Package to support static library
HellGhost Apr 19, 2022
0d8116e
Update Package.swift
HellGhost Apr 20, 2022
cdfaeca
Add caching support for maven & dependencies. Also, include caching for
hs-apotell Aug 14, 2022
778bcc3
use snap to install go 1.19
parrt Aug 15, 2022
7298b4d
grr...install snap
parrt Aug 15, 2022
22bc7ba
ugh. start snap
parrt Aug 15, 2022
b8de845
ugh. start snap
parrt Aug 15, 2022
3ac6040
ugh. cant get snap to install go
parrt Aug 15, 2022
46f4f0d
try downloading golang with curl
parrt Aug 15, 2022
287750a
Issue #3823: Temporarily disable a few tests on CI
hs-apotell Aug 15, 2022
2c928d9
update actions status badge
parrt Sep 2, 2022
5aa550c
update getting started document to say java 11
parrt Jul 22, 2022
06be349
Revert "update getting started document to say java 11"
parrt Jul 22, 2022
7cf65fb
update getting-started doc
Nicksxs Jun 14, 2022
b992179
make getValue visible to external profiler tools.
parrt Jul 23, 2022
3cb4dc2
Fix #3508: Document the $parser attribute and its use in target-agnos…
RossPatterson Aug 1, 2022
543780e
Add accessor to IntervalSet for intervals
JamesRTaylor Aug 1, 2022
90eaf64
Remove libuuid dependency from C++ runtime
Technius Jul 14, 2022
4e64674
Add `@SuppressWarnings("CheckReturnValue")` to prevent error_prone li…
parrt Aug 9, 2022
ae9bc5f
fix: Fixes for https://github.com/antlr/antlr4/issues/3718
Aug 13, 2022
ae35acf
fix: #3718 Revert accidental keyboard error in Java target
Aug 14, 2022
3c0d902
fix: #3718 Correct DFAState index in Lexer ATN Simulator
Aug 15, 2022
3dc5810
fix: #3718 Fix go runtime test runners
Aug 15, 2022
a8f8441
Rm remote github actions; hosted seems to work
parrt Aug 13, 2022
e56dba2
install golang with curl; go was missing from dev
parrt Aug 15, 2022
9d90942
fix: Rework of all Hash() and Equals() methods - implement generic co…
Aug 20, 2022
1d253d3
fix: #3718 Correct DFAState index in Lexer ATN Simulator
Aug 15, 2022
d89bf4e
feat: Reduce initial memory allocations for collections
Aug 21, 2022
cf95233
fix: #3758 Allow for string being a keyword and fix go template to us…
Aug 22, 2022
a4399af
fix: #3758 Add go.sum to the repo
Aug 23, 2022
f3aa043
fix: #3758 Ensure that standard runtime extensions are included in go…
Aug 23, 2022
34f209b
fix: #2826 Go template is incorrect for dynamic scopes
Aug 22, 2022
e78a7f0
fix: #2016 - Generate correct iGo code for lists in a grammar, such a…
Aug 23, 2022
2737936
feat: Bump poms to use 4.11 Snapshot
Aug 23, 2022
049afb1
turn off Golang test at circleci for now
parrt Aug 26, 2022
ba58f09
Replace smart-quote with single-quote in code examples
timmc Aug 26, 2022
226e130
Augment error message during testing to include full cause of problem.
parrt Aug 27, 2022
0041270
Augment error message during testing to include full cause of problem…
parrt Aug 27, 2022
9c02642
Cpp: Link to threads library
Krzmbrzl Jul 18, 2022
e33c906
add test for #2016 and fix java.
parrt Aug 27, 2022
9a0be4b
ensure all targets have the appropriate argument list for the templat…
parrt Aug 27, 2022
2694548
Fix other targets
parrt Aug 27, 2022
534f1e2
fix format
parrt Aug 28, 2022
e5dd859
add check that $args is a list
parrt Aug 28, 2022
c6bf3ca
change made by @lingyv-li to fix bug in DART exposed by this test.
parrt Aug 28, 2022
f0b1cc6
fix AssertIsList in multiple targets. Go doesn't pass test and has no…
parrt Aug 28, 2022
23bf0d4
C++ gets an exception with this test so I'm turning it off. See https…
parrt Aug 28, 2022
40893e1
feat: #3840 Move Go to version v4.11.0
Aug 31, 2022
120c436
feat: #3840 Create the v4 version of the Go runtime
Aug 31, 2022
1f6b441
feat: Create the v4 runtime layout for the Go runtime, ready for rele…
Aug 31, 2022
cab9eba
Reenable go tests on CircleCI
KvanTTT Aug 30, 2022
ec4184d
Fold constants in generated code for all runtimes
KvanTTT Aug 30, 2022
44598d0
Use int literals instead of refs for Python and JavaScript
KvanTTT Aug 30, 2022
b6dd6ec
update release doc for Go version numbers
parrt Sep 2, 2022
cc5cc1a
fix: #2016 Fix Go template list reference, go runtime and got test te…
Aug 30, 2022
4853a32
feat: Add a deprecation message to the existing v1 module
Sep 1, 2022
94e9579
Split tool and runtime tests for GitHub workflow
KvanTTT Sep 1, 2022
2eb204c
Remove not used methods from FileUtils (runtime tests)
KvanTTT Sep 1, 2022
eeb203a
Update dependencies of antlr4-maven-plugin
KvanTTT Sep 1, 2022
b528b01
Update jUnit: 5.8.2 -> 5.9.0
KvanTTT Sep 2, 2022
b01e6c9
Fixes #3733; update ST4 so it uses proper ANTLR 3
parrt Sep 3, 2022
b0b939b
tweak doc
parrt Sep 4, 2022
4fa7d59
Set to 4.11.0 not 4.11 in poms
parrt Sep 4, 2022
e4dae63
[maven-release-plugin] prepare release 4.11.0
parrt Sep 4, 2022
d2dcdf0
[maven-release-plugin] prepare for next development iteration
parrt Sep 4, 2022
5e34cf2
Damn. java target said 4.10.2 not 4.11.0
parrt Sep 4, 2022
24c428f
roll back to 4.11.0; made mistake
parrt Sep 4, 2022
d9dd4e7
roll back to 4.11.0; made mistake
parrt Sep 4, 2022
a97d64f
[maven-release-plugin] prepare release antlr4-master-4.11.0
parrt Sep 4, 2022
2fbce07
[maven-release-plugin] prepare for next development iteration
parrt Sep 4, 2022
3ef1175
use build and twine to publish source and wheel
eagleoflqj Aug 5, 2022
3fd76cc
tweak doc
parrt Sep 4, 2022
3c03b13
tweak c++ build script to make Mac binaries with cmake/make
parrt Sep 4, 2022
1282aeb
tweak release doc
parrt Sep 4, 2022
2a339b1
tweak code / doc related to bad previous release
parrt Sep 4, 2022
cc6255d
[maven-release-plugin] prepare release 4.11.1
parrt Sep 4, 2022
247ea95
[maven-release-plugin] prepare for next development iteration
parrt Sep 4, 2022
4f51c8e
clean up deploy c++ source script
parrt Sep 4, 2022
7ecc8d4
cleanup code generation
ericvergnaud Sep 6, 2022
4436371
don't initialize default param values twice
ericvergnaud Sep 6, 2022
5ae181d
add missing field
ericvergnaud Sep 6, 2022
6606541
update codegen template for 4.11.1
ericvergnaud Sep 6, 2022
12bb4c0
support new param: Parser
ericvergnaud Sep 6, 2022
c686a23
fix template for 4.11
ericvergnaud Sep 6, 2022
53f37e6
default export Listener and Visitor
ericvergnaud Sep 6, 2022
3346121
also default export parser and lexer
ericvergnaud Sep 6, 2022
721dd27
all tests pass except 7 caused by #3868
ericvergnaud Sep 6, 2022
59a7cda
fix issues
ericvergnaud Sep 7, 2022
974606e
make it easy to break
ericvergnaud Sep 7, 2022
4cdda92
fix #3868
ericvergnaud Sep 7, 2022
3c177ad
ALL TESTS PASS!!!!
ericvergnaud Sep 7, 2022
adfea72
cross fingers with CI
ericvergnaud Sep 7, 2022
c9fda4c
try fixing broken go tests
ericvergnaud Sep 7, 2022
aab39f3
Try fix typescript CI
ericvergnaud Sep 7, 2022
3a2c80a
disable cpp for now
ericvergnaud Sep 7, 2022
b9155d5
fix broken config
ericvergnaud Sep 7, 2022
0385b0f
try fix macos gh build
ericvergnaud Sep 8, 2022
b569a8a
improve speed by caching node_modules
ericvergnaud Sep 8, 2022
b6f3a3e
no longer using ts-node
ericvergnaud Sep 8, 2022
46cd715
fix all tsc warnings
ericvergnaud Sep 8, 2022
d579281
try fix MacOS CI
ericvergnaud Sep 8, 2022
cfb7a07
CI errors seem random, reactivate ubuntu
ericvergnaud Sep 8, 2022
f7ca70f
Disable node_modules caching, which seems to randomly fail in CI
ericvergnaud Sep 9, 2022
cd42048
don't delete symlink contents on windows (java bug with is SymbolicLi…
ericvergnaud Sep 9, 2022
39f9187
fix broken windows CI
ericvergnaud Sep 9, 2022
d1ce99f
verify windows ci
ericvergnaud Sep 9, 2022
e0b49ff
Revert "verify windows ci"
ericvergnaud Sep 9, 2022
e46a957
reinstate full CI
ericvergnaud Sep 9, 2022
c120035
Merge branch 'dev' into typescript-target
ericvergnaud Sep 9, 2022
b267b88
manually merged
ericvergnaud Sep 9, 2022
994c1da
manually merge
ericvergnaud Sep 9, 2022
2196356
fix merge
ericvergnaud Sep 9, 2022
32d8324
fix broken template
ericvergnaud Sep 9, 2022
8459a10
add template for invoking context list
ericvergnaud Sep 9, 2022
ce4ef34
fix typo
ericvergnaud Sep 9, 2022
6243515
fix test templates
ericvergnaud Sep 9, 2022
95d9323
Add code of conduct but with a different name since I do not like tha…
parrt Sep 10, 2022
c902766
Merge branch 'master' of github.com:antlr/antlr4
parrt Sep 10, 2022
0b6ad68
Tweak code of conduct
parrt Sep 11, 2022
e96de77
Bring back the Package.swift in the project's root
edigaryev Sep 6, 2022
af9d33b
swift-target.md: fix SPM installation instructions
edigaryev Sep 6, 2022
dafe48c
the scope (parser or lexer) in @parser::header was dropped, so keep t…
ericvergnaud Sep 8, 2022
b1a96db
Describe using antlr4-tools in getting started documentation
parrt Sep 11, 2022
eaed29b
Tweak doc
parrt Sep 11, 2022
483a431
Merge branch 'master' of github.com:antlr/antlr4
parrt Sep 11, 2022
f94a484
Describe using antlr4-tools in getting started documentation
parrt Sep 11, 2022
b979bbb
Tweak doc
parrt Sep 11, 2022
aa1f1f1
Add Windows doc for antlr4-tool usage
parrt Sep 11, 2022
dd6499b
Add code of conduct but with a different name since I do not like tha…
parrt Sep 10, 2022
13cade1
Update C# release instructions
ericvergnaud Sep 4, 2022
32b9ab1
Tweak code of conduct
parrt Sep 11, 2022
2056bdc
Bring back the Package.swift in the project's root
edigaryev Sep 6, 2022
f85941a
swift-target.md: fix SPM installation instructions
edigaryev Sep 6, 2022
0d9f564
the scope (parser or lexer) in @parser::header was dropped, so keep t…
ericvergnaud Sep 8, 2022
0ba2430
Merge commit 'aa1f1f12a846846fcb78544bdb2ad135471376db' into typescri…
ericvergnaud Sep 12, 2022
d47725c
drop workaround in favor of #3878
ericvergnaud Sep 12, 2022
c51aa8e
drop cache usage since it fails in CI
ericvergnaud Sep 12, 2022
3f53baf
#3878 was missing some scenarios
ericvergnaud Sep 12, 2022
4f68fd1
fix issue when deleting test folder
ericvergnaud Sep 12, 2022
8598898
fix warnings
ericvergnaud Sep 18, 2022
c77c6a4
drop duplicate behavior
ericvergnaud Sep 18, 2022
0ecd794
drop alien 'abstractRecognizer' property
ericvergnaud Sep 18, 2022
fba546f
drop alien property 'channels'
ericvergnaud Sep 18, 2022
b309992
fix various codegen issues
ericvergnaud Sep 18, 2022
7a41586
change import
ericvergnaud Sep 18, 2022
73aa072
restore js extensions, see https://github.com/microsoft/TypeScript/is…
ericvergnaud Sep 18, 2022
49208a0
use consistent inheritance
ericvergnaud Sep 18, 2022
475ce03
more API
ericvergnaud Sep 18, 2022
cfc617f
more API stuff
ericvergnaud Oct 6, 2022
8b56bd9
fix typo
ericvergnaud Oct 6, 2022
553d49d
fix typescript exports
ericvergnaud Oct 16, 2022
c89dcbd
use ts-node to run typescript tests
ericvergnaud Oct 16, 2022
c52f538
webpack runtime before linking
ericvergnaud Oct 16, 2022
1d350cb
fix exec paths on windows
ericvergnaud Oct 16, 2022
c4cf52b
fix failing tests
ericvergnaud Oct 17, 2022
5d4692e
fix a few import issues
ericvergnaud Oct 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ jobs:
go,
java,
javascript,
typescript,
php,
python2,
python3,
Expand Down Expand Up @@ -230,7 +231,7 @@ jobs:
architecture: 'x64'

- name: Set up Node 14
if: matrix.target == 'javascript'
if: (matrix.target == 'javascript') || (matrix.target == 'typescript')
uses: actions/setup-node@v3
with:
node-version: '14'
Expand Down
28 changes: 28 additions & 0 deletions ANTLR-HOUSE-RULES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ANTLR HOUSE RULES

*Last updated: Sept 10, 2022*

This brief document describes best practices for us to all get along and for the benefit of the project. Collaborating on this project poses a number of difficulties:

* different native languages
* different time zones
* lack of common company or other organization as social glue
* we are just github userids without personal connection to most other contributors
* those developers able to contribute to such a complex project typically have a lot of experience and, consequently, strong opinions

Effective communication is difficult under the circumstances and civil discourse is a requirement to keep the project on track. Over 35 years, in-fighting between contributors has made parrt's job as supreme dictator for life much more difficult.

Rules

1. Assume good intentions of the other party.
2. Try to be welcoming and respectful of differing viewpoints experiences.
2. No personal attacks, meaning ideas can be bad in your comments but not people. Replace "You are ..." with "Your idea is ...".
3. Control your anger please. No hate speech, racism, sexism, or ethnocentrism. No trolling or insulting. See rule #1.
2. Be tolerant and understanding of non-native English speakers' word choice and phrasing. This is a huge source of misunderstandings; see rule #1. For example, to a native English speaker "I cannot *approve* this" makes it sound like the writer has control over the readers contribution. Instead, the writer likely meant "I cannot *support* this." See rule #1.
3. Soften word choice to use conditional tenses and helper words. For example, use phrases such as "I'm not sure this is a good idea because ..." or "I wonder if you'd consider this other possibility: ..." etc...

Supreme dictator for life parrt has final say. His decisions will not always be correct nor to your liking, but he has a difficult cost-benefit equation to solve for every bug fix, feature, and PR.

Any text contrary to these house rules will likely be edited and replaced with an admonishment by parrt.

Send concerns to parrt@antlr.org.
10 changes: 7 additions & 3 deletions runtime/Swift/Package.swift → Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ let package = Package(
.target(
name: "Antlr4",
dependencies: [],
path: "Sources/Antlr4"),
path: "./runtime/Swift/Sources/Antlr4"),
.testTarget(
name: "Antlr4Tests",
dependencies: ["Antlr4"],
path:"Tests/Antlr4Tests",
path: "./runtime/Swift/Tests/Antlr4Tests",
exclude: [
"VisitorBasic.g4", "VisitorCalc.g4", "LexerA.g4", "LexerB.g4", "Threading.g4"
"./runtime/Swift/Tests/VisitorBasic.g4",
"./runtime/Swift/Tests/VisitorCalc.g4",
"./runtime/Swift/Tests/LexerA.g4",
"./runtime/Swift/Tests/LexerB.g4",
"./runtime/Swift/Tests/Threading.g4"
]
)
]
Expand Down
128 changes: 126 additions & 2 deletions doc/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,134 @@
# Getting Started with ANTLR v4

Hi and welcome to the version 4 release of ANTLR! It's named after the fearless hero of the [Crazy Nasty-Ass Honey Badger](http://www.youtube.com/watch?v=4r7wHMg5Yjg) since ANTLR v4 takes whatever you give it--it just doesn't give a crap! See [Why do we need ANTLR v4?](faq/general.md) and the [preface of the ANTLR v4 book](http://media.pragprog.com/titles/tpantlr2/preface.pdf).
Hi and welcome to the version 4 release of ANTLR! See [Why do we need ANTLR v4?](faq/general.md) and the [preface of the ANTLR v4 book](http://media.pragprog.com/titles/tpantlr2/preface.pdf).

## Getting started the easy way using antlr4-tools

To play around with ANTLR without having to worry about installing it and the Java needed to execute it, use [antlr4-tools](https://github.com/antlr/antlr4-tools). The only requirement is Python3, which is typically installed on all developer machines on all operating systems. (See below for Windows issue.)

```bash
$ pip install antlr4-tools
```

That command creates `antlr4` and `antlr4-parse` executables that, if necessary, will download and install Java 11 plus the latest ANTLR jar:

```bash
$ antlr4
Downloading antlr4-4.11.1-complete.jar
ANTLR tool needs Java to run; install Java JRE 11 yes/no (default yes)? y
Installed Java in /Users/parrt/.jre/jdk-11.0.15+10-jre; remove that dir to uninstall
ANTLR Parser Generator Version 4.11.1
-o ___ specify output directory where all output is generated
-lib ___ specify location of grammars, tokens files
...
```

Let's play with a simple grammar:

```
grammar Expr;
prog: expr EOF ;
expr: expr ('*'|'/') expr
| expr ('+'|'-') expr
| INT
| '(' expr ')'
;
NEWLINE : [\r\n]+ -> skip;
INT : [0-9]+ ;
```

### Windows-specific issues

On Windows, the `pip` command doesn't just work---you need to add the `...\local-packages\python38\scripts` dir to your `PATH`, which itself might require a fun reboot. If you use WSL on Windows, then the pip install will also properly at the scripts directly (if you run from bash shell).


1. Go to the Microsoft Store
2. Search in Microsoft Store for Python
3. Select the newest version of Python (3.10).
4. Click the "Get" button. Store installs python and pip at "c:\Users...\AppData\Local\Microsoft\WindowsApps\python.exe" and "c:\Users...\AppData\Local\Microsoft\WindowsApps\pip.exe", respectively. And, it updates the search path immediately with the install.
5. Open a "cmd" terminal.
6. You can now type "python" and "pip", and "pip install antlr4-tools". 7. Unfortunately, it does not add that to the search path.
7. Update the search path to contain `c:\Users...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p8\LocalCache\local-packages\Python310\Scripts`. You may need to install MSYS2, then do a `find /c/ -name antlr4.exe 2> /dev/null` and enter that path.
8. Or, you can set up an alias to antlr4.exe on that path.

The good news is that the ANTLR4 Python tool downloads the ANTLR jar in a standard location, and you don't need to do that manually. It's also possible to go in a browser, go to python.org, and download the python package. But, it's likely you will need to update the path for antlr4.exe as before.

### Try parsing with a sample grammar

To parse and get the parse tree in text form, use:

```bash
$ antlr4-parse Expr.g4 prog -tree
10+20*30
^D
(prog:1 (expr:2 (expr:3 10) + (expr:1 (expr:3 20) * (expr:3 30))) <EOF>)
```
(Note: `^D` means control-D and indicates "end of input" on Unix; use `^Z` on Windows.)

Here's how to get the tokens and trace through the parse:

```bash
$ antlr4-parse Expr.g4 prog -tokens -trace
10+20*30
^D
[@0,0:1='10',<INT>,1:0]
[@1,2:2='+',<'+'>,1:2]
[@2,3:4='20',<INT>,1:3]
[@3,5:5='*',<'*'>,1:5]
[@4,6:7='30',<INT>,1:6]
[@5,9:8='<EOF>',<EOF>,2:0]
enter prog, LT(1)=10
enter expr, LT(1)=10
consume [@0,0:1='10',<8>,1:0] rule expr
enter expr, LT(1)=+
consume [@1,2:2='+',<3>,1:2] rule expr
enter expr, LT(1)=20
consume [@2,3:4='20',<8>,1:3] rule expr
enter expr, LT(1)=*
consume [@3,5:5='*',<1>,1:5] rule expr
enter expr, LT(1)=30
consume [@4,6:7='30',<8>,1:6] rule expr
exit expr, LT(1)=<EOF>
exit expr, LT(1)=<EOF>
exit expr, LT(1)=<EOF>
consume [@5,9:8='<EOF>',<-1>,2:0] rule prog
exit prog, LT(1)=<EOF>
```

Here's how to get a visual tree view:

```bash
$ antlr4-parse Expr.g4 prog -gui
10+20*30
^D
```

The following will pop up in a Java-based GUI window:

<img src="https://github.com/antlr/antlr4-tools/blob/master/images/parse-tree.png?raw=true" width="300">

### Generating parser code

The previous section used a built-in ANTLR interpreter but typically you will ask ANTLR to generate code in the language used by your project (there are about 10 languages to choose from as of 4.11). Here's how to generate Java code from a grammar:

```bash
$ antlr4 Expr.g4
$ ls Expr*.java
ExprBaseListener.java ExprLexer.java ExprListener.java ExprParser.java
```

And, here's how to generate C++ code from the same grammar:

```bash
$ antlr4 -Dlanguage=Cpp Expr.g4
$ ls Expr*.cpp Expr*.h
ExprBaseListener.cpp ExprLexer.cpp ExprListener.cpp ExprParser.cpp
ExprBaseListener.h ExprLexer.h ExprListener.h ExprParser.h
```

## Installation

ANTLR is really two things: a tool that translates your grammar to a parser/lexer in Java (or other target language) and the runtime needed by the generated parsers/lexers. Even if you are using the ANTLR Intellij plug-in or ANTLRWorks to run the ANTLR tool, the generated code will still need the runtime library.
ANTLR is really two things: a tool written in Java that translates your grammar to a parser/lexer in Java (or other target language) and the runtime library needed by the generated parsers/lexers. Even if you are using the ANTLR Intellij plug-in or ANTLRWorks to run the ANTLR tool, the generated code will still need the runtime library.

The first thing you should do is probably download and install a development tool plug-in. Even if you only use such tools for editing, they are great. Then, follow the instructions below to get the runtime environment available to your system to run generated parsers/lexers. In what follows, I talk about antlr-4.11.1-complete.jar, which has the tool and the runtime and any other support libraries (e.g., ANTLR v4 is written in v3).

Expand Down
62 changes: 11 additions & 51 deletions doc/releasing-antlr.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,61 +279,24 @@ zip -r ~/antlr/sites/website-antlr4/download/antlr-javascript-runtime-4.11.1.zip

### CSharp

**Install the pre-requisites**
As of writing, you can only release from a Windows box, because Visual Studio for Mac can only build the netstandard2.0 version

You need Mono and `nuget` to be installed. On mac:
**Install the pre-requisites**

- .NET build tools - can be loaded from [here](https://www.visualstudio.com/downloads/) (I need dotnet 5 and 3.1 versions)
- nuget - download [nuget.exe](https://www.nuget.org/downloads)
- dotnet - follow [the instructions here](https://www.microsoft.com/net/core)
You need 'msbuild' and `nuget` to be installed.

Alternatively, you can install Visual Studio 2017 and make sure to check boxes with .NET Core SDK.
**Creating the signed assembly**

You also need to enable .NET Framework 3.5 support in Windows "Programs and Features".
cd ~/antlr/code/antlr4/runtime/CSharp/src
dotnet build -c Release Antlr4.csproj

**Creating the signed assembly**
check that the bin/Release folder contains both the netstandard2.0 and the net45 builds
the binaries are already signed, but it's worth double checking

From Mac:
sn -v bin/Release/netstandard2.0/Antlr4.Runtime.Standard.dll
sn -v bin/Release/net45/Antlr4.Runtime.Standard.dll

```bash
critter:~ $ cd ~/antlr/code/antlr4/runtime/CSharp/src
critter:~/antlr/code/antlr4/runtime/CSharp/src $ dotnet build -c Release Antlr4.csproj
Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore...
Restored /Users/parrt/antlr/code/antlr4/runtime/CSharp/src/Antlr4.csproj (in 340 ms).
Antlr4 -> /Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/netstandard2.0/Antlr4.Runtime.Standard.dll
Successfully created package '/Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/Antlr4.Runtime.Standard.4.11.1.0.nupkg'.

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:06.77
critter:~/antlr/code/antlr4/runtime/CSharp/src $ /Library/Frameworks/Mono.framework/Versions/Current/Commands/sn -R bin/Release/netstandard2.0/Antlr4.Runtime.Standard.dll Antlr4.snk
Mono StrongName - version 6.12.0.0
StrongName utility for signing assemblies
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

Assembly bin/Release/netstandard2.0/Antlr4.Runtime.Standard.dll signed.
critter:~/antlr/code/antlr4/runtime/CSharp/src $ /Library/Frameworks/Mono.framework/Versions/Current/Commands/sn -v bin/Release/netstandard2.0/Antlr4.Runtime.Standard.dll
Mono StrongName - version 6.12.0.0
StrongName utility for signing assemblies
Copyright 2002, 2003 Motus Technologies. Copyright 2004-2008 Novell. BSD licensed.

Assembly bin/Release/netstandard2.0/Antlr4.Runtime.Standard.dll is strongnamed.
$ tree /Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/
/Users/parrt/antlr/code/antlr4/runtime/CSharp/src/bin/Release/
├── Antlr4.Runtime.Standard.4.11.1.0.nupkg
└── netstandard2.0
├── Antlr4.Runtime.Standard.deps.json
├── Antlr4.Runtime.Standard.dll
├── Antlr4.Runtime.Standard.pdb
└── Antlr4.Runtime.Standard.xml

1 directory, 5 files
```
both should say the dll is valid

**Publishing to NuGet**

Expand All @@ -346,9 +309,6 @@ Alternately, you can publish from the cmd line. You need to get your NuGet key f
nuget push Antlr4.Runtime.Standard.<version>.nupkg <your-key> -Source https://www.nuget.org/api/v2/package
```

Nuget packages are also accessible as artifacts of [AppVeyor builds](https://ci.appveyor.com/project/parrt/antlr4/build/artifacts).


### Python

The Python targets get deployed with `setup.py` (Python 2), or `build` and `twine` (Python 3).
Expand Down
3 changes: 2 additions & 1 deletion doc/swift-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ Add Antlr4 as a dependency to your `Package.swift` file. For more information, p


```swift
.package(name: "Antlr4", url: "https://github.com/antlr/antlr4", from: "4.11.1"
.package(url: "https://github.com/antlr/antlr4", from: "4.11.1")
```

## Swift access levels

You may use the `accessLevel` option to control the access levels on generated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Parser
grammar T;
s : e {<writeln("$e.v")>};
e returns [int v]
: e '*' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
: e '*' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| INT{$v = $INT.int;} # anInt
| '(' e ')' {$v = $e.v;} # parens
| left=e INC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "INC()"):Concat(" != null"):Assert()>$v = $left.v + 1;} # unary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Parser
grammar T;
s : e {<writeln("$e.v")>};
e returns [int v]
: e '*' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
: e '*' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| INT{$v = $INT.int;} # anInt
| '(' e ')' {$v = $e.v;} # parens
| left=e INC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "INC()"):Concat(" != null"):Assert()>$v = $left.v + 1;} # unary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Parser
grammar T;
s : e {<writeln("$e.v")>};
e returns [int v]
: e '*' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
: e '*' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| INT{$v = $INT.int;} # anInt
| '(' e ')' {$v = $e.v;} # parens
| left=e INC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "INC()"):Concat(" != null"):Assert()>$v = $left.v + 1;} # unary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Parser
grammar T;
s : e {<writeln("$e.v")>};
e returns [int v]
: e '*' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
: e '*' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| INT{$v = $INT.int;} # anInt
| '(' e ')' {$v = $e.v;} # parens
| left=e INC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "INC()"):Concat(" != null"):Assert()>$v = $left.v + 1;} # unary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Parser
grammar T;
s : e {<writeln("$e.v")>};
e returns [int v]
: e '*' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):ContextMember({<Production("e")>(1)}, {<Result("v")>})>;} # binary
: e '*' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> * <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| e '+' e {$v = <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(0)}, {<Result("v")>})> + <Cast("BinaryContext","$ctx"):SubContextLocal({<Production("e")>(1)}, {<Result("v")>})>;} # binary
| INT{$v = $INT.int;} # anInt
| '(' e ')' {$v = $e.v;} # parens
| left=e INC {<ContextRuleFunction(Cast("UnaryContext","$ctx"), "INC()"):Concat(" != null"):Assert()>$v = $left.v + 1;} # unary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ grammar T;

s
@after {
<ContextRuleFunction("$ctx", "r"):ToStringTree():writeln()>
<ContextRuleFunction("$ctx", "r"):WalkListener()>
<ContextMember("$ctx", "r"):ToStringTree():writeln()>
<ContextMember("$ctx", "r"):WalkListener()>
}
: r=a ;
a : INT INT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ grammar T;

s
@after {
<ContextRuleFunction("$ctx", "r"):ToStringTree():writeln()>
<ContextRuleFunction("$ctx", "r"):WalkListener()>
<ContextMember("$ctx", "r"):ToStringTree():writeln()>
<ContextMember("$ctx", "r"):WalkListener()>
}
: r=e ;
e : e op='*' e
Expand Down
Loading