Skip to content

Commit

Permalink
avoid postfixOps
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed May 18, 2021
1 parent 1bb91e2 commit b91c3ff
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions scalap/src/main/scala/org/json4s/scalap/SeqRule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

package org.json4s.scalap

import language.postfixOps

/**
* A workaround for the difficulties of dealing with
* a contravariant 'In' parameter type...
Expand Down Expand Up @@ -51,7 +49,7 @@ class SeqRule[S, +A, +X](rule: Rule[S, S, A, X]) {
* Creates a rule that always succeeds with a Boolean value.
* Value is 'true' if this rule succeeds, 'false' otherwise
*/
def -? = ? map { _ isDefined }
def -? = ? map (_.isDefined)

def * = from[S] {
// tail-recursive function with reverse list accumulator
Expand All @@ -67,12 +65,12 @@ class SeqRule[S, +A, +X](rule: Rule[S, S, A, X]) {

def ~>?[B >: A, X2 >: X](f: => Rule[S, S, B => B, X2]) = for {
a <- rule
fs <- f ?
fs <- f.?
} yield fs.foldLeft[B](a) { (b, f) => f(b) }

def ~>*[B >: A, X2 >: X](f: => Rule[S, S, B => B, X2]) = for {
a <- rule
fs <- f *
fs <- f.*
} yield fs.foldLeft[B](a) { (b, f) => f(b) }

def ~*~[B >: A, X2 >: X](join: => Rule[S, S, (B, B) => B, X2]) = {
Expand All @@ -83,13 +81,13 @@ class SeqRule[S, +A, +X](rule: Rule[S, S, A, X]) {
}

/** Repeats this rule one or more times with a separator (which is discarded) */
def +/[X2 >: X](sep: => Rule[S, S, Any, X2]) = rule ~++ (sep -~ rule *)
def +/[X2 >: X](sep: => Rule[S, S, Any, X2]) = rule ~++ ((sep -~ rule).*)

/** Repeats this rule zero or more times with a separator (which is discarded) */
def */[X2 >: X](sep: => Rule[S, S, Any, X2]) = +/(sep) | state[S].nil

def *~-[Out, X2 >: X](end: => Rule[S, Out, Any, X2]) = (rule - end *) ~- end
def +~-[Out, X2 >: X](end: => Rule[S, Out, Any, X2]) = (rule - end +) ~- end
def *~-[Out, X2 >: X](end: => Rule[S, Out, Any, X2]) = ((rule - end).*) ~- end
def +~-[Out, X2 >: X](end: => Rule[S, Out, Any, X2]) = ((rule - end).+) ~- end

/** Repeats this rule num times */
def times(num: Int): Rule[S, S, Seq[A], X] = from[S] {
Expand Down

0 comments on commit b91c3ff

Please sign in to comment.