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