summaryrefslogtreecommitdiff
path: root/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala
diff options
context:
space:
mode:
Diffstat (limited to 'scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala')
-rw-r--r--scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala39
1 files changed, 15 insertions, 24 deletions
diff --git a/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala b/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala
index a95afac..4bc972f 100644
--- a/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala
+++ b/scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala
@@ -6,39 +6,30 @@ import org.parboiled2._
trait Identifiers { self: Parser with Basic =>
object Identifiers{
import Basic._
- def Operator = rule{!Keywords ~ oneOrMore(OperatorChar)}
+ def Operator = rule(oneOrMore(OperatorChar))
- def VarId = VarId0(true)
- def VarId0(dollar: Boolean) = rule { !Keywords ~ Lower ~ IdRest(dollar) }
- def PlainId = rule { !Keywords ~ Upper ~ IdRest(true) | VarId | Operator }
- def PlainIdNoDollar = rule { !Keywords ~ Upper ~ IdRest(false) | VarId0(false) | Operator }
- def Id = rule { !Keywords ~ PlainId | ("`" ~ oneOrMore(noneOf("`")) ~ "`") }
- def IdRest(dollar: Boolean) = {
- if (!dollar) rule {
- zeroOrMore(zeroOrMore("_") ~ oneOrMore(!anyOf("_$") ~ Letter | Digit)) ~
- optional(oneOrMore("_") ~ zeroOrMore(OperatorChar))
- } else rule{
- zeroOrMore(zeroOrMore("_") ~ oneOrMore(!"_" ~ Letter | Digit)) ~
- optional(oneOrMore("_") ~ zeroOrMore(OperatorChar))
- }
+ def VarId = rule {
+ !(Keywords ~ (WhitespaceChar | Newline | "//" | "/*")) ~ Lower ~ IdRest
}
+ def PlainId = rule { Upper ~ IdRest | VarId | !(Keywords ~ (WhitespaceChar | Newline | "//" | "/*")) ~ Operator }
+ def Id = rule { PlainId | ("`" ~ oneOrMore(noneOf("`")) ~ "`") }
+ def IdRest = rule {
+ zeroOrMore(zeroOrMore("_") ~ oneOrMore(!"_" ~ Letter | Digit)) ~
+ optional(oneOrMore("_") ~ optional(Operator))
+ }
+
def AlphabetKeywords = rule {
- (
- "abstract" | "case" | "catch" | "class" | "def" | "do" | "else" | "extends" | "false" | "finally" | "final" | "finally" | "forSome" | "for" | "if" |
- "implicit" | "import" | "lazy" | "match" | "new" | "null" | "object" | "override" | "package" | "private" | "protected" | "return" |
- "sealed" | "super" | "this" | "throw" | "trait" | "try" | "true" | "type" | "val" | "var" | "while" | "with" | "yield" | "_"
- ) ~ !Letter
+ "abstract" | "case" | "catch" | "class" | "def" | "do" | "else" | "extends" | "false" | "finally" | "final" | "finally" | "forSome" | "for" | "if" |
+ "implicit" | "import" | "lazy" | "match" | "new" | "null" | "object" | "override" | "package" | "private" | "protected" | "return" |
+ "sealed" | "super" | "this" | "throw" | "trait" | "try" | "true" | "type" | "val" | "var" | "while" | "with" | "yield" | "_"
}
def SymbolicKeywords = rule{
- (
- ":" | ";" | "=>" | "=" | "<-" | "<:" | "<%" | ">:" | "#" | "@" | "\u21d2" | "\u2190"
- ) ~ !OperatorChar
+ ":" | ";" | "=>" | "=" | "<-" | "<:" | "<%" | ">:" | "#" | "@" | "\u21d2" | "\u2190"
}
def Keywords = rule {
- AlphabetKeywords | SymbolicKeywords
+ AlphabetKeywords ~ !Letter | SymbolicKeywords ~ !OperatorChar
}
-
}
}