Skip to content
Permalink
Browse files

= Reformat with scalafmt, update file headers

  • Loading branch information...
sirthias committed May 3, 2019
1 parent 447a271 commit 7ed425af9e22724934a486e9efcba2ca9d5bc346
Showing with 1,500 additions and 1,293 deletions.
  1. +9 −9 examples/src/main/scala/org/parboiled2/examples/ABCParser.scala
  2. +9 −7 examples/src/main/scala/org/parboiled2/examples/Calculator1.scala
  3. +16 −14 examples/src/main/scala/org/parboiled2/examples/Calculator2.scala
  4. +13 −11 examples/src/main/scala/org/parboiled2/examples/CsvParser.scala
  5. +20 −18 examples/src/main/scala/org/parboiled2/examples/JsonParser.scala
  6. +76 −10 examples/src/test/scala/org/parboiled2/examples/CsvParserSpec.scala
  7. +7 −7 examples/src/test/scala/org/parboiled2/examples/JsonParserSpec.scala
  8. +16 −0 jsonBenchmark/src/main/scala/org/parboiled/examples/JsonParserBenchmark.scala
  9. +37 −28 parboiled-core/src/main/scala/org/parboiled2/CharPredicate.scala
  10. +53 −52 parboiled-core/src/main/scala/org/parboiled2/CharUtils.scala
  11. +85 −72 parboiled-core/src/main/scala/org/parboiled2/ErrorFormatter.scala
  12. +50 −50 parboiled-core/src/main/scala/org/parboiled2/ParseError.scala
  13. +171 −158 parboiled-core/src/main/scala/org/parboiled2/Parser.scala
  14. +45 −38 parboiled-core/src/main/scala/org/parboiled2/ParserInput.scala
  15. +66 −56 parboiled-core/src/main/scala/org/parboiled2/Rule.scala
  16. +42 −40 parboiled-core/src/main/scala/org/parboiled2/RuleDSLActions.scala
  17. +47 −48 parboiled-core/src/main/scala/org/parboiled2/RuleDSLBasics.scala
  18. +60 −50 parboiled-core/src/main/scala/org/parboiled2/RuleDSLCombinators.scala
  19. +76 −76 parboiled-core/src/main/scala/org/parboiled2/ValueStack.scala
  20. +7 −7 parboiled-core/src/main/scala/org/parboiled2/package.scala
  21. +51 −11 parboiled-core/src/main/scala/org/parboiled2/support/ActionOpsSupport.scala
  22. +4 −4 parboiled-core/src/main/scala/org/parboiled2/support/HListable.scala
  23. +11 −10 parboiled-core/src/main/scala/org/parboiled2/support/Lifter.scala
  24. +130 −85 parboiled-core/src/main/scala/org/parboiled2/support/OpTreeContext.scala
  25. +18 −7 parboiled-core/src/main/scala/org/parboiled2/support/RunResult.scala
  26. +9 −9 parboiled-core/src/main/scala/org/parboiled2/support/TailSwitch.scala
  27. +14 −14 parboiled-core/src/main/scala/org/parboiled2/support/Unpack.scala
  28. +2 −2 parboiled-core/src/main/scala/org/parboiled2/support/package.scala
  29. +56 −124 parboiled-core/src/main/scala/org/parboiled2/util/Base64.scala
  30. +25 −19 parboiled-core/src/test/scala/org/parboiled2/ActionSpec.scala
  31. +14 −15 parboiled-core/src/test/scala/org/parboiled2/BasicSpec.scala
  32. +11 −7 parboiled-core/src/test/scala/org/parboiled2/CalculatorSpec.scala
  33. +3 −3 parboiled-core/src/test/scala/org/parboiled2/CharPredicateSpec.scala
  34. +17 −17 parboiled-core/src/test/scala/org/parboiled2/CharUtilsSpec.scala
  35. +5 −5 parboiled-core/src/test/scala/org/parboiled2/CombinatorSpec.scala
  36. +3 −3 parboiled-core/src/test/scala/org/parboiled2/CustomCharAndStringExpansionSpec.scala
  37. +8 −9 parboiled-core/src/test/scala/org/parboiled2/CutSpec.scala
  38. +17 −15 parboiled-core/src/test/scala/org/parboiled2/DSLTest.scala
  39. +2 −2 parboiled-core/src/test/scala/org/parboiled2/DefaultArgumentsSpec.scala
  40. +31 −45 parboiled-core/src/test/scala/org/parboiled2/ErrorReportingSpec.scala
  41. +6 −6 parboiled-core/src/test/scala/org/parboiled2/MetaRuleSpec.scala
  42. +6 −6 parboiled-core/src/test/scala/org/parboiled2/ReductionTypeSpec.scala
  43. +7 −4 parboiled-core/src/test/scala/org/parboiled2/RunSubParserSpec.scala
  44. +5 −5 parboiled-core/src/test/scala/org/parboiled2/RunningSpec.scala
  45. +8 −7 parboiled-core/src/test/scala/org/parboiled2/TailrecSpec.scala
  46. +15 −15 parboiled-core/src/test/scala/org/parboiled2/TestParserSpec.scala
  47. +17 −1 parboiled-core/src/test/scala/org/parboiled2/ValueStackSpec.scala
  48. +8 −8 parboiled-core/src/test/scala/org/parboiled2/VarianceSpec.scala
  49. +3 −3 parboiled-core/src/test/scala/org/parboiled2/nestedpackage/AlienPackageParserSpec.scala
  50. +19 −18 parboiled-core/src/test/scala/org/parboiled2/util/Base64Spec.scala
  51. +20 −20 parboiled/src/main/scala/org/parboiled2/Base64Parsing.scala
  52. +22 −19 parboiled/src/main/scala/org/parboiled2/DynamicRuleDispatch.scala
  53. +7 −7 parboiled/src/main/scala/org/parboiled2/StringBuilding.scala
  54. +14 −10 parboiled/src/test/scala/org/parboiled2/Base64ParsingSpec.scala
  55. +7 −7 parboiled/src/test/scala/org/parboiled2/DynamicRuleDispatchSpec.scala
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009-2013 Mathias Doenitz, Alexander Myltsev
* Copyright 2009-2019 Mathias Doenitz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,7 +17,7 @@
package org.parboiled2.examples

