Skip to content

Commit 25629c4

Browse files
authored
Merge branch 'antlr:dev' into patch-1
2 parents 3e20d40 + 5435f14 commit 25629c4

File tree

365 files changed

+2108
-679
lines changed

Some content is hidden

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

365 files changed

+2108
-679
lines changed

.github/workflows/hosted.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
os: [
24-
macos-12,
24+
macos-15,
2525
ubuntu-20.04,
2626
windows-2022
2727
]
@@ -147,7 +147,7 @@ jobs:
147147
- name: Archive artifacts
148148
if: always()
149149
continue-on-error: true
150-
uses: actions/upload-artifact@v3
150+
uses: actions/upload-artifact@v4
151151
with:
152152
name: antlr_${{ matrix.os }}_${{ matrix.compiler }}
153153
path: antlr_${{ matrix.os }}_${{ matrix.compiler }}.tgz
@@ -160,7 +160,7 @@ jobs:
160160
fail-fast: false
161161
matrix:
162162
os: [
163-
macos-12,
163+
macos-15,
164164
ubuntu-20.04,
165165
windows-2022
166166
]
@@ -336,7 +336,7 @@ jobs:
336336
- name: Archive artifacts
337337
if: always()
338338
continue-on-error: true
339-
uses: actions/upload-artifact@v3
339+
uses: actions/upload-artifact@v4
340340
with:
341341
name: antlr_${{ matrix.os }}_${{ matrix.target }}
342342
path: antlr_${{ matrix.os }}_${{ matrix.target }}.tgz

docker/Dockerfile

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM eclipse-temurin:11 AS builder
1+
FROM eclipse-temurin:21 AS builder
22

33
WORKDIR /opt/antlr4
44

@@ -14,23 +14,8 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install maven git -
1414
&& mvn -DskipTests install --projects tool --also-make \
1515
&& mv ./tool/target/antlr4-*-complete.jar antlr4-tool.jar
1616

17-
FROM eclipse-temurin:11-jre
18-
19-
ARG user=appuser
20-
ARG group=appuser
21-
ARG uid=1000
22-
ARG gid=1000
23-
24-
RUN adduser \
25-
--disabled-password \
26-
--gecos "" \
27-
--home "$(pwd)" \
28-
--no-create-home \
29-
--uid "${uid}" \
30-
"${user}"
17+
FROM eclipse-temurin:21-jre
3118

3219
COPY --from=builder /opt/antlr4/antlr4/antlr4-tool.jar /usr/local/lib/
3320
WORKDIR /work
3421
ENTRYPOINT ["java", "-Xmx500M", "-cp", "/usr/local/lib/antlr4-tool.jar", "org.antlr.v4.Tool"]
35-
36-

runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/TypeScript.test.stg

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
writeln(s) ::= <<console.log(<s> || '');>>
2-
write(s) ::= <<process.stdout.write(<s> || '');>>
1+
writeln(s) ::= <<console.log(<s>);>>
2+
write(s) ::= <<process.stdout.write(<s>);>>
33
writeList(s) ::= <<console.log(<s; separator="+">);>>
44

55
False() ::= "false"

runtime/CSharp/src/Atn/ATN.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ public class ATN
7777
private readonly PredictionContextCache contextCache = new PredictionContextCache();
7878

7979
[NotNull]
80-
public DFA[] decisionToDFA = new DFA[0];
80+
public DFA[] decisionToDFA = Collections.EmptyList<DFA>();
8181

8282
[NotNull]
83-
public DFA[] modeToDFA = new DFA[0];
83+
public DFA[] modeToDFA = Collections.EmptyList<DFA>();
8484

8585
protected internal readonly ConcurrentDictionary<int, int> LL1Table = new ConcurrentDictionary<int, int>();
8686

