Skip to content

Commit b3a4591

Browse files
committed
Merge remote-tracking branch 'ups/dev' into force-compile
2 parents 6ea7057 + 2647323 commit b3a4591

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+723
-189
lines changed

.github/workflows/hosted.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
os: [
24-
macos-11,
24+
macos-12,
2525
ubuntu-20.04,
2626
windows-2022
2727
]
@@ -160,7 +160,7 @@ jobs:
160160
fail-fast: false
161161
matrix:
162162
os: [
163-
macos-11,
163+
macos-12,
164164
ubuntu-20.04,
165165
windows-2022
166166
]
@@ -196,6 +196,14 @@ jobs:
196196
repository: antlr/antlr-php-runtime
197197
path: runtime/PHP
198198

199+
- name: Setup PHP 8.2
200+
if: matrix.target == 'php'
201+
uses: shivammathur/setup-php@v2
202+
with:
203+
php-version: '8.3'
204+
extensions: mbstring
205+
tools: composer
206+
199207
- name: Install dependencies
200208
env:
201209
COMPOSER_CACHE_DIR: ${{ github.workspace }}/.cache
@@ -263,14 +271,6 @@ jobs:
263271
with:
264272
go-version: '^1.19'
265273

266-
- name: Setup PHP 8.2
267-
if: matrix.target == 'php'
268-
uses: shivammathur/[email protected]
269-
with:
270-
php-version: '8.2'
271-
extensions: mbstring
272-
tools: composer
273-
274274
- name: Setup Swift
275275
if: matrix.target == 'swift'
276276
uses: swift-actions/[email protected]

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
## Versioning
2323

