diff options
author | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:44:40 -0800 |
---|---|---|
committer | Haoyi Li <haoyi@haoyi-mbp.corp.dropbox.com> | 2014-11-26 00:44:40 -0800 |
commit | c50f0d417b34d7a8be432c34bac92088734a14ca (patch) | |
tree | 1fee0dc07793e900b6c1b848fac2b7d6fd86b04b /scalaParser/src/main/scala/scalaParser/syntax/Literals.scala | |
parent | 8e76b69d7576877ce5d706651b57d8e1d6ecd717 (diff) | |
download | hands-on-scala-js-c50f0d417b34d7a8be432c34bac92088734a14ca.tar.gz hands-on-scala-js-c50f0d417b34d7a8be432c34bac92088734a14ca.tar.bz2 hands-on-scala-js-c50f0d417b34d7a8be432c34bac92088734a14ca.zip |
tweaks
Diffstat (limited to 'scalaParser/src/main/scala/scalaParser/syntax/Literals.scala')
-rw-r--r-- | scalaParser/src/main/scala/scalaParser/syntax/Literals.scala | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala index b8342e2..9fd9d5b 100644 --- a/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala +++ b/scalaParser/src/main/scala/scalaParser/syntax/Literals.scala @@ -7,17 +7,18 @@ trait Literals { self: Parser with Basic with Identifiers => object Literals{ import Basic._ def FloatingPointLiteral = rule { - capture( + + "." ~ oneOrMore(Digit) ~ optional(ExponentPart) ~ optional(FloatType) | + oneOrMore(Digit) ~ ( "." ~ oneOrMore(Digit) ~ optional(ExponentPart) ~ optional(FloatType) | - oneOrMore(Digit) ~ ( - "." ~ oneOrMore(Digit) ~ optional(ExponentPart) ~ optional(FloatType) | - ExponentPart ~ optional(FloatType) | - optional(ExponentPart) ~ FloatType)) + ExponentPart ~ optional(FloatType) | + optional(ExponentPart) ~ FloatType + ) } - def IntegerLiteral = rule { capture((DecimalNumeral | HexNumeral) ~ optional(anyOf("Ll"))) } + def IntegerLiteral = rule { (DecimalNumeral | HexNumeral) ~ optional(anyOf("Ll")) } - def BooleanLiteral = rule { capture(Key.W("true") | Key.W("false")) } + def BooleanLiteral = rule { Key.W("true") | Key.W("false") } def MultilineComment: Rule0 = rule { "/*" ~ zeroOrMore(MultilineComment | !"*/" ~ ANY) ~ "*/" } def Comment: Rule0 = rule { @@ -26,26 +27,26 @@ trait Literals { self: Parser with Basic with Identifiers => } def Literal = rule { - (capture(optional("-")) ~ (FloatingPointLiteral | IntegerLiteral) ~> ((sign: String, number) => sign + number)) | + (optional("-") ~ (FloatingPointLiteral | IntegerLiteral)) | BooleanLiteral | CharacterLiteral | StringLiteral | SymbolLiteral | - capture(Key.W("null") ~ !(Basic.Letter | Basic.Digit)) + (Key.W("null") ~ !(Basic.Letter | Basic.Digit)) } def EscapedChars = rule { '\\' ~ anyOf("rnt\\\"") } // Note that symbols can take on the same values as keywords! - def SymbolLiteral = rule { ''' ~ capture(Identifiers.PlainId | Identifiers.Keywords) } + def SymbolLiteral = rule { ''' ~ (Identifiers.PlainId | Identifiers.Keywords) } - def CharacterLiteral = rule { ''' ~ capture(UnicodeExcape | EscapedChars | !'\\' ~ CharPredicate.from(isPrintableChar)) ~ ''' } + def CharacterLiteral = rule { ''' ~ (UnicodeExcape | EscapedChars | !'\\' ~ CharPredicate.from(isPrintableChar)) ~ ''' } def MultiLineChars = rule { zeroOrMore(optional('"') ~ optional('"') ~ noneOf("\"")) } def StringLiteral = rule { - (optional(Identifiers.Id) ~ "\"\"\"" ~ capture(MultiLineChars) ~ capture("\"\"\"" ~ zeroOrMore('"')) ~> ((multilineChars: String, quotes) => multilineChars + quotes.dropRight(3))) | - (optional(Identifiers.Id) ~ '"' ~ capture(zeroOrMore("\\\"" | noneOf("\n\""))) ~ '"') + (optional(Identifiers.Id) ~ "\"\"\"" ~ MultiLineChars ~ ("\"\"\"" ~ zeroOrMore('"'))) | + (optional(Identifiers.Id) ~ '"' ~ zeroOrMore("\\\"" | noneOf("\n\"")) ~ '"') } def isPrintableChar(c: Char): Boolean = { |