-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse line breaks without newlines (#854)
- Loading branch information
1 parent
0c54cc3
commit 4b8970b
Showing
8 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@nomicfoundation/slang": patch | ||
--- | ||
|
||
parse line breaks without newlines |
This file contains 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
10 changes: 7 additions & 3 deletions
10
crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
mod cst_output; | ||
mod doc_examples; | ||
mod trivia; |
This file contains 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,47 @@ | ||
use anyhow::Result; | ||
use semver::Version; | ||
use slang_solidity::cst::Node; | ||
use slang_solidity::kinds::{RuleKind, TokenKind}; | ||
use slang_solidity::language::Language; | ||
|
||
#[test] | ||
fn end_of_line() -> Result<()> { | ||
// Only one is valid as a single token: | ||
compare_end_of_lines("\r", &["\r"])?; | ||
compare_end_of_lines("\n", &["\n"])?; | ||
|
||
// Two of the same are two tokens: | ||
compare_end_of_lines("\n\n", &["\n", "\n"])?; | ||
compare_end_of_lines("\r\r", &["\r", "\r"])?; | ||
|
||
// A carriage return followed by a newline is one token, but the opposite is not: | ||
compare_end_of_lines("\r\n", &["\r\n"])?; | ||
compare_end_of_lines("\n\r", &["\n", "\r"])?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn compare_end_of_lines(input: &str, expected: &[&str]) -> Result<()> { | ||
let version = Version::parse("0.8.0")?; | ||
let language = &Language::new(version)?; | ||
|
||
let output = language.parse(RuleKind::SourceUnit, input); | ||
assert!(output.is_valid()); | ||
|
||
let actual = output | ||
.create_tree_cursor() | ||
.filter_map(|node| match node { | ||
Node::Rule(_) => None, | ||
|
||
Node::Token(token) => { | ||
assert_eq!(token.kind, TokenKind::EndOfLine); | ||
Some(token.text.to_owned()) | ||
} | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
let expected = expected.to_vec(); | ||
assert_eq!(actual, expected); | ||
|
||
Ok(()) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
crates/solidity/outputs/spec/generated/public/01-file-structure/06-trivia.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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