in rsc/src/main/scala/rsc/parse/scala/Pats.scala [85:180]
private def simplePat(permitColon: Boolean): Pat = {
val start = in.offset
in.token match {
case ID =>
val termPath = this.termPath()
termPath match {
case TermId("-") if in.token.isNumericLit =>
PatLit(negatedLiteral())
case termPath =>
in.token match {
case LBRACKET =>
val fun = termPath
val targs = tptArgs()
val args = patArgs()
atPos(start)(PatExtract(fun, targs, args))
case LPAREN =>
val fun = termPath
val args = patArgs()
atPos(start)(PatExtract(fun, Nil, args))
case _ =>
termPath match {
case TermId("-") if in.token.isNumericLit =>
val value = literal()
atPos(start)(PatLit(value))
case unfinished: TermId =>
val value = unfinished.value
val isBackquoted = input.chars(unfinished.pos.start) == '`'
if (value.isPatVar && !isBackquoted) {
simplePatRest(unfinished, permitColon)
} else {
patPath(unfinished)
}
case termPath =>
patPath(termPath)
}
}
}
case THIS =>
patPath()
case USCORE =>
in.nextToken()
val unfinished = atPos(start)(anonId())
if (in.token == ID && in.idValue == "*") {
in.nextToken()
val mods = atPos(in.offset)(Mods(Nil))
val pat = atPos(start)(PatVar(mods, unfinished, None))
atPos(start)(PatRepeat(pat))
} else {
simplePatRest(unfinished, permitColon)
}
case token if token.isLit =>
val value = literal()
atPos(start)(PatLit(value))
case LPAREN =>
val pats = patArgs()
pats match {
case Nil => atPos(start)(PatLit(()))
case pat :: Nil => pat
case pats => atPos(start)(PatTuple(pats))
}
case INTID =>
val value = in.idValue
in.nextToken()
val id = atPos(start)(TermId(value))
val parts = List.newBuilder[PatLit]
val args = List.newBuilder[Pat]
accept(INTSTART)
var expected = INTPART
while (in.token != INTEND) {
if (expected == INTPART) {
val start = in.offset
val value = in.value.asInstanceOf[String]
accept(INTPART)
parts += atPos(start)(PatLit(value))
expected = INTSPLICE
} else if (expected == INTSPLICE) {
accept(INTSPLICE)
args += pat()
expected = INTPART
} else {
crash(expected)
}
}
accept(INTEND)
atPos(start)(PatInterpolate(id, parts.result, args.result))
case XML =>
// FIXME: https://github.com/twitter/rsc/issues/81
val raw = in.value
in.nextToken()
atPos(start)(PatXml(raw))
case _ =>
val errOffset = in.offset
reportOffset(errOffset, IllegalStartOfSimplePat)
atPos(errOffset)(errorPat())
}
}