Skip to content

Commit

Permalink
parse line breaks without newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Feb 24, 2024
1 parent 5c42e0e commit a0cbf9c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-ants-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/slang": patch
---

parse line breaks without newlines
3 changes: 2 additions & 1 deletion crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ codegen_language_macros::compile!(Language(
),
Trivia(
name = EndOfLine,
scanner = Sequence([Optional(Atom("\r")), Atom("\n")])
scanner =
Choice([Atom("\n"), Sequence([Atom("\r"), Optional(Atom("\n"))])])
),
Trivia(
name = SingleLineComment,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/solidity/outputs/spec/generated/grammar.ebnf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ // foo │ 0..6
2 │ // bar │ 7..13
Errors: []

Tree:
- (SourceUnit) ► (LeadingTrivia): # "// foo\r\n// bar" (0..14)
- (SingleLineComment): "// foo" # (0..6)
- (EndOfLine): "\r\n" # (6..8)
- (SingleLineComment): "// bar" # (8..14)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// foo
// bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ // foo │ 0..6
2 │ // bar │ 7..13
Errors: []

Tree:
- (SourceUnit) ► (LeadingTrivia): # "// foo\r// bar" (0..13)
- (SingleLineComment): "// foo" # (0..6)
- (EndOfLine): "\r" # (6..7)
- (SingleLineComment): "// bar" # (7..13)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// foo// bar
Expand Down
3 changes: 3 additions & 0 deletions crates/solidity/testing/utils/src/cst_snapshots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ fn write_source(w: &mut String, source: &str) -> Result<()> {
return Ok(());
}

// "lines()" only handles "\n", so let's normalize all line endings:
let source = source.replace("\r\n", "\n").replace('\r', "\n");

let line_data = source
.lines()
.enumerate()
Expand Down

0 comments on commit a0cbf9c

Please sign in to comment.