-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Consider syntax with significant indentation #2488
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a3e51e6
Allow `with' in front of `{`.
odersky a8fb236
Set default tab size to 2
odersky 8ddd572
Make indentation significant
odersky ed1ee76
Add interpreted // end comments
odersky e7786b5
Handle multiple withs on one line
odersky 6d8414b
Also handle indentation after if and catch
odersky 9235861
Fix indentation after enums.
odersky 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
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
64 changes: 64 additions & 0 deletions
64
compiler/src/dotty/tools/dotc/parsing/CheckAlignments.scala
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,64 @@ | ||
package dotty.tools.dotc | ||
package parsing | ||
|
||
import ast.NavigateAST.precedingTrees | ||
import core.Comments._ | ||
import core.Flags | ||
import core.Decorators._ | ||
import core.Contexts._ | ||
import ast.{Positioned, Trees, untpd} | ||
import util.SourceFile | ||
|
||
object CheckAlignments { | ||
import untpd._ | ||
|
||
private def kindString(t: Positioned)(implicit ctx: Context) = t match { | ||
case t: ValDef => if (t.mods.is(Flags.Mutable)) "var" else "val" | ||
case _: DefDef => "def" | ||
case t: TypeDef => if (t.isClassDef) "class" else "type" | ||
case _: ModuleDef => "object" | ||
case _: PackageDef => "package" | ||
case _: If => "if" | ||
case _: Try => "try" | ||
case _: Match => "match" | ||
case _: WhileDo => "while" | ||
case _: DoWhile => "do" | ||
case _: ForDo | _: ForYield => "for" | ||
case _ => "" | ||
} | ||
|
||
private def definedString(t: Positioned) = t match { | ||
case t: MemberDef => t.name.toString | ||
case _ => "" | ||
} | ||
|
||
def checkEndComments(source: SourceFile, endComments: List[Comment], roots: List[Tree])(implicit ctx: Context) = { | ||
for (ec <- endComments) { | ||
val endStr = ec.endCommentString | ||
val column = source.column(ec.pos.start) | ||
def misAligned(other: String): String = | ||
i"misaligned '// end', corresponds to $other" | ||
var warning: String = misAligned("nothing") | ||
def combine(s1: String, s2: String) = | ||
if (s1.isEmpty) | ||
if (s2.isEmpty) "nothing" else s"'$s2'" | ||
else | ||
if (s2.isEmpty) s"'$s1'" else s"'$s1 $s2'" | ||
def checkMatch(ts: List[Positioned]): Unit = ts match { | ||
case t :: ts1 => | ||
if (source.column(t.pos.start) == column) { | ||
if (endStr == kindString(t) || endStr == definedString(t)) | ||
warning = "" | ||
else { | ||
if (kindString(t).nonEmpty) | ||
warning = misAligned(combine(kindString(t), definedString(t))) | ||
checkMatch(ts1) | ||
} | ||
} else checkMatch(ts1) | ||
case Nil => | ||
} | ||
checkMatch(precedingTrees(ec.pos.start, roots)) | ||
if (warning.nonEmpty) ctx.warning(warning, ec.pos) | ||
} | ||
} | ||
} |
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
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.
Does this add semantic meaning to comments?
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.
Not really, since you only get a warning if there's misalignment.