diff options
Diffstat (limited to 'scalaParser/src/main/scala/scalaParser/syntax')
-rw-r--r-- | scalaParser/src/main/scala/scalaParser/syntax/Identifiers.scala | 39 | ||||
-rw-r--r-- | scalaParser/src/main/scala/scalaParser/syntax/Literals.scala | 27 |
2 files changed, 23 insertions, 43 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 } - } } diff --git a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala index e6dd54d..9fd9d5b 100644 --- a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala +++ b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala @@ -4,8 +4,6 @@ import acyclic.file import org.parboiled2._ trait Literals { self: Parser with Basic with Identifiers => - def Block: Rule0 - def WL: Rule0 object Literals{ import Basic._ def FloatingPointLiteral = rule { @@ -18,14 +16,14 @@ trait Literals { self: Parser with Basic with Identifiers => ) } - def IntegerLiteral = rule { (HexNumeral | DecimalNumeral) ~ optional(anyOf("Ll")) } + def IntegerLiteral = rule { (DecimalNumeral | HexNumeral) ~ optional(anyOf("Ll")) } def BooleanLiteral = rule { Key.W("true") | Key.W("false") } def MultilineComment: Rule0 = rule { "/*" ~ zeroOrMore(MultilineComment | !"*/" ~ ANY) ~ "*/" } def Comment: Rule0 = rule { MultilineComment | - "//" ~ zeroOrMore(!Basic.Newline ~ ANY) ~ &(Basic.Newline | EOI) + "//" ~ zeroOrMore(!Basic.Newline ~ ANY) ~ &(Basic.Newline | EOI) } def Literal = rule { @@ -37,27 +35,18 @@ trait Literals { self: Parser with Basic with Identifiers => (Key.W("null") ~ !(Basic.Letter | Basic.Digit)) } - def EscapedChars = rule { '\\' ~ anyOf("btnfr'\\\"") } + + def EscapedChars = rule { '\\' ~ anyOf("rnt\\\"") } // Note that symbols can take on the same values as keywords! def SymbolLiteral = rule { ''' ~ (Identifiers.PlainId | Identifiers.Keywords) } - def CharacterLiteral = rule { - ''' ~ (UnicodeExcape | EscapedChars | !'\\' ~ CharPredicate.from(isPrintableChar)) ~ ''' - } + def CharacterLiteral = rule { ''' ~ (UnicodeExcape | EscapedChars | !'\\' ~ CharPredicate.from(isPrintableChar)) ~ ''' } - def MultiLineChars = rule { - zeroOrMore(Interpolation | optional('"') ~ optional('"') ~ noneOf("\"")) - } - def pr(s: String) = rule { run(println(s"LOGGING $cursor: $s")) } - def Interpolation = rule{ - "$" ~ Identifiers.PlainIdNoDollar | "${" ~ Block ~ WL ~ "}" | "$$" - } + def MultiLineChars = rule { zeroOrMore(optional('"') ~ optional('"') ~ noneOf("\"")) } def StringLiteral = rule { - (Identifiers.Id ~ "\"\"\"" ~ MultiLineChars ~ ("\"\"\"" ~ zeroOrMore('"'))) | - (Identifiers.Id ~ '"' ~ zeroOrMore(Interpolation | "\\\"" | "\\\\" | noneOf("\n\"")) ~ '"') | - ("\"\"\"" ~ MultiLineChars ~ ("\"\"\"" ~ zeroOrMore('"'))) | - ('"' ~ zeroOrMore("\\\"" | "\\\\" | noneOf("\n\"")) ~ '"') + (optional(Identifiers.Id) ~ "\"\"\"" ~ MultiLineChars ~ ("\"\"\"" ~ zeroOrMore('"'))) | + (optional(Identifiers.Id) ~ '"' ~ zeroOrMore("\\\"" | noneOf("\n\"")) ~ '"') } def isPrintableChar(c: Char): Boolean = { |