Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a clarification to the docs about trailing whitespace #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import utest._
* Same as MathTests, but demonstrating the use of whitespace
*/
object WhiteSpaceMathTests extends TestSuite{
val White = WhitespaceApi.Wrapper{
val White = fastparse.WhitespaceApi.Wrapper{
Copy link
Contributor Author

@laughedelic laughedelic Aug 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed here to compile, but as it is quoted in the docs without the package context, one cannot just copy-paste this piece of code (it's not clear where does this WhitespaceApi come from).

import fastparse.all._
NoTrace(" ".rep)
}
import fastparse.noApi._
import White._

def eval(tree: (Int, Seq[(String, Int)])): Int = {
val (base, ops) = tree
ops.foldLeft(base){ case (left, (op, right)) => op match{
case "+" => left + right case "-" => left - right
case "*" => left * right case "/" => left / right
}}
}

val number: P[Int] = P( CharIn('0'to'9').rep(1).!.map(_.toInt) )
val parens: P[Int] = P( "(" ~/ addSub ~ ")" )
val factor: P[Int] = P( number | parens )
Expand Down
7 changes: 3 additions & 4 deletions readme/Readme.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
@hl.ref(tests/"WhiteSpaceMathTests.scala", "val White", "val tests")

@p
To handle whitespace and other non-significant characters with FastParse, use the @hl.scala{WhitespaceApi} as a substitue for the normal API that is provided for parsers. This modifies the @hl.scala{~} and @hl.scala{.rep} operators to consume all non-trailing whitespace and ignoring it.
To handle whitespace and other non-significant characters with FastParse, use the @hl.scala{WhitespaceApi} as a substitute for the normal API that is provided for parsers. This modifies the @hl.scala{~} and @hl.scala{.rep} operators to consume all non-trailing whitespace and ignore it. This means that whitespace is skipped between parsers, so if you want to consume it in the beginning or the end of input, use @sect.ref("End, Start", "Start or End") parsers.

@p
Note how you can pass in whatever definition of whitespace you want: here we're passing in a simple @hl.scala{" ".rep}, but in a more sophisticated parser you may wish to include tabs, newlines, comments or even nested comments. The whitespace parser can be arbitrarily complex.
Expand Down Expand Up @@ -808,10 +808,10 @@
@ul
@li
Object @hl.scala{Result} has been renamed to @hl.scala{Parsed}

@li
Former @hl.scala{Result} has moved to @hl.scala{Parsed}.

@li
Methods for position retrieval @hl.scala{line} and @hl.scala{col} have moved to @hl.scala{Failure.Extra}

Expand Down Expand Up @@ -890,4 +890,3 @@
Added @hl.scala{IgnoreCase} combinator, for case-insensitive string matching
@li
Cross-published for Scala 2.10