import scala.annotation.tailrec
import scala.util.{ Success, Failure }
import scala.util.{Failure, Success}
import scala.io.StdIn
import org.parboiled2._

@@ -45,12 +45,12 @@ object ABCParser extends App {
}

/**
* This parser reads the classic non-context-free language:
*
* a^n b^n c^n (for n > 1)
*
* See also: http://en.wikipedia.org/wiki/Parsing_expression_grammar#Examples
*/
* This parser reads the classic non-context-free language:
*
* a^n b^n c^n (for n > 1)
*
* See also: http://en.wikipedia.org/wiki/Parsing_expression_grammar#Examples
*/
class ABCParser(val input: ParserInput) extends Parser {

def InputLine = rule {
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009-2013 Mathias Doenitz, Alexander Myltsev
* Copyright 2009-2019 Mathias Doenitz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -45,22 +45,24 @@ object Calculator1 extends App {
}

/**
* This parser reads simple calculator expressions and evaluates them right during
* the parsing run with the help of the value stack.
*/
* This parser reads simple calculator expressions and evaluates them right during
* the parsing run with the help of the value stack.
*/
class Calculator1(val input: ParserInput) extends Parser {
def InputLine = rule { Expression ~ EOI }

def Expression: Rule1[Int] = rule {
Term ~ zeroOrMore(
'+' ~ Term ~> ((_: Int) + _)
| '-' ~ Term ~> ((_: Int) - _))
| '-' ~ Term ~> ((_: Int) - _)
)
}

def Term = rule {
Factor ~ zeroOrMore(
'*' ~ Factor ~> ((_: Int) * _)
| '/' ~ Factor ~> ((_: Int) / _))
| '/' ~ Factor ~> ((_: Int) / _)
)
}

def Factor = rule { Number | Parens }
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009-2013 Mathias Doenitz, Alexander Myltsev
* Copyright 2009-2019 Mathias Doenitz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -47,39 +47,41 @@ object Calculator2 extends App {
expr match {
case Value(v) => v.toInt
case Addition(a, b) => eval(a) + eval(b)
case Subtraction(a, b) => eval(a) - eval(b)
case Subtraction(a, b) => eval(a) - eval(b)
case Multiplication(a, b) => eval(a) * eval(b)
case Division(a, b) => eval(a) / eval(b)
}

// our abstract syntax tree model
sealed trait Expr
case class Value(value: String) extends Expr
case class Addition(lhs: Expr, rhs: Expr) extends Expr
case class Subtraction(lhs: Expr, rhs: Expr) extends Expr
case class Value(value: String) extends Expr
case class Addition(lhs: Expr, rhs: Expr) extends Expr
case class Subtraction(lhs: Expr, rhs: Expr) extends Expr
case class Multiplication(lhs: Expr, rhs: Expr) extends Expr
case class Division(lhs: Expr, rhs: Expr) extends Expr
case class Division(lhs: Expr, rhs: Expr) extends Expr
}

/**
* This parser reads simple calculator expressions and builds an AST
* for them, to be evaluated in a separate phase, after parsing is completed.
*/
* This parser reads simple calculator expressions and builds an AST
* for them, to be evaluated in a separate phase, after parsing is completed.
*/
class Calculator2(val input: ParserInput) extends Parser {
import Calculator2._

def InputLine = rule { Expression ~ EOI }

def Expression: Rule1[Expr] = rule {
Term ~ zeroOrMore(
'+' ~ Term ~> Addition
| '-' ~ Term ~> Subtraction)
| '-' ~ Term ~> Subtraction
)
}

def Term = rule {
Factor ~ zeroOrMore(
'*' ~ Factor ~> Multiplication
| '/' ~ Factor ~> Division)
| '/' ~ Factor ~> Division
)
}

