Skip to content

Commit b1e3f30

Browse files
committed
Make use of isNewLine and isIdent methods in Scanner
1 parent c30eafa commit b1e3f30

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ object Parsers {
181181

182182
/* -------------- TOKEN CLASSES ------------------------------------------- */
183183

184-
def isIdent = in.token == IDENTIFIER || in.token == BACKQUOTED_IDENT
184+
def isIdent = in.isIdent
185185
def isIdent(name: Name) = in.token == IDENTIFIER && in.name == name
186186
def isSimpleLiteral = simpleLiteralTokens contains in.token
187187
def isLiteral = literalTokens contains in.token
@@ -215,8 +215,7 @@ object Parsers {
215215
(allowedMods `contains` in.token) ||
216216
in.isSoftModifierInModifierPosition && !excludedSoftModifiers.contains(in.name)
217217

218-
def isStatSep: Boolean =
219-
in.token == NEWLINE || in.token == NEWLINES || in.token == SEMI
218+
def isStatSep: Boolean = in.isNewLine || in.token == SEMI
220219

221220
/** A '$' identifier is treated as a splice if followed by a `{`.
222221
* A longer identifier starting with `$` is treated as a splice/id combination
@@ -341,10 +340,8 @@ object Parsers {
341340
/** semi = nl {nl} | `;'
342341
* nl = `\n' // where allowed
343342
*/
344-
def acceptStatSep(): Unit = in.token match {
345-
case NEWLINE | NEWLINES => in.nextToken()
346-
case _ => accept(SEMI)
347-
}
343+
def acceptStatSep(): Unit =
344+
if in.isNewLine then in.nextToken() else accept(SEMI)
348345

349346
def acceptStatSepUnlessAtEnd(altEnd: Token = EOF): Unit =
350347
if (!isStatSeqEnd)
@@ -603,9 +600,7 @@ object Parsers {
603600
val t = body()
604601
// Therefore, make sure there would be a matching <outdent>
605602
def nextIndentWidth = in.indentWidth(in.next.offset)
606-
if (in.token == NEWLINE || in.token == NEWLINES)
607-
&& !(nextIndentWidth < startIndentWidth)
608-
then
603+
if in.isNewLine && !(nextIndentWidth < startIndentWidth) then
609604
warning(
610605
if startIndentWidth <= nextIndentWidth then
611606
i"""Line is indented too far to the right, or a `{' is missing before:
@@ -623,7 +618,7 @@ object Parsers {
623618
* statement that's indented relative to the current region.
624619
*/
625620
def checkNextNotIndented(): Unit = in.currentRegion match
626-
case r: InBraces if in.token == NEWLINE || in.token == NEWLINES =>
621+
case r: InBraces if in.isNewLine =>
627622
val nextIndentWidth = in.indentWidth(in.next.offset)
628623
if r.indentWidth < nextIndentWidth then
629624
warning(i"Line is indented too far to the right, or a `{' is missing", in.next.offset)
@@ -876,7 +871,7 @@ object Parsers {
876871
}
877872
if (lookahead.token == LARROW)
878873
false // it's a pattern
879-
else if (lookahead.token != IDENTIFIER && lookahead.token != BACKQUOTED_IDENT)
874+
else if (lookahead.isIdent)
880875
true // it's not a pattern since token cannot be an infix operator
881876
else
882877
followedByToken(LARROW) // `<-` comes before possible statement starts
@@ -904,7 +899,7 @@ object Parsers {
904899
*/
905900
def followingIsGivenSig() =
906901
val lookahead = in.LookaheadScanner()
907-
if lookahead.token == IDENTIFIER || lookahead.token == BACKQUOTED_IDENT then
902+
if lookahead.isIdent then
908903
lookahead.nextToken()
909904
while lookahead.token == LPAREN || lookahead.token == LBRACKET do
910905
lookahead.skipParens()
@@ -1230,8 +1225,7 @@ object Parsers {
12301225
if (in.token == NEWLINE) in.nextToken()
12311226

12321227
def newLinesOpt(): Unit =
1233-
if (in.token == NEWLINE || in.token == NEWLINES)
1234-
in.nextToken()
1228+
if in.isNewLine then in.nextToken()
12351229

12361230
def newLineOptWhenFollowedBy(token: Int): Unit =
12371231
// note: next is defined here because current == NEWLINE

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ object Scanners {
10061006
isSoftModifier && !lookaheadIn(BitSet(COLON))
10071007

10081008
def isNewLine = token == NEWLINE || token == NEWLINES
1009+
def isIdent = token == IDENTIFIER || token == BACKQUOTED_IDENT
10091010

10101011
def isNestedStart = token == LBRACE || token == INDENT
10111012
def isNestedEnd = token == RBRACE || token == OUTDENT

0 commit comments

Comments
 (0)