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