Skip to content

Commit

Permalink
Documentation fixes, and some comments/simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Jan 29, 2024
1 parent 5318915 commit 08b1b17
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
12 changes: 2 additions & 10 deletions docs/api-guide/errors/tokenextractors.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ to parse a token from `Lexer`, or not. The return value,
`Token`, is one of the following classes:

```scala
case class Named(name: String, span: TokenSpan) extends Token
case class Named(name: String, span: Int) extends Token
case class Raw(tok: String) extends Token

sealed trait TokenSpan
case class Spanning(line: Int, col: Int) extends TokenSpan
case class Width(w: Int) extends TokenSpan
```

A `Raw` token indicates no further processing of the input could
Expand All @@ -47,10 +43,6 @@ Otherwise, a `Named` token can replace a raw token with something
derived from the input -- the `span` here denotes how wide that
token had been determined to be.

@:callout(warning)
The `Spanning` class will be removed in `parsley:5.0.0`: in future, the width will be in `Named` directly.
@:@

The idea is that `unexpectedToken` should examine the provided
arguments and determine if a more specific token can be extracted
from the residual input, or, if not, produce a final `Raw` token
Expand Down Expand Up @@ -132,7 +124,7 @@ trait LexToken {
def extractItem(cs: Iterable[Char], amountOfInputParserWanted: Int): Token = {
SingleChar.unexpectedToken(cs)
}
def selectToken(matchedToks: List[(String, (Int, Int))]): (String, (Int, Int)) = {
def selectToken(matchedToks: List[(String, Int)]): (String, Int) = {
matchedToks.maxBy(_._2)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ private [errors] final class TrivialErrorBuilder(presentationOffset: Int, outOfR
private val expecteds = mutable.Set.empty[ExpectItem]
private var unexpected = EmptyItem
private val reasons = mutable.Set.empty[String]
private var _acceptingExpected = 0
private def acceptingExpected = _acceptingExpected == 0
private var acceptingExpected = true

/** Updates the position of the error message.
*
Expand Down Expand Up @@ -95,9 +94,10 @@ private [errors] final class TrivialErrorBuilder(presentationOffset: Int, outOfR
* @param action the action to perform, during which no expected items can be accepted
*/
def ignoreExpected(action: =>Unit): Unit = {
_acceptingExpected += 1
val old = acceptingExpected
acceptingExpected = false
action
_acceptingExpected -= 1
acceptingExpected = old
}

/** Makes a `HintCollector` for collecting any hints from a `DefuncHints`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private [errors] sealed abstract class TrivialDefuncError extends DefuncError {
case self: BaseError =>
collector ++= self.expected
collector.updateWidth(self.unexpectedWidth)
// FIXME: Why doesn't this traverse deeper to collect the width?
case self: WithLabel => collector ++= self.labels.map(new ExpectDesc(_))
case self: WithHints =>
self.hints.collect(collector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ object SpaceDesc {
*
* {{{
* multiLineCommentStart = ""
* commentEnd = ""
* lineComment = ""
* multiLineCommendEnd = ""
* lineCommentStart = ""
* lineCommentAllowsEOF = true
* multiLineNestedComments = false
* space = Unicode(Character.isWhitespace)
Expand Down

0 comments on commit 08b1b17

Please sign in to comment.