Skip to content

Commit

Permalink
refactor(token)!: flatten the description packages
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Dec 27, 2024
1 parent 694205e commit ddfef94
Show file tree
Hide file tree
Showing 32 changed files with 37 additions and 46 deletions.
4 changes: 1 addition & 3 deletions docs/api-guide/token/Lexer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ laika.site.metadata.description = "This page describes how Parsley's lexer works
%}

```scala mdoc:invisible
import parsley.token.{Lexer, descriptions, predicate}, descriptions.{LexicalDesc, numeric, text}
import parsley.token.{Lexer, descriptions, predicate}, descriptions._
import predicate.CharPredicate
import numeric._
import text._
```

# Lexer (`parsley.token.Lexer`)
Expand Down
13 changes: 6 additions & 7 deletions docs/tutorial/interlude-1-haskell.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ import parsley.Parsley

object lexer {
import parsley.token.Lexer
import parsley.token.descriptions.{LexicalDesc, NameDesc, SymbolDesc, SpaceDesc,
numeric, text}
import parsley.token.descriptions.{LexicalDesc, NameDesc, SymbolDesc, SpaceDesc, NumericDesc, ExponentDesc, EscapeDesc, TextDesc}
import parsley.token.predicate.{Unicode, Basic}
import parsley.character.newline
private val haskellDesc = LexicalDesc(
Expand All @@ -97,12 +96,12 @@ object lexer {
hardOperators = Set("$", "||", "&&", "<", "<=", ">", ">=", "==", "/=", ":",
"++", "+", "-", "*", "/", "^", "."),
),
numeric.NumericDesc.plain.copy(
octalExponentDesc = numeric.ExponentDesc.NoExponents,
binaryExponentDesc = numeric.ExponentDesc.NoExponents,
NumericDesc.plain.copy(
octalExponentDesc = ExponentDesc.NoExponents,
binaryExponentDesc = ExponentDesc.NoExponents,
),
text.TextDesc.plain.copy(
escapeSequences = text.EscapeDesc.haskell,
TextDesc.plain.copy(
escapeSequences = EscapeDesc.haskell,
),
SpaceDesc.plain.copy(
lineCommentStart = "--",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import parsley.debug.{Breakpoint, Profiler}
import parsley.errors.ErrorBuilder
import parsley.state.Ref
import parsley.token.descriptions.SpaceDesc
import parsley.token.descriptions.numeric.PlusSignPresence
import parsley.token.descriptions.PlusSignPresence
import parsley.token.errors.{ErrorConfig, LabelConfig, LabelWithExplainConfig, SpecializedFilterConfig}
import parsley.token.predicate.CharPredicate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/
package parsley.internal.deepembedding.singletons

import parsley.token.descriptions.SpaceDesc
import parsley.token.descriptions.numeric.PlusSignPresence
import parsley.token.descriptions.{PlusSignPresence, SpaceDesc}
import parsley.token.errors.ErrorConfig

import parsley.internal.deepembedding.Sign.SignType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
package parsley.internal.machine.instructions

import parsley.token.descriptions.numeric.PlusSignPresence
import parsley.token.descriptions.PlusSignPresence

import parsley.internal.deepembedding.Sign.{CombinedType, DoubleType, IntType, SignType}
import parsley.internal.errors.{ExpectItem, ExpectRaw}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package parsley.token.descriptions
*/
final case class LexicalDesc (nameDesc: NameDesc,
symbolDesc: SymbolDesc,
numericDesc: numeric.NumericDesc,
textDesc: text.TextDesc,
numericDesc: NumericDesc,
textDesc: TextDesc,
spaceDesc: SpaceDesc)

/** This object contains any preconfigured lexical definitions.
Expand All @@ -28,5 +28,5 @@ object LexicalDesc {
/** Defaults to the plain definitions of each sub-description.
* @since 4.0.0
*/
val plain = LexicalDesc(NameDesc.plain, SymbolDesc.plain, numeric.NumericDesc.plain, text.TextDesc.plain, SpaceDesc.plain)
val plain = LexicalDesc(NameDesc.plain, SymbolDesc.plain, NumericDesc.plain, TextDesc.plain, SpaceDesc.plain)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.token.descriptions.numeric
package parsley.token.descriptions

/** This class, and its subtypes, describe whether or not the plus sign (`+`) is allowed
* in a specific position.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley.token.descriptions.text
package parsley.token.descriptions

import parsley.token.predicate.{CharPredicate, Unicode}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import parsley.character, character.{isHexDigit, isOctDigit, satisfy}
import parsley.combinator.optional
import parsley.errors.combinator.ErrorMethods
import parsley.syntax.character.charLift
import parsley.token.descriptions.numeric.{BreakCharDesc, NumericDesc}
import parsley.token.descriptions.{BreakCharDesc, NumericDesc}
import parsley.token.errors.{ErrorConfig, LabelConfig}

private [token] class Generic(err: ErrorConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package parsley.token.numeric

import parsley.Parsley
import parsley.token.descriptions.numeric.NumericDesc
import parsley.token.descriptions.NumericDesc
import parsley.token.errors.{ErrorConfig, LabelWithExplainConfig}

/** This class defines a uniform interface for defining parsers for integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package parsley.token.numeric

import parsley.Parsley, Parsley.atomic
import parsley.token.descriptions.numeric.NumericDesc
import parsley.token.descriptions.NumericDesc
import parsley.token.errors.ErrorConfig

import parsley.internal.deepembedding.Sign.CombinedType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package parsley.token.numeric

import parsley.Parsley, Parsley.atomic
import parsley.token.descriptions.numeric.NumericDesc
import parsley.token.descriptions.NumericDesc
import parsley.token.errors.{ErrorConfig, LabelWithExplainConfig}

import parsley.internal.deepembedding.Sign.IntType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package parsley.token.numeric

import parsley.Parsley, Parsley.atomic
import parsley.token.descriptions.numeric.NumericDesc
import parsley.token.descriptions.NumericDesc
import parsley.token.errors.ErrorConfig

import parsley.internal.deepembedding.Sign.DoubleType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package parsley.token.numeric

import parsley.Parsley, Parsley.atomic
import parsley.token.descriptions.numeric.NumericDesc
import parsley.token.descriptions.NumericDesc
import parsley.token.errors.ErrorConfig

import org.typelevel.scalaccompat.annotation.unused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import parsley.character.oneOf
import parsley.combinator.optional
import parsley.errors.combinator.ErrorMethods
import parsley.syntax.character.charLift
import parsley.token.descriptions.numeric.{BreakCharDesc, NumericDesc}
import parsley.token.descriptions.{BreakCharDesc, NumericDesc}
import parsley.token.errors.{ErrorConfig, LabelWithExplainConfig}

private [token] final class UnsignedInteger(desc: NumericDesc, err: ErrorConfig, generic: Generic) extends IntegerParsers(desc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import parsley.errors.combinator.{amendThenDislodge, entrench}
import parsley.lift.lift2
import parsley.state.Ref
import parsley.syntax.character.charLift
import parsley.token.descriptions.numeric.{BreakCharDesc, ExponentDesc, NumericDesc}
import parsley.token.descriptions.{BreakCharDesc, ExponentDesc, NumericDesc}
import parsley.token.errors.{ErrorConfig, LabelConfig}

private [token] final class UnsignedReal(desc: NumericDesc, err: ErrorConfig, generic: Generic) extends RealParsers(err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package parsley.token.text

import parsley.Parsley
import parsley.character.char
import parsley.token.descriptions.text.TextDesc
import parsley.token.descriptions.TextDesc
import parsley.token.errors.{ErrorConfig, FilterConfig, LabelConfig, LabelWithExplainConfig}

private [token] final class ConcreteCharacter(desc: TextDesc, escapes: Escape, err: ErrorConfig) extends CharacterParsers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package parsley.token.text

import parsley.Parsley, Parsley.empty
import parsley.character.char
import parsley.token.descriptions.text.{EscapeDesc, NumberOfDigits, NumericEscape}
import parsley.token.descriptions.{EscapeDesc, NumberOfDigits, NumericEscape}
import parsley.token.errors.{ErrorConfig, NotConfigured}
import parsley.token.numeric

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package parsley.token.text

import parsley.Parsley, Parsley.{empty, some}
import parsley.character.{char, satisfyMap}
import parsley.token.descriptions.text.EscapeDesc
import parsley.token.descriptions.EscapeDesc
import parsley.token.errors.ErrorConfig
import parsley.token.predicate.{Basic, CharPredicate, NotRequired, Unicode}
import parsley.unicode.{satisfyMap => satisfyMapUtf16}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import parsley.internal.deepembedding.singletons.token.*
import parsley.internal.errors.{CaretWidth, FlexibleCaret}
import parsley.state.Ref
import parsley.token.descriptions.SpaceDesc
import parsley.token.descriptions.numeric.PlusSignPresence
import parsley.token.descriptions.PlusSignPresence
import parsley.token.errors.{ErrorConfig, BasicFilter, LabelConfig, SpecializedFilterConfig}
import parsley.token.predicate.Basic
import parsley.token.errors.NotConfigured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ package parsley.token
import parsley.ParsleyTest

import descriptions._
import descriptions.numeric._
import descriptions.text._

class DescriptionRequireTests extends ParsleyTest {
"SymbolDesc" should "not allow an intersection between operators and keywords" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class TokeniserTests extends ParsleyTest {
"trait", "abstract", "override", "val", "var", "lazy"),
hardOperators = Set(":", "=", "::", ":="),
caseSensitive = true),
desc.numeric.NumericDesc.plain,
desc.text.TextDesc.plain,
desc.NumericDesc.plain,
desc.TextDesc.plain,
desc.SpaceDesc(multiLineCommentStart = "/*",
multiLineCommentEnd = "*/",
lineCommentStart = "//",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import parsley.token.predicate.implicits.Basic.charToBasic
import org.scalacheck.Gen
import org.scalacheck.Arbitrary

import parsley.token.descriptions.text._

object DescGen {
// NAMES
val identifierLetterGen = Gen.oneOf[CharPredicate](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package parsley.token.descriptions

import org.scalacheck.Shrink

import parsley.token.descriptions.text._
import org.typelevel.scalaccompat.annotation._

object DescShrink {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Predef.{ArrowAssoc => _, _}

import parsley.ParsleyTest
import parsley.token.LexemeImpl
import parsley.token.descriptions.numeric._, ExponentDesc.NoExponents
import parsley.token.descriptions._, ExponentDesc.NoExponents
import parsley.token.errors.ErrorConfig
import org.scalactic.source.Position

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Predef.{ArrowAssoc => _, _}

import parsley.ParsleyTest
import parsley.token.LexemeImpl
import parsley.token.descriptions.numeric._
import parsley.token.descriptions._
import parsley.token.errors.ErrorConfig
import org.scalactic.source.Position

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Predef.{ArrowAssoc => _, _}

import parsley.ParsleyTest
import parsley.token.LexemeImpl
import parsley.token.descriptions.numeric._
import parsley.token.descriptions._
import parsley.token.errors.ErrorConfig
import org.scalactic.source.Position

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.Predef.{ArrowAssoc => _, _}
import parsley.ParsleyTest
import parsley.token.LexemeImpl

import parsley.token.descriptions.text._
import parsley.token.descriptions._
import parsley.token.errors.ErrorConfig
import parsley.token.predicate._
import org.scalactic.source.Position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.scalatest.matchers._
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks

import parsley.Parsley.eof
import parsley.token.descriptions.text._
import parsley.token.descriptions._
import parsley.token.errors.ErrorConfig
import org.scalacheck.Gen

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package parsley.token.text
import scala.Predef.{String => SString, ArrowAssoc => _, _}
import parsley.ParsleyTest

import parsley.token.descriptions.text._
import parsley.token.descriptions._
import parsley.token.errors.ErrorConfig
import org.scalactic.source.Position

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import parsley.Parsley, Parsley.{atomic, empty, pure}
import parsley.character.{bit, char, digit, hexDigit, octDigit, strings}
import parsley.combinator.guardS
import parsley.syntax.zipped._
import parsley.token.descriptions.text.{EscapeDesc, NumberOfDigits, NumericEscape}
import parsley.token.descriptions.{EscapeDesc, NumberOfDigits, NumericEscape}
import parsley.token.errors.{ErrorConfig, NotConfigured}
import parsley.token.numeric

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import scala.Predef.{ArrowAssoc => _, _}
import parsley.ParsleyTest
import parsley.token.LexemeImpl

import parsley.token.descriptions.text._
import parsley.token.descriptions._
import parsley.token.errors.ErrorConfig
import parsley.token.predicate._
import parsley.character.space
Expand Down

0 comments on commit ddfef94

Please sign in to comment.