Skip to content

Commit b77cb52

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into fix-nodenext-module-resolution
; Conflicts: ; runtime/JavaScript/package.json
2 parents 67244f2 + 88a0c7a commit b77cb52

Some content is hidden

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

48 files changed

+718
-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

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ You might also find the following pages useful, particularly if you want to mess
9696

9797
Programmers run into parsing problems all the time. Whether it’s a data format like JSON, a network protocol like SMTP, a server configuration file for Apache, a PostScript/PDF file, or a simple spreadsheet macro language—ANTLR v4 and this book will demystify the process. ANTLR v4 has been rewritten from scratch to make it easier than ever to build parsers and the language applications built on top. This completely rewritten new edition of the bestselling Definitive ANTLR Reference shows you how to take advantage of these new features.
9898

99-
You can buy the book [The Definitive ANTLR 4 Reference](http://amzn.com/1934356999) at amazon or an [electronic version at the publisher's site](https://pragprog.com/book/tpantlr2/the-definitive-antlr-4-reference).
99+
You can buy the book [The Definitive ANTLR 4 Reference](http://amzn.com/dp/1934356999) at amazon or an [electronic version at the publisher's site](https://pragprog.com/book/tpantlr2/the-definitive-antlr-4-reference).
100100

101101
You will find the [Book source code](http://pragprog.com/titles/tpantlr2/source_code) useful.
102102

doc/cpp-target.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# C++
22

3-
The C++ target supports all platforms that can either run MS Visual Studio 2013 (or newer), XCode 7 (or newer) or CMake (C++11 required). All build tools can either create static or dynamic libraries, both as 64bit or 32bit arch. Additionally, XCode can create an iOS library. Also see [Antlr4 for C++ with CMake: A practical example](http://blorente.me/beyond-the-loop/Antlr-cpp-cmake/).
3+
The C++ target supports all platforms that can either run MS Visual Studio 2017 (or newer), XCode 7 (or newer) or CMake (C++17 required). All build tools can either create static or dynamic libraries, both as 64bit or 32bit arch. Additionally, XCode can create an iOS library. Also see [Antlr4 for C++ with CMake: A practical example](http://blorente.me/beyond-the-loop/Antlr-cpp-cmake/).
44

55
## How to create a C++ lexer or parser?
66
This is pretty much the same as creating a Java lexer or parser, except you need to specify the language target, for example:

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?

runtime/Cpp/runtime/CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ if (NOT ANTLR_BUILD_SHARED AND NOT ANTLR_BUILD_STATIC)
77
message(FATAL_ERROR "Options ANTLR_BUILD_SHARED and ANTLR_BUILD_STATIC can't both be OFF")
88
endif()
99

10-
include_directories(
10+
set(libantlrcpp_INCLUDE_INSTALL_DIR "include/antlr4-runtime")
11+
12+
set(libantlrcpp_INCLUDE_DIRS
1113
${PROJECT_SOURCE_DIR}/runtime/src
1214
${PROJECT_SOURCE_DIR}/runtime/src/atn
1315
${PROJECT_SOURCE_DIR}/runtime/src/dfa
@@ -34,9 +36,15 @@ file(GLOB libantlrcpp_SRC
3436

3537
if (ANTLR_BUILD_SHARED)
3638
add_library(antlr4_shared SHARED ${libantlrcpp_SRC})
39+
target_include_directories(antlr4_shared PUBLIC
40+
"$<BUILD_INTERFACE:${libantlrcpp_INCLUDE_DIRS}>"
41+
"$<INSTALL_INTERFACE:${libantlrcpp_INCLUDE_INSTALL_DIR}>")
3742
endif()
3843
if (ANTLR_BUILD_STATIC)
3944
add_library(antlr4_static STATIC ${libantlrcpp_SRC})
45+
target_include_directories(antlr4_static PUBLIC
46+
"$<BUILD_INTERFACE:${libantlrcpp_INCLUDE_DIRS}>"
47+
"$<INSTALL_INTERFACE:${libantlrcpp_INCLUDE_INSTALL_DIR}>")
4048
endif()
4149

4250
if (CMAKE_HOST_UNIX)
@@ -185,7 +193,7 @@ if (TARGET antlr4_static)
185193
endif()
186194

187195
install(DIRECTORY "${PROJECT_SOURCE_DIR}/runtime/src/"
188-
DESTINATION "include/antlr4-runtime"
196+
DESTINATION "${libantlrcpp_INCLUDE_INSTALL_DIR}"
189197
COMPONENT dev
190198
FILES_MATCHING PATTERN "*.h"
191199
)

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/Cpp/runtime/src/atn/ATNDeserializationOptions.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ATNDeserializationOptions::ATNDeserializationOptions(ATNDeserializationOptions *
1414
_generateRuleBypassTransitions(options->_generateRuleBypassTransitions) {}
1515

1616
const ATNDeserializationOptions& ATNDeserializationOptions::getDefaultOptions() {
17-
static const ATNDeserializationOptions* const defaultOptions = new ATNDeserializationOptions();
17+
static const std::unique_ptr<const ATNDeserializationOptions> defaultOptions = std::make_unique<const ATNDeserializationOptions>();
1818
return *defaultOptions;
1919
}
2020

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)