Skip to main content

antlr4_runtime/
lib.rs

1//! Clean-room ANTLR v4 runtime foundation for Rust.
2
3pub mod atn;
4pub mod char_stream;
5pub mod dfa;
6pub mod errors;
7pub mod generated;
8pub mod int_stream;
9pub mod lexer;
10pub mod parser;
11#[cfg(feature = "perf-counters")]
12pub mod perf;
13pub mod prediction;
14pub mod recognizer;
15pub mod semir;
16pub mod token;
17pub mod token_stream;
18pub mod tree;
19pub mod vocabulary;
20
21pub use atn::parser::{ParserAtnPrediction, ParserAtnSimulator, ParserAtnSimulatorError};
22pub use char_stream::{CharStream, InputStream, TextInterval};
23pub use dfa::{Dfa, DfaState};
24pub use errors::{AntlrError, ConsoleErrorListener, ErrorListener};
25pub use generated::{GeneratedLexer, GeneratedParser, GrammarMetadata};
26pub use int_stream::{EOF, IntStream, UNKNOWN_SOURCE_NAME};
27pub use lexer::{BaseLexer, Lexer, LexerCustomAction, LexerMode, LexerPredicate, LexerSemCtx};
28pub use parser::{
29    BailErrorStrategy, BaseParser, ExpectedTokenSet, NoSemanticHooks, Parser, ParserAction,
30    ParserMemberAction, ParserPredicate, ParserReturnAction, ParserRuleArg, ParserRuntimeOptions,
31    ParserSemCtx, ParserSemanticAction, ParserSemanticPredicate, ParserSemantics, PredictionMode,
32    SemanticHooks, UnknownSemanticPolicy,
33};
34#[cfg(feature = "perf-counters")]
35pub use perf::{dump as dump_prediction_perf_counters, reset as reset_prediction_perf_counters};
36pub use prediction::{
37    AtnConfig, AtnConfigSet, PredictionContext, PredictionContextMergeCache, SemanticContext,
38};
39pub use recognizer::{Recognizer, RecognizerData};
40pub use token::{
41    CommonToken, CommonTokenFactory, DEFAULT_CHANNEL, HIDDEN_CHANNEL, INVALID_TOKEN_TYPE,
42    TOKEN_EOF, Token, TokenChannel, TokenFactory, TokenSource,
43};
44pub use token_stream::CommonTokenStream;
45pub use tree::{
46    ErrorNode, FromRuleContext, GeneratedAttrs, ParseTree, ParseTreeListener, ParseTreeWalker,
47    ParserRuleContext, RuleNode, TerminalNode,
48};
49pub use vocabulary::Vocabulary;
50
51/// Formats a slice the way Java's `List.toString` does: `[a, b, c]`.
52///
53/// ANTLR's runtime-testsuite descriptors byte-compare output produced by
54/// Java's list rendering (`getRuleInvocationStack()`, token-getter lists).
55/// Rust's `Vec` `Debug` quotes elements, so — like Go's
56/// `antlr.PrintArrayJavaStyle` and Python's `str_list` — the Rust target
57/// exposes a dedicated formatter for generated test actions.
58pub fn java_style_list<T: std::fmt::Display>(items: &[T]) -> String {
59    let mut out = String::from("[");
60    for (index, item) in items.iter().enumerate() {
61        if index > 0 {
62            out.push_str(", ");
63        }
64        use std::fmt::Write;
65        write!(out, "{item}").expect("writing to a string cannot fail");
66    }
67    out.push(']');
68    out
69}