-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scalameta is gradually phasing out macros, so let's stop using custom classifiers. Also, let's switch to using standard scalameta token branches instead of custom ones defined within scalafmt: - Trivia -> Token.Trivia - Whitespace -> Token.Whitespace - Delim -> Token.Symbolic - Literal -> Token.Literal - rename Keyword as Reserved and represent it as Token.Keyword and false/true/null - remove Modifier since it's covered by Reserved and used only once, where Reserved applies already
- Loading branch information
Showing
9 changed files
with
43 additions
and
123 deletions.
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
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
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
92 changes: 6 additions & 86 deletions
92
scalafmt-core/shared/src/main/scala/org/scalafmt/util/TokenClasses.scala
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 |
---|---|---|
@@ -1,121 +1,41 @@ | ||
package org.scalafmt.util | ||
|
||
import scala.meta.Dialect | ||
import scala.meta.internal.classifiers.classifier | ||
import scala.meta.internal.parsers.SoftKeywords | ||
import scala.meta.tokens.Token | ||
import scala.meta.tokens.Token._ | ||
|
||
@classifier | ||
trait Keyword | ||
object Keyword { | ||
def unapply(token: Token): Boolean = { | ||
token.is[KwAbstract] || token.is[KwCase] || token.is[KwCatch] || | ||
token.is[KwClass] || token.is[KwDef] || token.is[KwDo] || | ||
token.is[KwElse] || token.is[KwEnum] || token.is[KwExport] || | ||
token.is[KwExtends] || token.is[KwFalse] || token.is[KwFinal] || | ||
token.is[KwFinally] || token.is[KwFor] || token.is[KwForsome] || | ||
token.is[KwGiven] || token.is[KwIf] || token.is[KwImplicit] || | ||
token.is[KwImport] || token.is[KwLazy] || token.is[KwMatch] || | ||
token.is[KwMacro] || token.is[KwNew] || token.is[KwNull] || | ||
token.is[KwObject] || token.is[KwOverride] || token.is[KwPackage] || | ||
token.is[KwPrivate] || token.is[KwProtected] || token.is[KwReturn] || | ||
token.is[KwSealed] || token.is[KwSuper] || token.is[KwThis] || | ||
token.is[KwThen] || | ||
token.is[KwThrow] || token.is[KwTrait] || token.is[KwTrue] || | ||
token.is[KwTry] || token.is[KwType] || token.is[KwVal] || | ||
token.is[KwVar] || token.is[KwWhile] || token.is[KwWith] || | ||
token.is[KwYield] | ||
object Reserved { | ||
def unapply(token: Token): Boolean = token match { | ||
case _: Keyword | _: KwFalse | _: KwNull | _: KwTrue => true | ||
case _ => false | ||
} | ||
} | ||
|
||
@classifier | ||
trait Delim | ||
object Delim { | ||
def unapply(token: Token): Boolean = { | ||
token.is[Hash] || token.is[Colon] || token.is[Viewbound] || | ||
token.is[LeftArrow] || token.is[Subtype] || token.is[Equals] || | ||
token.is[RightArrow] || token.is[Supertype] || token.is[At] || | ||
token.is[Underscore] || token.is[LeftParen] || token.is[RightParen] || | ||
token.is[Comma] || token.is[Dot] || token.is[Semicolon] || | ||
token.is[LeftBracket] || token.is[RightBracket] || token.is[LeftBrace] || | ||
token.is[RightBrace] || token.is[ContextArrow] || token.is[TypeLambdaArrow] | ||
} | ||
} | ||
|
||
@classifier | ||
trait Modifier | ||
object Modifier { | ||
def unapply(token: Token): Boolean = { | ||
token.is[KwAbstract] || token.is[KwFinal] || token.is[KwSealed] || | ||
token.is[KwImplicit] || token.is[KwLazy] || token.is[KwPrivate] || | ||
token.is[KwProtected] || token.is[KwOverride] | ||
} | ||
} | ||
|
||
@classifier | ||
trait Literal | ||
object Literal { | ||
def unapply(token: Token): Boolean = { | ||
token.is[Constant.Int] || token.is[Constant.Long] || | ||
token.is[Constant.Float] || token.is[Constant.Double] || | ||
token.is[Constant.Char] || token.is[Constant.Symbol] || | ||
token.is[Constant.String] || token.is[KwNull] || token.is[KwTrue] || | ||
token.is[KwFalse] | ||
} | ||
} | ||
|
||
@classifier | ||
trait Whitespace | ||
object Whitespace { | ||
def unapply(token: Token): Boolean = { | ||
token.is[Space] || token.is[Tab] || token.is[CR] || token.is[LF] || | ||
token.is[FF] | ||
} | ||
} | ||
|
||
@classifier | ||
trait Trivia | ||
object Trivia { | ||
def unapply(token: Token): Boolean = { | ||
token.is[Whitespace] || token.is[Comment] | ||
} | ||
} | ||
|
||
@classifier | ||
trait LeftParenOrBracket | ||
object LeftParenOrBracket { | ||
def unapply(tok: Token): Boolean = | ||
tok.is[LeftParen] || tok.is[LeftBracket] | ||
} | ||
|
||
@classifier | ||
trait RightParenOrBracket | ||
object RightParenOrBracket { | ||
def unapply(tok: Token): Boolean = | ||
tok.is[RightParen] || tok.is[RightBracket] | ||
} | ||
|
||
@classifier | ||
trait LeftParenOrBrace | ||
object LeftParenOrBrace { | ||
def unapply(tok: Token): Boolean = tok.is[LeftParen] || tok.is[LeftBrace] | ||
} | ||
|
||
class SoftKeywordClasses(dialect: Dialect) extends SoftKeywords(dialect) { | ||
@classifier | ||
trait ImplicitOrUsing | ||
object ImplicitOrUsing { | ||
def unapply(tok: Token): Boolean = { | ||
tok.is[KwImplicit] || tok.is[KwUsing] | ||
tok.is[KwImplicit] || KwUsing.unapply(tok) | ||
} | ||
} | ||
|
||
@classifier | ||
trait ExtendsOrDerives | ||
object ExtendsOrDerives { | ||
def unapply(tok: Token): Boolean = { | ||
tok.is[KwExtends] || tok.is[KwDerives] | ||
tok.is[KwExtends] || KwDerives.unapply(tok) | ||
} | ||
} | ||
} |
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