def Factor = rule { Number | Parens }
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009-2013 Mathias Doenitz, Alexander Myltsev
* Copyright 2009-2019 Mathias Doenitz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -26,30 +26,32 @@ object CsvParser extends {
case class Error(msg: String)

/**
* Parses the given input into a [[CsvFile]] or an [[Error]] instance.
*/
* Parses the given input into a [[CsvFile]] or an [[Error]] instance.
*/
def apply(input: ParserInput, headerPresent: Boolean = true, fieldDelimiter: Char = ','): Either[Error, CsvFile] = {
import Parser.DeliveryScheme.Either
val parser = new CsvParser(input, headerPresent, fieldDelimiter)
parser.file.run().left.map(error => Error(parser.formatError(error)))
}

private val `TEXTDATA-BASE` = CharPredicate.Printable -- '"'
private val QTEXTDATA = `TEXTDATA-BASE` ++ "\r\n"
private val QTEXTDATA = `TEXTDATA-BASE` ++ "\r\n"
}

/**
* Simple, fast CSV parser.
*
* See http://tools.ietf.org/html/rfc4180#section-2
*/
class CsvParser(val input: ParserInput, headerPresent: Boolean, fieldDelimiter: Char) extends Parser with StringBuilding {
* Simple, fast CSV parser.
*
* See http://tools.ietf.org/html/rfc4180#section-2
*/
class CsvParser(val input: ParserInput, headerPresent: Boolean, fieldDelimiter: Char)
extends Parser with StringBuilding {
import CsvParser._

val TEXTDATA = `TEXTDATA-BASE` -- fieldDelimiter

def file = rule {
OWS ~ optional(test(headerPresent) ~ header ~ NL) ~ oneOrMore(record).separatedBy(NL) ~ optional(NL) ~ EOI ~> CsvFile
OWS ~ optional(test(headerPresent) ~ header ~ NL) ~ oneOrMore(record)
.separatedBy(NL) ~ optional(NL) ~ EOI ~> CsvFile
}

def header = rule { record }
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2009-2013 Mathias Doenitz, Alexander Myltsev
* Copyright 2009-2019 Mathias Doenitz
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -21,9 +21,9 @@ import org.parboiled2._
import spray.json.{ParserInput => _, _}

/**
* This is a feature-complete JSON parser implementation that almost directly
* models the JSON grammar presented at http://www.json.org as a parboiled2 PEG parser.
*/
* This is a feature-complete JSON parser implementation that almost directly
* models the JSON grammar presented at http://www.json.org as a parboiled2 PEG parser.
*/
class JsonParser(val input: ParserInput) extends Parser with StringBuilding {
import CharPredicate.{Digit, Digit19, HexDigit}
import JsonParser._
@@ -32,7 +32,7 @@ class JsonParser(val input: ParserInput) extends Parser with StringBuilding {
def Json = rule { WhiteSpace ~ Value ~ EOI }

def JsonObject: Rule1[JsObject] = rule {
ws('{') ~ zeroOrMore(Pair).separatedBy(ws(',')) ~ ws('}') ~> ((fields: Seq[JsField]) => JsObject(fields :_*))
ws('{') ~ zeroOrMore(Pair).separatedBy(ws(',')) ~ ws('}') ~> ((fields: Seq[JsField]) => JsObject(fields: _*))
}

def Pair = rule { JsonStringUnwrapped ~ ws(':') ~ Value ~> ((_, _)) }
@@ -43,14 +43,14 @@ class JsonParser(val input: ParserInput) extends Parser with StringBuilding {
// we make use of the fact that one-char lookahead is enough to discriminate the cases
run {
(cursorChar: @switch) match {
case '"' => JsonString
case '"' => JsonString
case '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '-' => JsonNumber
case '{' => JsonObject
case '[' => JsonArray
case 't' => JsonTrue
case 'f' => JsonFalse
case 'n' => JsonNull
case _ => MISMATCH
case '{' => JsonObject
case '[' => JsonArray
case 't' => JsonTrue
case 'f' => JsonFalse
case 'n' => JsonNull
case _ => MISMATCH
}
}
}
@@ -61,20 +61,22 @@ class JsonParser(val input: ParserInput) extends Parser with StringBuilding {

def JsonNumber = rule { capture(Integer ~ optional(Frac) ~ optional(Exp)) ~> (JsNumber(_)) ~ WhiteSpace }

def JsonArray = rule { ws('[') ~ zeroOrMore(Value).separatedBy(ws(',')) ~ ws(']') ~> (JsArray(_ :_*)) }
def JsonArray = rule { ws('[') ~ zeroOrMore(Value).separatedBy(ws(',')) ~ ws(']') ~> (JsArray(_: _*)) }

def Characters = rule { zeroOrMore(NormalChar | '\\' ~ EscapedChar) }

def NormalChar = rule { !QuoteBackslash ~ ANY ~ appendSB() }

def EscapedChar = rule (
def EscapedChar = rule(
QuoteSlashBackSlash ~ appendSB()
| 'b' ~ appendSB('\b')
| 'f' ~ appendSB('\f')
| 'n' ~ appendSB('\n')
| 'r' ~ appendSB('\r')
| 't' ~ appendSB('\t')
| Unicode ~> { code => sb.append(code.asInstanceOf[Char]); () }
| Unicode ~> { code =>
sb.append(code.asInstanceOf[Char]); ()
}
)

def Unicode = rule { 'u' ~ capture(HexDigit ~ HexDigit ~ HexDigit ~ HexDigit) ~> (java.lang.Integer.parseInt(_, 16)) }
@@ -99,7 +101,7 @@ class JsonParser(val input: ParserInput) extends Parser with StringBuilding {
}

object JsonParser {
val WhiteSpaceChar = CharPredicate(" \n\r\t\f")
val QuoteBackslash = CharPredicate("\"\\")
val WhiteSpaceChar = CharPredicate(" \n\r\t\f")
val QuoteBackslash = CharPredicate("\"\\")
val QuoteSlashBackSlash = QuoteBackslash ++ "/"
}
Oops, something went wrong.

0 comments on commit 7ed425a

Please sign in to comment.
You can’t perform that action at this time.