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