Repository navigation
feat(codegen): add lex-only generated helpers #316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a6f80b3
feat(codegen): add lex-only generated helpers
tinovyatkin 65bfab9
test(codegen): lock offline build fixture dependencies
tinovyatkin 3abf94d
fix(codegen): make lex-only token dumps explicit
tinovyatkin 1947c6e
test(codegen): snapshot lex-only token sequence
tinovyatkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../src/generator/snapshots/antlr_rust_codegen__generator__tests__lexer_lex_convenience.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| --- | ||
| source: crates/antlr-rust-codegen/src/generator/tests.rs | ||
| expression: "&convenience" | ||
| --- | ||
| /// Lexes UTF-8 text into an eagerly filled token stream without constructing | ||
| /// a parser. | ||
| /// | ||
| /// The stream retains every emitted token, including EOF and tokens on hidden | ||
| /// or custom channels. Lexer rules using `skip` do not emit tokens. | ||
| /// | ||
| /// With `use antlr4_runtime::Token as _;`, print each token's vocabulary name, | ||
| /// numeric channel, and text: | ||
| /// `let vocabulary = metadata().vocabulary(); for token in lex(src, TLexer::new).tokens() { println!("type={} channel={} text={:?}", vocabulary.display_name(token.token_type()), token.channel(), token.text()); }` | ||
| /// | ||
| /// `number_of_source_errors()` reports buffered lexer diagnostics. After | ||
| /// iterating `tokens()`, `drain_source_errors()` retrieves those diagnostics. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if buffering returns an [`antlr4_runtime::TokenStoreError`]. Construct | ||
| /// the lexer and call [`antlr4_runtime::CommonTokenStream::try_new`] to handle | ||
| /// that error instead. | ||
| pub fn lex<L: antlr4_runtime::TokenSource>( | ||
| input: impl AsRef<str>, | ||
| lexer: impl FnOnce(antlr4_runtime::InputStream) -> L, | ||
| ) -> antlr4_runtime::CommonTokenStream<L> { | ||
| lex_stream(antlr4_runtime::InputStream::new(input.as_ref()), lexer) | ||
| } | ||
|
|
||
| /// Lexes a caller-provided character stream without constructing a parser. | ||
| /// | ||
| /// Unlike [`lex`], this accepts any [`antlr4_runtime::CharStream`], including a | ||
| /// named [`antlr4_runtime::InputStream`] or a byte-oriented | ||
| /// [`antlr4_runtime::ByteStream`]. | ||
| /// | ||
| /// `number_of_source_errors()` reports buffered lexer diagnostics. After | ||
| /// iterating `tokens()`, `drain_source_errors()` retrieves those diagnostics. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if buffering returns an [`antlr4_runtime::TokenStoreError`]. Call | ||
| /// [`antlr4_runtime::CommonTokenStream::try_new`] with the constructed lexer to | ||
| /// handle that error instead. | ||
| pub fn lex_stream<I: antlr4_runtime::CharStream, L: antlr4_runtime::TokenSource>( | ||
| input: I, | ||
| lexer: impl FnOnce(I) -> L, | ||
| ) -> antlr4_runtime::CommonTokenStream<L> { | ||
| antlr4_runtime::CommonTokenStream::new(lexer(input)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 47 additions & 2 deletions
49
crates/antlr-rust-g4-parser/src/generated/antlr_v4_lexer.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.