-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
enh(scala) add Scala 3 end
and extension
soft keywords
#3327
Merged
joshgoebel
merged 3 commits into
highlightjs:main
from
nicolasstucki:add-scala-end-syntax
Sep 9, 2021
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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,41 @@ | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span> </span>= | ||
<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) | ||
() | ||
<span class="hljs-keyword">else</span> | ||
() | ||
<span class="hljs-keyword">end</span> <span class="hljs-keyword">if</span> | ||
|
||
<span class="hljs-keyword">while</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">do</span> | ||
() | ||
<span class="hljs-keyword">end</span> <span class="hljs-keyword">while</span> | ||
|
||
<span class="hljs-keyword">for</span> x <- xs <span class="hljs-keyword">do</span> | ||
() | ||
<span class="hljs-keyword">end</span> <span class="hljs-keyword">for</span> | ||
|
||
x <span class="hljs-keyword">match</span> | ||
<span class="hljs-keyword">case</span> _ => | ||
<span class="hljs-keyword">end</span> <span class="hljs-keyword">match</span> | ||
<span class="hljs-keyword">end</span> foo | ||
|
||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">bar</span> </span>= | ||
<span class="hljs-keyword">new</span> <span class="hljs-type">Foo</span>: | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span> </span>= () | ||
<span class="hljs-keyword">end</span> <span class="hljs-keyword">new</span> | ||
<span class="hljs-keyword">end</span> | ||
|
||
<span class="hljs-keyword">val</span> baz = | ||
() | ||
<span class="hljs-keyword">end</span> <span class="hljs-keyword">val</span> | ||
|
||
<span class="hljs-keyword">var</span> baz2 = | ||
() | ||
<span class="hljs-keyword">end</span> <span class="hljs-keyword">var</span> | ||
|
||
<span class="hljs-keyword">extension</span> (x: <span class="hljs-type">Int</span>) | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span> </span>= <span class="hljs-number">1</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span> </span>= <span class="hljs-number">2</span> | ||
<span class="hljs-keyword">end</span> <span class="hljs-keyword">extension</span> | ||
|
||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span></span>: | ||
<span class="hljs-keyword">end</span> <span class="hljs-type">Foo</span> |
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,41 @@ | ||
def foo = | ||
if (true) | ||
() | ||
else | ||
() | ||
end if | ||
|
||
while true do | ||
() | ||
end while | ||
|
||
for x <- xs do | ||
() | ||
end for | ||
|
||
x match | ||
case _ => | ||
end match | ||
end foo | ||
|
||
def bar = | ||
new Foo: | ||
def f = () | ||
end new | ||
end | ||
|
||
val baz = | ||
() | ||
end val | ||
|
||
var baz2 = | ||
() | ||
end var | ||
|
||
extension (x: Int) | ||
def f = 1 | ||
def f = 2 | ||
end extension | ||
|
||
class Foo: | ||
end Foo |
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,19 @@ | ||
<span class="hljs-keyword">extension</span> (x: <span class="hljs-type">Int</span>) <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">plus</span></span>(y: <span class="hljs-type">Int</span>) = x + y | ||
|
||
<span class="hljs-keyword">extension</span> [<span class="hljs-type">T</span>](x: <span class="hljs-type">T</span>) <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span> </span>= () | ||
|
||
<span class="hljs-keyword">extension</span> (x: <span class="hljs-type">Int</span>) | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span> </span>= <span class="hljs-number">1</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span> </span>= <span class="hljs-number">2</span> | ||
|
||
<span class="hljs-class"><span class="hljs-keyword">object</span> <span class="hljs-title">Foo</span> </span>{ | ||
<span class="hljs-keyword">extension</span> (x: <span class="hljs-type">Int</span>) | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span> </span>= <span class="hljs-number">1</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span> </span>= <span class="hljs-number">2</span> | ||
} | ||
|
||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">extension</span></span>(file: <span class="hljs-type">File</span>) = | ||
file.extension | ||
|
||
file | ||
.extension |
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,19 @@ | ||
extension (x: Int) def plus(y: Int) = x + y | ||
|
||
extension [T](x: T) def f = () | ||
|
||
extension (x: Int) | ||
def f = 1 | ||
def f = 2 | ||
|
||
object Foo { | ||
extension (x: Int) | ||
def f = 1 | ||
def f = 2 | ||
} | ||
|
||
def extension(file: File) = | ||
file.extension | ||
|
||
file | ||
.extension |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I use escapes for
(
and[
as in the other PR?The rule would be
/\s+(?=\[|\()/
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, it's a character group. But we don't generally use a single character group to avoid escapes, hence my flagging the other.