diff options
Diffstat (limited to 'scalaParser/src/main')
-rw-r--r-- | scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala | 39 | ||||
-rw-r--r-- | scalaParser/src/main/scala/scalaParser/syntax/Literals.scala | 6 |
2 files changed, 29 insertions, 16 deletions
diff --git a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala index ef5eb4a..39d57eb 100644 --- a/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala +++ b/scalaParser/src/main/scala/scalaParser/ScalaSyntax.scala @@ -74,7 +74,17 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def Ids = rule { oneOrMore(Id) separatedBy ',' } def NotNewline: R0 = rule{ &( WS ~ noneOf("\n") )} - def OneNewlineMax: R0 = rule{ WS ~ optional(Basic.Newline) ~ NotNewline} + def OneNewlineMax: R0 = rule{ + WS ~ + optional(Basic.Newline) ~ + zeroOrMore( + zeroOrMore(Basic.WhitespaceChar) ~ + Literals.Comment ~ + zeroOrMore(Basic.WhitespaceChar) ~ + Basic.Newline + ) ~ + NotNewline + } def StableId: R0 = { def ClassQualifier = rule { '[' ~ Id ~ ']' } rule { @@ -123,8 +133,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif } rule { BasicType ~ - optional('#' ~ Id) ~ - optional(TypeArgs) + zeroOrMore(TypeArgs | '#' ~ Id) } } @@ -164,12 +173,14 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def Expr = Expr0() def ExprSensitive = Expr0(true) def Expr0(G: Boolean = false): R0 = { - def IfCFlow = rule { "if" ~ '(' ~ Expr ~ ')' ~ Expr0(G) ~ optional(optional(Semi) ~ K.W("else") ~ Expr0(G)) } + def IfCFlow = rule { + "if" ~ '(' ~ Expr ~ ')' ~ Expr0(G) ~ optional(optional(Semi) ~ K.W("else") ~ Expr0(G)) + } def WhileCFlow = rule { "while" ~ '(' ~ Expr ~ ')' ~ Expr0(G) } def TryCFlow = rule { K.W("try") ~ Expr0(G) ~ - optional(K.W("catch") ~ Expr0(G)) ~ - optional(K.W("finally") ~ Expr0(G)) + optional(K.W("catch") ~ Expr0(G)) ~ + optional(K.W("finally") ~ Expr0(G)) } def DoWhileCFlow = rule { K.W("do") ~ Expr0(G) ~ optional(Semi) ~ "while" ~ '(' ~ Expr ~ ")" } @@ -228,7 +239,7 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif } rule { SimpleExpr1 ~ - zeroOrMore('.' ~ Id | TypeArgs | ArgumentExprs) ~ + zeroOrMore('.' ~ Id | TypeArgs | NotNewline ~ ArgumentExprs) ~ optional(K.W("_")) } } @@ -363,7 +374,10 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif Expr0(true) } - def SelfType: R0 = rule { K.W("this") ~ K.O(":") ~ Type ~ K.O("=>") | Id ~ optional(K.O(":") ~ Type) ~ K.O("=>") } + def SelfType: R0 = rule { + K.W("this") ~ K.O(":") ~ InfixType ~ K.O("=>") | + (Id | K.W("_")) ~ optional(K.O(":") ~ InfixType) ~ K.O("=>") + } def Import: R0 = { def ImportExpr: R0 = rule { @@ -403,11 +417,10 @@ class ScalaSyntax(val input: ParserInput) extends Parser with Basic with Identif def ConstrExpr: R0 = rule { ConstrBlock | SelfInvocation } def FunDef: R0 = rule { K.W("this") ~ ParamClause ~ ParamClauses ~ (K.O("=") ~ ConstrExpr | OneNewlineMax ~ ConstrBlock) | - FunSig ~ - ( - optional(K.O(":") ~ Type) ~ K.O("=") ~ optional(K.W("macro")) ~ Expr | - OneNewlineMax ~ '{' ~ Block ~ "}" - ) + FunSig ~ ( + optional(K.O(":") ~ Type) ~ K.O("=") ~ optional(K.W("macro")) ~ Expr0(true) | + OneNewlineMax ~ '{' ~ Block ~ "}" + ) } rule { K.W("def") ~ FunDef | K.W("type") ~ TypeDef | PatVarDef | TmplDef } } diff --git a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala index f854671..703c793 100644 --- a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala +++ b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala @@ -4,7 +4,8 @@ import acyclic.file import org.parboiled2._ trait Literals { self: Parser with Basic with Identifiers => - def Expr: Rule0 + def Block: Rule0 + def WL: Rule0 object Literals{ import Basic._ def FloatingPointLiteral = rule { @@ -36,7 +37,6 @@ trait Literals { self: Parser with Basic with Identifiers => (Key.W("null") ~ !(Basic.Letter | Basic.Digit)) } - def EscapedChars = rule { '\\' ~ anyOf("btnfr'\\\"") } // Note that symbols can take on the same values as keywords! @@ -51,7 +51,7 @@ trait Literals { self: Parser with Basic with Identifiers => } def pr(s: String) = rule { run(println(s"LOGGING $cursor: $s")) } def Interpolation = rule{ - "$" ~ Identifiers.Id | "${" ~ Expr ~ "}" | "$$" + "$" ~ Identifiers.Id | "${" ~ Block ~ WL ~ "}" | "$$" } def StringLiteral = rule { (Identifiers.Id ~ "\"\"\"" ~ MultiLineChars ~ ("\"\"\"" ~ zeroOrMore('"'))) | |