Skip to content
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

Feat: Support for full UTF8 parsing by default. #2717

Merged
merged 15 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Upcoming

- feat: Support for parsing Basic Multilingual Plane characters from UTF-8 in code and comments (https://github.com/dafny-lang/dafny/pull/2717)
- feat: Command-line arguments are now available from `Main` in Dafny programs, using `Main(args: seq<string>)` (https://github.com/dafny-lang/dafny/pull/2594)
- feat: Generate warning when 'old' has no effect (https://github.com/dafny-lang/dafny/pull/2610)
- fix: Missing related position in failing precondition (https://github.com/dafny-lang/dafny/pull/2658)
Expand Down
3 changes: 3 additions & 0 deletions Source/DafnyCore/Coco/Scanner.frame
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ public class Scanner {
}
buffer = new UTF8Buffer(buffer); col = 0;
NextCh();
} else {
// We consider all files to be UTF-8 by default
buffer = new UTF8Buffer(buffer);
}
pt = tokens = new Token(); // first token is a dummy
}
Expand Down
4 changes: 2 additions & 2 deletions Source/DafnyPipeline.Test/Trivia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void TriviaSplitWorksOnLinuxMacAndWindows() {
foreach (Newlines newLinesType in Enum.GetValues(typeof(Newlines))) {
currentNewlines = newLinesType;
var programString = @"
// Comment before
// Comment before
module Test // Module docstring
{}

Expand Down Expand Up @@ -92,7 +92,7 @@ ensures true
var f = defaultClass.Members[1];
var g = defaultClass.Members[2];
var m = defaultClass.Members[3];
AssertTrivia(moduleTest, "\n// Comment before\n", " // Module docstring\n");
AssertTrivia(moduleTest, "\n// Comment before\n", " // Module docstring\n");
AssertTrivia(trait1, "/** Trait docstring */\n", " ");
AssertTrivia(trait2, "// Just a comment\n", "\n// Trait docstring\n");
AssertTrivia(subsetType, "// This is attached to n\n", "\n// This is attached to n as well\n\n");
Expand Down
6 changes: 6 additions & 0 deletions Test/dafny0/PrintUTF8.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %dafny /compile:3 "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

method Main() {
print "Mikaël fixed UTF8\n";
}
robin-aws marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions Test/dafny0/PrintUTF8.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

Dafny program verifier finished with 0 verified, 0 errors
Mikaël fixed UTF8
6 changes: 6 additions & 0 deletions Test/dafny0/PrintUTF8Fails.dfy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %dafny_0 /compile:3 "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

method Main() {
print "Mikaël did not fix 😎\n";
}
2 changes: 2 additions & 0 deletions Test/dafny0/PrintUTF8Fails.dfy.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PrintUTF8Fails.dfy(5,8): Error: invalid LogicalExpression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow that's worse than I thought 😎

1 parse errors detected in PrintUTF8Fails.dfy
5 changes: 2 additions & 3 deletions docs/DafnyRef/Grammar.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ let you reconstruct the original grammar.

## 2.1. Dafny Input {#sec-unicode}

Dafny source code files are readable text encoded as UTF-8 Unicode
(because this is what the Coco/R-generated scanner and parser read).
Dafny source code files are readable text encoded in UTF-8, where each decoded character has to be from the Basic Multilingual Plane and therefore encodable with a single UTF-16 code unit. This is what the Coco/R-generated scanner and parser read.
All program text other than the contents of comments, character, string and verbatim string literals
consists of printable and white-space ASCII characters,
consists of printable and white-space ASCII characters.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from , to . is wrong here -- it leaves a sentence fragment on the next line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix it in your next PR please? I can review that. Thanks for reporting.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to cok-docs-TODOs, PR#2817

that is, ASCII characters in the range `!` to `~`, plus space, tab, cr and nl (ASCII, 9, 10, 13, 32) characters.

However, a current limitation of the Coco/R tool used by `dafny`
Expand Down