Skip to content

Commit

Permalink
doc: properly refer to changes to ErrorBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Apr 9, 2024
1 parent 8b945bb commit f957822
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions docs/api-guide/errors/ErrorBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ testing generated error messages.
Error messages within `parsley` take two different forms: *vanilla*
or *specialised*. The error chosen depends on the combinators used
to produce it: `empty`, `unexpected`, `char`, `string`, etc all produce vanilla errors; and `fail` and its derivatives produce
specialised errors. An `ErrorBuilder` must describe how to format
specialised errors. An `ErrorBuilder` must describe how to build
both kinds of error; their structure is explained below.

### Vanilla Errors
Expand Down Expand Up @@ -134,8 +134,8 @@ exposing unnecessary information into the rest of the system.
After these types are specified, the methods of the typeclass
can be implemented. These put together the primtive-most components
and compose them into the larger whole. The documentation of the
typeclass details the role of these well enough, however. For example's sake, however, these are the two shapes of call that will
be made for the different types of error messages:
typeclass details the role of these well enough, however. For example's sake, however, these
are the two shapes of call that will be made for the different types of error messages:

#### Vanilla
```
Expand All @@ -148,7 +148,7 @@ be made for the different types of error messages:
```
```scala mdoc:silent:nest
val builder = implicitly[ErrorBuilder[String]]
builder.format (
builder.build (
builder.pos(1, 5),
builder.source(None),
builder.vanillaError (
Expand All @@ -164,7 +164,7 @@ builder.format (
builder.combineMessages(List(
builder.reason("'-' is a binary operator")
)),
builder.lineInfo("3+4-", Nil, Nil, 4, 4)
builder.lineInfo("3+4-", Nil, Nil, 1, 4, 4)
)
)
```
Expand All @@ -185,7 +185,7 @@ In file 'foo.txt' (line 2, column 6):
```
```scala mdoc:silent:nest
val builder = implicitly[ErrorBuilder[String]]
builder.format (
builder.build (
builder.pos(2, 6),
builder.source(Some("foo.txt")),
builder.specializedError (
Expand All @@ -196,6 +196,7 @@ builder.format (
builder.lineInfo("second line",
List("first line of input"),
List("third line", "fourth line"),
2,
5,
3)
)
Expand All @@ -222,7 +223,7 @@ case class TestNamed(item: String) extends TestErrorItem
case object TestEndOfInput extends TestErrorItem
```

This type, as will become evident from the formatter derived
This type, as will become evident from the builder derived
from it, is lossy and does not perfectly encode all the
information available. Notice that `TestErrorItem` is a supertype
of `TestRaw`, `TestNamed`, and `TestEndOfInput`: this is
Expand Down Expand Up @@ -257,8 +258,8 @@ methods make it very easy to fill in the gaps:
```scala
class TestErrorBuilder extends ErrorBuilder[TestError] {
//...
def format(pos: (Int, Int), source: Unit,
lines: TestErrorLines): TestError = TestError(pos, lines)
def build(pos: (Int, Int), source: Unit,
lines: TestErrorLines): TestError = TestError(pos, lines)
def vanillaError(
unexpected: Option[TestErrorItem],
expected: Set[TestErrorItem],
Expand Down Expand Up @@ -287,7 +288,7 @@ class TestErrorBuilder extends ErrorBuilder[TestError] {
line: String,
linesBefore: Seq[String],
linesAfter: Seq[String],
errorPointsAt: Int, errorWidth: Int
lineNum: Int, errorPointsAt: Int, errorWidth: Int
): Unit = ()

// The implementation of this is usually provided by a mixed-in
Expand Down

0 comments on commit f957822

Please sign in to comment.