Skip to main content

antlr4_runtime/
lib.rs

1//! Clean-room ANTLR v4 runtime foundation for Rust.
2
3extern crate self as antlr4_runtime;
4
5pub mod atn;
6pub mod byte_stream;
7pub mod char_stream;
8pub mod dfa;
9pub mod errors;
10pub mod generated;
11pub mod int_stream;
12pub mod lexer;
13pub mod parser;
14#[cfg(feature = "perf-counters")]
15pub mod perf;
16pub mod prediction;
17pub mod recognizer;
18pub mod semir;
19pub mod token;
20pub mod token_stream;
21pub mod tree;
22pub mod vocabulary;
23pub mod xpath;
24
25pub use atn::parser::{ParserAtnPrediction, ParserAtnSimulator, ParserAtnSimulatorError};
26pub use byte_stream::ByteStream;
27pub use char_stream::{CharStream, InputStream, PositionSummary, TextInterval};
28pub use dfa::{DfaStateId, DfaTransition, ParserDfa, ParserDfaStateView, ParserDfaStats};
29pub use errors::{AntlrError, ConsoleErrorListener, ErrorListener};
30pub use generated::{GeneratedLexer, GeneratedParser, GrammarMetadata};
31pub use int_stream::{EOF, IntStream, UNKNOWN_SOURCE_NAME};
32pub use lexer::{
33    BaseLexer, Lexer, LexerCustomAction, LexerLifecycleCtx, LexerMode, LexerPredicate, LexerSemCtx,
34};
35pub use parser::{
36    BailErrorStrategy, BaseParser, ExpectedTokenSet, NoSemanticHooks, Parser, ParserAction,
37    ParserMemberAction, ParserPredicate, ParserReturnAction, ParserRuleArg, ParserRuntimeOptions,
38    ParserSemCtx, ParserSemanticAction, ParserSemanticPredicate, ParserSemantics, PredictionMode,
39    RecognitionArenaStats, SemanticHooks, UnknownSemanticPolicy,
40};
41#[cfg(feature = "perf-counters")]
42pub use perf::{dump as dump_prediction_perf_counters, reset as reset_prediction_perf_counters};
43pub use prediction::{ContextId, PredictionContextStats, SemanticContext};
44pub use recognizer::{Recognizer, RecognizerData};
45pub use token::{
46    DEFAULT_CHANNEL, HIDDEN_CHANNEL, INVALID_TOKEN_TYPE, MAX_TOKEN_OFFSET, TOKEN_EOF, Token,
47    TokenChannel, TokenId, TokenIter, TokenSink, TokenSource, TokenSpec, TokenStore,
48    TokenStoreError, TokenView,
49};
50pub use token_stream::CommonTokenStream;
51pub use tree::{
52    AsRuleNode, ErrorNodeView, FromRuleNode, GeneratedAttrs, MissingChildError, Node, NodeChildren,
53    NodeId, NodeKind, ParseTree, ParseTreeDescendants, ParseTreeListener, ParseTreeStats,
54    ParseTreeStorage, ParseTreeVisitor, ParseTreeWalker, ParsedFile, ParserRuleContext,
55    RuleNodeView, TerminalNodeView,
56};
57pub use vocabulary::Vocabulary;
58pub use xpath::{XPath, XPathError};
59
60/// Formats a slice the way Java's `List.toString` does: `[a, b, c]`.
61///
62/// ANTLR's runtime-testsuite descriptors byte-compare output produced by
63/// Java's list rendering (`getRuleInvocationStack()`, token-getter lists).
64/// Rust's `Vec` `Debug` quotes elements, so — like Go's
65/// `antlr.PrintArrayJavaStyle` and Python's `str_list` — the Rust target
66/// exposes a dedicated formatter for generated test actions.
67pub fn java_style_list<T: std::fmt::Display>(items: &[T]) -> String {
68    let mut out = String::from("[");
69    for (index, item) in items.iter().enumerate() {
70        if index > 0 {
71            out.push_str(", ");
72        }
73        use std::fmt::Write;
74        write!(out, "{item}").expect("writing to a string cannot fail");
75    }
76    out.push(']');
77    out
78}