2424
ANTLR 4 supports 10 target languages
25-
(Cpp, CSharp, Dart, Java, JavaScript, PHP, Python3, Swift, TypeScript),
25+
(Cpp, CSharp, Dart, Java, JavaScript, PHP, Python3, Swift, TypeScript, Go),
2626
and ensuring consistency across these targets is a unique and highly valuable feature.
2727
To ensure proper support of this feature, each release of ANTLR is a complete release of the tool and the 10 runtimes, all with the same version.
2828
As such, ANTLR versioning does not strictly follow semver semantics:
@@ -54,7 +54,7 @@ The dedicated Go repo is for `go get` and `import` only. Go runtime development
5454
ANTLR project lead and supreme dictator for life
5555
[University of San Francisco](http://www.usfca.edu/)
5656
* [Sam Harwell](http://tunnelvisionlabs.com/) (Tool co-author, Java and original C# target)
57-
* [Eric Vergnaud](https://github.com/ericvergnaud) (Javascript, Python2, Python3 targets and maintenance of C# target)
57+
* [Eric Vergnaud](https://github.com/ericvergnaud) (Javascript, TypeScript, Python2, Python3 targets and maintenance of C# target)
5858
* [Peter Boyer](https://github.com/pboyer) (Go target)
5959
* [Mike Lischke](http://www.soft-gems.net/) (C++ completed target)
6060
* Dan McLaughlin (C++ initial target)
@@ -77,7 +77,7 @@ ANTLR project lead and supreme dictator for life
7777
* [Official site](http://www.antlr.org/)
7878
* [Documentation](https://github.com/antlr/antlr4/blob/master/doc/index.md)
7979
* [FAQ](https://github.com/antlr/antlr4/blob/master/doc/faq/index.md)
80-
* [ANTLR code generation targets](https://github.com/antlr/antlr4/blob/master/doc/targets.md)<br>(Currently: Java, C#, Python3, JavaScript, Go, C++, Swift, Dart, PHP)
80+
* [ANTLR code generation targets](https://github.com/antlr/antlr4/blob/master/doc/targets.md)<br>(Currently: Java, C#, Python3, JavaScript, TypeScript, Go, C++, Swift, Dart, PHP)
8181
* _Note: As of version 4.14, we are dropping support for Python 2. We love the Python
8282
community, but Python 2 support was officially halted in Jan 2020. More recently,
8383
GiHub also dropped support for Python 2, which has made it impossible for us to

doc/javascript-target.md

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ Once you've generated the lexer and/or parser code, you need to download the run
4040

4141
The JavaScript runtime is [available from npm](https://www.npmjs.com/package/antlr4).
4242

43-
If you can't use npm, the JavaScript runtime is also available from the ANTLR web site [download section](http://www.antlr.org/download/index.html). The runtime is provided in the form of source code, so no additional installation is required.
44-
4543
We will not document here how to refer to the runtime from your project, since this would differ a lot depending on your project type and IDE.
4644

4745
## How do I get the runtime in my browser?

doc/python-target.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ must include a reference to the Antlr Python3 runtime.
5050
You should provide a script that builds the program.
5151
```
5252
pip install -r requirements.txt
53-
antlr4 -v 4.13.0 -Dlanguage=Python3 Expr.g4
53+
antlr4 -Dlanguage=Python3 Expr.g4
5454
```
5555
_It is vital that the versions for the
5656
Antlr tool used to generate the parser

runtime/Cpp/cmake/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ set(ANTLR4_WITH_STATIC_CRT OFF)
3434
3535
# add external build for antlrcpp
3636
include(ExternalAntlr4Cpp)
37-
# add antrl4cpp artifacts to project environment
37+
# add antlr4cpp artifacts to project environment
3838
include_directories(${ANTLR4_INCLUDE_DIRS})
3939
4040
# set variable pointing to the antlr tool that supports C++

runtime/Cpp/runtime/src/TokenStreamRewriter.cpp

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
1+
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
22
* Use of this file is governed by the BSD 3-clause license that
33
* can be found in the LICENSE.txt file in the project root.
44
*/
@@ -313,6 +313,10 @@ std::string TokenStreamRewriter::getText(const std::string &programName, const I
313313
std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRewriter::reduceToSingleOperationPerIndex(
314314
std::vector<TokenStreamRewriter::RewriteOperation*> &rewrites) {
315315

316+
// Reset the instructionIndex
317+
for (size_t i = 0; i < rewrites.size(); ++i) {
318+
rewrites[i]->instructionIndex = i;
319+
}
316320

317321
// WALK REPLACES
318322
for (size_t i = 0; i < rewrites.size(); ++i) {
@@ -327,35 +331,34 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
327331
if (iop->index == rop->index) {
328332
// E.g., insert before 2, delete 2..2; update replace
329333
// text to include insert before, kill insert
330-
delete rewrites[iop->instructionIndex];
331-
rewrites[iop->instructionIndex] = nullptr;
332334
rop->text = iop->text + (!rop->text.empty() ? rop->text : "");
335+
rewrites[iop->instructionIndex] = nullptr;
336+
delete iop;
333337
}
334338
else if (iop->index > rop->index && iop->index <= rop->lastIndex) {
335339
// delete insert as it's a no-op.
336-
delete rewrites[iop->instructionIndex];
337340
rewrites[iop->instructionIndex] = nullptr;
341+
delete iop;
338342
}
339343
}
340344
// Drop any prior replaces contained within
341345
std::vector<ReplaceOp*> prevReplaces = getKindOfOps<ReplaceOp>(rewrites, i);
342346
for (auto *prevRop : prevReplaces) {
343347
if (prevRop->index >= rop->index && prevRop->lastIndex <= rop->lastIndex) {
344348
// delete replace as it's a no-op.
345-
delete rewrites[prevRop->instructionIndex];
346349
rewrites[prevRop->instructionIndex] = nullptr;
350+
delete prevRop;
347351
continue;
348352
}
349353
// throw exception unless disjoint or identical
350354
bool disjoint = prevRop->lastIndex < rop->index || prevRop->index > rop->lastIndex;
351355
// Delete special case of replace (text==null):
352356
// D.i-j.u D.x-y.v | boundaries overlap combine to max(min)..max(right)
353357
if (prevRop->text.empty() && rop->text.empty() && !disjoint) {
354-
delete rewrites[prevRop->instructionIndex];
355-
rewrites[prevRop->instructionIndex] = nullptr; // kill first delete
356358
rop->index = std::min(prevRop->index, rop->index);
357359
rop->lastIndex = std::max(prevRop->lastIndex, rop->lastIndex);
358-
std::cout << "new rop " << rop << std::endl;
360+
rewrites[prevRop->instructionIndex] = nullptr; // kill first delete
361+
delete prevRop;
359362
}
360363
else if (!disjoint) {
361364
throw IllegalArgumentException("replace op boundaries of " + rop->toString() +
@@ -379,8 +382,8 @@ std::unordered_map<size_t, TokenStreamRewriter::RewriteOperation*> TokenStreamRe
379382
// whole token buffer so no lazy eval issue with any templates
380383
iop->text = catOpText(&iop->text, &prevIop->text);
381384
// delete redundant prior insert
382-
delete rewrites[prevIop->instructionIndex];
383385
rewrites[prevIop->instructionIndex] = nullptr;
386+
delete prevIop;
384387
}
385388
}
386389
// look for replaces where iop.index is in range; error

runtime/Go/antlr/README.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Your driver code etc. should now be importing from the new release only repo for
1010

1111
```go
1212
import (
13-
github.com/antlr4-go/antlr
13+
"github.com/antlr4-go/antlr"
1414
)
1515
```
1616

runtime/Go/antlr/go.sum

-2
This file was deleted.

runtime/Go/antlr/v4/atn.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package antlr
66

7-
import "sync"
8-
97
// ATNInvalidAltNumber is used to represent an ALT number that has yet to be calculated or
108
// which is invalid for a particular struct such as [*antlr.BaseRuleContext]
119
var ATNInvalidAltNumber int
@@ -56,9 +54,9 @@ type ATN struct {
5654
//
5755
states []ATNState
5856

59-
mu sync.Mutex
60-
stateMu sync.RWMutex
61-
edgeMu sync.RWMutex
57+
mu Mutex
58+
stateMu RWMutex
59+
edgeMu RWMutex
6260
}
6361

6462
// NewATN returns a new ATN struct representing the given grammarType and is used

runtime/Go/antlr/v4/atn_config.go

-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ func NewATNConfig1(c *ATNConfig, state ATNState, context *PredictionContext) *AT
7373
// NewATNConfig creates a new ATNConfig instance given an existing config, a state, a context and a semantic context, other 'constructors'
7474
// are just wrappers around this one.
7575
func NewATNConfig(c *ATNConfig, state ATNState, context *PredictionContext, semanticContext SemanticContext) *ATNConfig {
76-
if semanticContext == nil {
77-
panic("semanticContext cannot be nil") // TODO: Remove this - probably put here for some bug that is now fixed
78-
}
7976
b := &ATNConfig{}
8077
b.InitATNConfig(c, state, c.GetAlt(), context, semanticContext)
8178
b.cType = parserConfig

runtime/Go/antlr/v4/jcollect.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"container/list"
99
"runtime/debug"
1010
"sort"
11-
"sync"
1211
)
1312

1413
// Collectable is an interface that a struct should implement if it is to be
@@ -587,12 +586,12 @@ type VisitRecord struct {
587586

588587
type VisitList struct {
589588
cache *list.List
590-
lock sync.RWMutex
589+
lock RWMutex
591590
}
592591

593592
var visitListPool = VisitList{
594593
cache: list.New(),
595-
lock: sync.RWMutex{},
594+
lock: RWMutex{},
596595
}
597596

598597
// NewVisitRecord returns a new VisitRecord instance from the pool if available.

runtime/Go/antlr/v4/ll1_analyzer.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (la *LL1Analyzer) getDecisionLookahead(s ATNState) []*IntervalSet {
4040
for alt := 0; alt < count; alt++ {
4141

4242
look[alt] = NewIntervalSet()
43+
// TODO: This is one of the reasons that ATNConfigs are allocated and freed all the time - fix this tomorrow jim!
4344
lookBusy := NewJStore[*ATNConfig, Comparator[*ATNConfig]](aConfEqInst, ClosureBusyCollection, "LL1Analyzer.getDecisionLookahead for lookBusy")
4445
la.look1(s.GetTransitions()[alt].getTarget(), nil, BasePredictionContextEMPTY, look[alt], lookBusy, NewBitSet(), false, false)
4546

runtime/Go/antlr/v4/mutex.go

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//go:build !antlr.nomutex
2+
// +build !antlr.nomutex
3+
4+
package antlr
5+
6+
import "sync"
7+
8+
// Mutex is a simple mutex implementation which just delegates to sync.Mutex, it
9+
// is used to provide a mutex implementation for the antlr package, which users
10+
// can turn off with the build tag -tags antlr.nomutex
11+
type Mutex struct {
12+
mu sync.Mutex
13+
}
14+
15+
func (m *Mutex) Lock() {
16+
m.mu.Lock()
17+
}
18+
19+
func (m *Mutex) Unlock() {
20+
m.mu.Unlock()
21+
}
22+
23+
type RWMutex struct {
24+
mu sync.RWMutex
25+
}
26+
27+
func (m *RWMutex) Lock() {
28+
m.mu.Lock()
29+
}
30+
31+
func (m *RWMutex) Unlock() {
32+
m.mu.Unlock()
33+
}
34+
35+
func (m *RWMutex) RLock() {
36+
m.mu.RLock()
37+
}
38+
39+
func (m *RWMutex) RUnlock() {
40+
m.mu.RUnlock()
41+
}

runtime/Go/antlr/v4/mutex_nomutex.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// +build antlr.nomutex
2+
3+
package antlr
4+
5+
type Mutex struct{}
6+
7+
func (m *Mutex) Lock() {
8+
// No-op
9+
}
10+
11+
func (m *Mutex) Unlock() {
12+
// No-op
13+
}
14+
15+
type RWMutex struct{}
16+
17+
func (m *RWMutex) Lock() {
18+
// No-op
19+
}
20+
21+
func (m *RWMutex) Unlock() {
22+
// No-op
23+
}
24+
25+
func (m *RWMutex) RLock() {
26+
// No-op
27+
}
28+
29+
func (m *RWMutex) RUnlock() {
30+
// No-op
31+
}

runtime/Go/antlr/v4/prediction_context.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package antlr
66

77
import (
88
"fmt"
9-
"golang.org/x/exp/slices"
109
"strconv"
1110
)
1211

@@ -115,6 +114,9 @@ func (p *PredictionContext) Hash() int {
115114
}
116115

117116
func (p *PredictionContext) Equals(other Collectable[*PredictionContext]) bool {
117+
if p == other {
118+
return true
119+
}
118120
switch p.pcType {
119121
case PredictionContextEmpty:
120122
otherP := other.(*PredictionContext)
@@ -141,18 +143,16 @@ func (p *PredictionContext) ArrayEquals(o Collectable[*PredictionContext]) bool
141143

142144
// Must compare the actual array elements and not just the array address
143145
//
144-
return slices.Equal(p.returnStates, other.returnStates) &&
145-
slices.EqualFunc(p.parents, other.parents, func(x, y *PredictionContext) bool {
146-
return x.Equals(y)
147-
})
146+
return intSlicesEqual(p.returnStates, other.returnStates) &&
147+
pcSliceEqual(p.parents, other.parents)
148148
}
149149

150150
func (p *PredictionContext) SingletonEquals(other Collectable[*PredictionContext]) bool {
151151
if other == nil {
152152
return false
153153
}
154154
otherP := other.(*PredictionContext)
155-
if otherP == nil {
155+
if otherP == nil || otherP.pcType != PredictionContextSingleton {
156156
return false
157157
}
158158

runtime/Go/antlr/v4/statistics.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path/filepath"
1010
"sort"
1111
"strconv"
12-
"sync"
1312
)
1413

1514
// This file allows the user to collect statistics about the runtime of the ANTLR runtime. It is not enabled by default
@@ -30,7 +29,7 @@ type goRunStats struct {
3029
// within this package.
3130
//
3231
jStats []*JStatRec
33-
jStatsLock sync.RWMutex
32+
jStatsLock RWMutex
3433
topN int
3534
topNByMax []*JStatRec
3635
topNByUsed []*JStatRec

0 commit comments

Comments
 (0)