Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
mio-19 committed Jan 22, 2025
1 parent 960bea6 commit 0318bbf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ case class LexerState(
errors: Vector[ParseError] = Vector.empty
)

object Lexer {
object LexerV2 {
def apply(tokens: TokenStream): LexerState = {
tokens.headOption match {
case Some(Right(token)) => LexerState(tokens.tail, token)
Expand Down
27 changes: 27 additions & 0 deletions reader/src/test/scala/chester/reader/parseAndCheck.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package chester.reader

import chester.error.Reporter
import chester.readerv2.LexerV2
import chester.syntax.concrete.*
import munit.Assertions.{assertEquals, fail}
import upickle.default.*
Expand Down Expand Up @@ -51,3 +53,28 @@ def getParsed(input: String): Expr = {
value => value
)
}


def parseAndCheckV2(input: String, expected: Expr): Unit = {
// Check old implementation first
parseAndCheck(input, expected)

// Check new implementation
val source = FileNameAndContent("testFile", input)
given reporter: Reporter[ParseError] = new Reporter[ParseError] {
def apply(error: ParseError): Unit = fail(s"Tokenizer error: ${error.message}")
}
val tokenizer = chester.readerv2.Tokenizer(SourceOffset(source))
val tokens = tokenizer.tokenize
val lexerState = LexerV2(tokens)

LexerV2.parseExpr(lexerState).fold(
error => fail(s"V2 Parsing failed for input: $input ${error.message} at ${error.pos}"),
{ case (value, _) =>
assertEquals(value, expected, s"V2 implementation failed for input: $input")
// Also verify serialization works
assertEquals(read[Expr](write[Expr](value)), value)
assertEquals(readBinary[Expr](writeBinary[Expr](value)), value)
}
)
}

0 comments on commit 0318bbf

Please sign in to comment.