runtime/CSharp/src/Dfa/DFA.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public DFA(DecisionState atnStartState, int decision)
4646
{
4747
this.precedenceDfa = true;
4848
DFAState precedenceState = new DFAState(new ATNConfigSet());
49-
precedenceState.edges = new DFAState[0];
49+
precedenceState.edges = Collections.EmptyList<DFAState>();
5050
precedenceState.isAcceptState = false;
5151
precedenceState.requiresFullContext = false;
5252
this.s0 = precedenceState;

runtime/CSharp/src/LexerInterpreter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class LexerInterpreter: Lexer
3333

3434
[Obsolete("Use constructor with channelNames argument")]
3535
public LexerInterpreter(string grammarFileName, IVocabulary vocabulary, IEnumerable<string> ruleNames, IEnumerable<string> modeNames, ATN atn, ICharStream input)
36-
: this(grammarFileName, vocabulary, ruleNames, new string[0], modeNames, atn, input)
36+
: this(grammarFileName, vocabulary, ruleNames, Collections.EmptyList<string>(), modeNames, atn, input)
3737
{
3838
}
3939

runtime/CSharp/src/Recognizer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Runtime.CompilerServices;
88
using Antlr4.Runtime.Atn;
99
using Antlr4.Runtime.Misc;
10+
using Antlr4.Runtime.Sharpen;
1011

1112
namespace Antlr4.Runtime
1213
{
@@ -286,7 +287,7 @@ public virtual void RemoveErrorListener(IAntlrErrorListener<Symbol> listener)
286287

287288
public virtual void RemoveErrorListeners()
288289
{
289-
_listeners = new IAntlrErrorListener<Symbol>[0];
290+
_listeners = Collections.EmptyList<IAntlrErrorListener<Symbol>>();
290291
}
291292

292293
[NotNull]

runtime/CSharp/src/Sharpen/BitSet.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Antlr4.Runtime.Sharpen
99

1010
public class BitSet
1111
{
12-
private static readonly ulong[] EmptyBits = new ulong[0];
12+
private static readonly ulong[] EmptyBits = Collections.EmptyList<ulong>();
1313
private const int BitsPerElement = 8 * sizeof(ulong);
1414

1515
private ulong[] _data = EmptyBits;

runtime/CSharp/src/Sharpen/Collections.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ namespace Antlr4.Runtime.Sharpen
99

1010
internal static class Collections
1111
{
12-
public static T[] EmptyList<T>()
12+
/// <remarks>
13+
/// Available in .NET as Array.Empty but not to the net45 target.
14+
/// See: https://learn.microsoft.com/dotnet/api/system.array.empty.
15+
/// </remarks>
16+
public static T[] EmptyList<T>()
1317
{
1418
return EmptyListImpl<T>.Instance;
1519
}
@@ -31,10 +35,13 @@ public static ReadOnlyDictionary<TKey, TValue> SingletonMap<TKey, TValue>(TKey k
3135

3236
private static class EmptyListImpl<T>
3337
{
34-
public static readonly T[] Instance = new T[0];
35-
}
38+
#pragma warning disable CA1825
39+
// Provides a solution for CA1825.
40+
public static readonly T[] Instance = new T[0];
41+
#pragma warning restore CA1825
42+
}
3643

37-
private static class EmptyMapImpl<TKey, TValue>
44+
private static class EmptyMapImpl<TKey, TValue>
3845
{
3946
public static readonly ReadOnlyDictionary<TKey, TValue> Instance =
4047
new ReadOnlyDictionary<TKey, TValue>(new Dictionary<TKey, TValue>());

runtime/CSharp/src/Vocabulary.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Antlr4.Runtime
1616
/// <author>Sam Harwell</author>
1717
public class Vocabulary : IVocabulary
1818
{
19-
private static readonly string[] EmptyNames = new string[0];
19+
private static readonly string[] EmptyNames = Collections.EmptyList<string>();
2020

2121
/// <summary>
2222
/// Gets an empty

runtime/Cpp/cmake/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ By defualt the ANTLR C++ runtime source is cloned from GitHub. However, users ma
137137

138138
Visual C++ compiler users may want to additionally define `ANTLR4_WITH_STATIC_CRT` before including the file. Set `ANTLR4_WITH_STATIC_CRT` to true if ANTLR4 C++ runtime library should be compiled with `/MT` flag, otherwise will be compiled with `/MD` flag. This variable has a default value of `OFF`. Changing `ANTLR4_WITH_STATIC_CRT` after building the library may require reinitialization of CMake or `clean` for the library to get rebuilt.
139139

140-
You may need to modify your local copy of ExternalAntlr4Cpp.cpp to modify some build settings. For example, to specify the C++ standard to use when building the runtime, add `-DCMAKE_CXX_STANDARD:STRING=17` to `CMAKE_CACHE_ARGS`.
140+
You may need to modify your local copy of ExternalAntlr4Cpp.cmake to modify some build settings. For example, to specify the C++ standard to use when building the runtime, add `-DCMAKE_CXX_STANDARD:STRING=17` to `CMAKE_CACHE_ARGS`.
141141

142142
### Examples
143143

runtime/Cpp/runtime/src/ANTLRErrorListener.h

100755100644
+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
#pragma once
77

8+
#include <exception>
9+
#include <string>
10+
#include <cstddef>
11+
#include "antlr4-common.h"
12+
#include "Token.h"
813
#include "RecognitionException.h"
914

1015
namespace antlrcpp {

runtime/Cpp/runtime/src/ANTLRErrorStrategy.h

100755100644
+3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
#pragma once
77

8+
#include <exception>
9+
#include "antlr4-common.h"
810
#include "Token.h"
911

1012
namespace antlr4 {
13+
class Parser;
1114

1215
/// <summary>
1316
/// The interface for defining strategies to deal with syntax errors encountered

runtime/Cpp/runtime/src/ANTLRFileStream.cpp

100755100644
+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* can be found in the LICENSE.txt file in the project root.
44
*/
55

6+
#include <string>
7+
#include "ANTLRInputStream.h"
68
#include "ANTLRFileStream.h"
79

810
using namespace antlr4;

runtime/Cpp/runtime/src/ANTLRFileStream.h

100755100644
+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#pragma once
77

8+
#include <string>
9+
#include <cstddef>
10+
#include "antlr4-common.h"
811
#include "ANTLRInputStream.h"
912

1013
namespace antlr4 {
@@ -21,7 +24,7 @@ namespace antlr4 {
2124

2225
// Assumes a file name encoded in UTF-8 and file content in the same encoding (with or w/o BOM).
2326
virtual void loadFromFile(const std::string &fileName);
24-
virtual std::string getSourceName() const override;
27+
std::string getSourceName() const override;
2528

2629
private:
2730
std::string _fileName; // UTF-8 encoded file name.

runtime/Cpp/runtime/src/ANTLRInputStream.cpp

100755100644
+5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
* can be found in the LICENSE.txt file in the project root.
44
*/
55

6+
#include <string_view>
7+
#include <cassert>
8+
#include <utility>
9+
#include <string>
610
#include <string.h>
711

812
#include "Exceptions.h"
13+
#include "antlr4-common.h"
914
#include "misc/Interval.h"
1015
#include "IntStream.h"
1116

runtime/Cpp/runtime/src/ANTLRInputStream.h

100755100644
+14-10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
#pragma once
77

8+
#include <string>
9+
#include <cstddef>
810
#include <string_view>
911

12+
#include "antlr4-common.h"
13+
#include "misc/Interval.h"
1014
#include "CharStream.h"
1115

1216
namespace antlr4 {
@@ -46,31 +50,31 @@ namespace antlr4 {
4650
/// when the object was created *except* the data array is not
4751
/// touched.
4852
virtual void reset();
49-
virtual void consume() override;
50-
virtual size_t LA(ssize_t i) override;
53+
void consume() override;
54+
size_t LA(ssize_t i) override;
5155
virtual size_t LT(ssize_t i);
5256

5357
/// <summary>
5458
/// Return the current input symbol index 0..n where n indicates the
5559
/// last symbol has been read. The index is the index of char to
5660
/// be returned from LA(1).
5761
/// </summary>
58-
virtual size_t index() override;
59-
virtual size_t size() override;
62+
size_t index() override;
63+
size_t size() override;
6064

6165
/// <summary>
6266
/// mark/release do nothing; we have entire buffer </summary>
63-
virtual ssize_t mark() override;
64-
virtual void release(ssize_t marker) override;
67+
ssize_t mark() override;
68+
void release(ssize_t marker) override;
6569

6670
/// <summary>
6771
/// consume() ahead until p==index; can't just set p=index as we must
6872
/// update line and charPositionInLine. If we seek backwards, just set p
6973
/// </summary>
70-
virtual void seek(size_t index) override;
71-
virtual std::string getText(const misc::Interval &interval) override;
72-
virtual std::string getSourceName() const override;
73-
virtual std::string toString() const override;
74+
void seek(size_t index) override;
75+
std::string getText(const misc::Interval &interval) override;
76+
std::string getSourceName() const override;
77+
std::string toString() const override;
7478

7579
private:
7680
void InitializeInstanceFields();

runtime/Cpp/runtime/src/BailErrorStrategy.cpp

100755100644
+2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
* can be found in the LICENSE.txt file in the project root.
44
*/
55

6+
#include <exception>
67
#include "Exceptions.h"
8+
#include "Token.h"
79
#include "ParserRuleContext.h"
810
#include "InputMismatchException.h"
911
#include "Parser.h"

runtime/Cpp/runtime/src/BailErrorStrategy.h

100755100644
+6-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#pragma once
77

8+
#include <exception>
9+
#include "antlr4-common.h"
10+
#include "Token.h"
811
#include "DefaultErrorStrategy.h"
912

1013
namespace antlr4 {
@@ -45,15 +48,15 @@ namespace antlr4 {
4548
/// original <seealso cref="RecognitionException"/>.
4649
/// </summary>
4750
public:
48-
virtual void recover(Parser *recognizer, std::exception_ptr e) override;
51+
void recover(Parser *recognizer, std::exception_ptr e) override;
4952

5053
/// Make sure we don't attempt to recover inline; if the parser
5154
/// successfully recovers, it won't throw an exception.
52-
virtual Token* recoverInline(Parser *recognizer) override;
55+
Token* recoverInline(Parser *recognizer) override;
5356

5457
/// <summary>
5558
/// Make sure we don't attempt to recover from problems in subrules. </summary>
56-
virtual void sync(Parser *recognizer) override;
59+
void sync(Parser *recognizer) override;
5760
};
5861

5962
} // namespace antlr4

runtime/Cpp/runtime/src/BaseErrorListener.cpp

100755100644
+4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* can be found in the LICENSE.txt file in the project root.
44
*/
55

6+
#include <exception>
7+
#include <string>
8+
#include <cstddef>
69
#include "BaseErrorListener.h"
10+
#include "Token.h"
711
#include "RecognitionException.h"
812

913
using namespace antlr4;

runtime/Cpp/runtime/src/BaseErrorListener.h

100755100644
+9-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
#pragma once
77

8+
#include <exception>
9+
#include <string>
10+
#include <cstddef>
11+
#include "antlr4-common.h"
12+
#include "Token.h"
813
#include "ANTLRErrorListener.h"
914

1015
namespace antlrcpp {
@@ -20,16 +25,16 @@ namespace antlr4 {
2025
*/
2126
class ANTLR4CPP_PUBLIC BaseErrorListener : public ANTLRErrorListener {
2227

23-
virtual void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine,
28+
void syntaxError(Recognizer *recognizer, Token * offendingSymbol, size_t line, size_t charPositionInLine,
2429
const std::string &msg, std::exception_ptr e) override;
2530

26-
virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
31+
void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
2732
const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override;
2833

29-
virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
34+
void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
3035
const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override;
3136

32-
virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
37+
void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
3338
size_t prediction, atn::ATNConfigSet *configs) override;
3439
};
3540

0 commit comments

Comments
 (0)