Skip to content

Commit

Permalink
Made XPathElemParser.White public, and added Comp parser
Browse files Browse the repository at this point in the history
  • Loading branch information
dvreeze committed Jul 15, 2018
1 parent 6464cc4 commit 5127281
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import fastparse.WhitespaceApi
* XPathElemParser.expr.parse(xpathString)
* }}}
*
* Using the parsers in XPathElemParser may be somewhat risky in that they malfunction when called in isolation,
* Using the parsers in XPathElemParser may be somewhat risky in that they may "malfunction" when called in isolation,
* due to the lack of context (such as cuts to avoid backtracking). Usually it is safer to stick to using the
* XPathParser.xpathExpr parser. On the other hand, exposing parsers for specific AST elements makes it easier to
* "decorate" specific parsers.
Expand All @@ -47,7 +47,11 @@ object XPathElemParser {
private val DT = DelimitingTerminals
private val NDT = NonDelimitingTerminals

private val White = WhitespaceApi.Wrapper {
/**
* WhitespaceApi implementation for ignoring whitespace. This makes the "~" and "rep"
* operators consume and ignore all non-trailing whitespace.
*/
val White = WhitespaceApi.Wrapper {
import fastparse.all._

// TODO Adapt. What about parsing of comments?
Expand Down Expand Up @@ -120,7 +124,7 @@ object XPathElemParser {
}

val comparisonExpr: P[ComparisonExpr] =
P(stringConcatExpr ~ ((valueComp | generalComp | nodeComp) ~/ stringConcatExpr).?) map {
P(stringConcatExpr ~ (comp ~/ stringConcatExpr).?) map {
case (expr1, Some((op, expr2))) => CompoundComparisonExpr(expr1, op, expr2)
case (expr, None) => expr
}
Expand Down Expand Up @@ -717,6 +721,9 @@ object XPathElemParser {

// Operators etc.

val comp: P[Comp] =
P(valueComp | generalComp | nodeComp)

val valueComp: P[ValueComp] =
P((NDT.eqWord | NDT.neWord | NDT.ltWord | NDT.leWord | NDT.gtWord | NDT.geWord).!) map (s => ValueComp.parse(s))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package eu.cdevreeze.xpathparser.parse

import eu.cdevreeze.xpathparser.ast.XPathExpr
import fastparse.WhitespaceApi

/**
* XPath 3.1 parsing support, using FastParse.
Expand All @@ -31,15 +30,7 @@ import fastparse.WhitespaceApi
*/
object XPathParser {

private val White = WhitespaceApi.Wrapper {
import fastparse.all._

// TODO Adapt. What about parsing of comments?

NoTrace(CharPred(c => java.lang.Character.isWhitespace(c)).rep)
}

import White._
import XPathElemParser.White._
import fastparse.noApi._

/**
Expand Down

0 comments on commit 5127281

Please sign in to comment.