Skip to content

Commit

Permalink
use .apply constructor syntax for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudolph committed Sep 7, 2021
1 parent 8c8d46d commit 5ffb5b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,24 @@ class Calculator2(val input: ParserInput) extends Parser {
def Expression: Rule1[Expr] =
rule {
Term ~ zeroOrMore(
'+' ~ Term ~> (Addition(_, _))
| '-' ~ Term ~> (Subtraction(_, _))
'+' ~ Term ~> Addition.apply
| '-' ~ Term ~> Subtraction.apply
)
}

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

def Factor = rule(Number | Parens)

def Parens = rule('(' ~ Expression ~ ')')

def Number = rule(capture(Digits) ~> (Value(_)))
def Number = rule(capture(Digits) ~> Value.apply)

def Digits = rule(oneOrMore(CharPredicate.Digit))
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class CsvParser(val input: ParserInput, headerPresent: Boolean, fieldDelimiter:
def file =
rule {
OWS ~ optional(test(headerPresent) ~ header ~ NL) ~ oneOrMore(record)
.separatedBy(NL) ~ optional(NL) ~ EOI ~> (CsvFile(_, _))
.separatedBy(NL) ~ optional(NL) ~ EOI ~> CsvFile.apply
}

def header = rule(record)

def record = rule(oneOrMore(field).separatedBy(fieldDelimiter) ~> (Record(_)))
def record = rule(oneOrMore(field).separatedBy(fieldDelimiter) ~> Record.apply)

def field = rule(`quoted-field` | `unquoted-field`)

Expand Down

0 comments on commit 5ffb5b6

Please sign in to comment.