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

fix(compiler): Incorrect focus on error [LNG-274] #959

Merged
merged 9 commits into from
Nov 2, 2023
10 changes: 5 additions & 5 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ runner {
}
}

rewrite {
rules = [
SortImports
]
}
rewrite.rules = [Imports]
rewrite.imports.sort = ascii
rewrite.imports.groups = [
["aqua\\..*"]
]
#runner.dialect = scala3
8 changes: 2 additions & 6 deletions aqua-src/antithesis.aqua
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
alias Troll: u32

func test() -> i8:
MyAbility = Troll(f = "sf")

<- 42
func arr(strs: []string) -> []string
<- strs
7 changes: 2 additions & 5 deletions io/src/main/scala/aqua/Rendering.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package aqua

import aqua.compiler.AquaError.{ParserError as AquaParserError, *}
import aqua.compiler.*
import aqua.compiler.AquaError.{ParserError as AquaParserError, *}
import aqua.files.FileModuleId
import aqua.io.AquaFileError
import aqua.parser.lift.{FileSpan, Span}
import aqua.parser.{ArrowReturnError, BlockIndentError, LexerError, ParserError}
import aqua.semantics.{HeaderError, RulesViolated, SemanticWarning, WrongAST}

import cats.parse.LocationMap
import cats.parse.Parser.Expectation
import cats.parse.Parser.Expectation.*
import cats.{Eval, Show}
import cats.Show

object Rendering {

Expand Down
35 changes: 35 additions & 0 deletions io/src/test/scala/aqua/RenderingSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package aqua

import aqua.Rendering.given
import aqua.compiler.AquaError
import aqua.files.FileModuleId
import aqua.io.AquaFileError
import aqua.parser.LexerError
import aqua.parser.lift.{FileSpan, Span}

import cats.Eval
import cats.data.NonEmptyList
import cats.parse.Parser.Expectation.InRange
import cats.parse.{LocationMap, Parser}
import cats.syntax.show.*
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.{Inside, Inspectors}

class RenderingSpec extends AnyFlatSpec with Matchers with Inside with Inspectors {

it should "render end of a string properly" in {
val script =
"""func arr(strs: []string) -> []string
| <- strs""".stripMargin

val error = Parser.Error(8, NonEmptyList.one(InRange(36, ':', ':')))
val fileSpan = FileSpan("file", Eval.now(LocationMap(script)), Span(8, 9))


val result: AquaError[FileModuleId, AquaFileError, FileSpan.F] =
AquaError.ParserError(LexerError((fileSpan, error)))

result.show should include("Syntax error: file:1:37")
}
}
16 changes: 6 additions & 10 deletions parser/src/main/scala/aqua/parser/Parser.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package aqua.parser

import aqua.parser.Ast.Tree
import aqua.parser.{Ast, LexerError, ParserError}
import aqua.parser.expr.RootExpr
import aqua.parser.head.HeadExpr
import aqua.parser.lexer.Token
import aqua.parser.lift.LiftParser.LiftErrorOps
import aqua.parser.lift.{FileSpan, LiftParser, Span}
import aqua.parser.lift.Span.S
import aqua.parser.lift.{LiftParser, Span}

import cats.data.{Validated, ValidatedNec}
DieMyst marked this conversation as resolved.
Show resolved Hide resolved
import cats.parse.{LocationMap, Parser as P, Parser0 as P0}
import cats.{~>, Comonad, Eval, Id}
import cats.parse.{Parser as P, Parser0 as P0}
import cats.{Comonad, ~>}

object Parser extends scribe.Logging {

import Span.spanLiftParser
lazy val spanParser = parserSchema
import LiftParser.Implicits.idLiftParser
lazy val spanParser: P0[ValidatedNec[ParserError[S], Ast[S]]] = parserSchema

def parserSchema: P0[ValidatedNec[ParserError[Span.S], Ast[Span.S]]] = {
logger.trace("creating schema...")
Expand Down
18 changes: 10 additions & 8 deletions parser/src/main/scala/aqua/parser/lift/Span.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package aqua.parser.lift

import cats.data.NonEmptyList
import cats.parse.{LocationMap, Parser as P, Parser0}
import cats.{Comonad, Eval}
import cats.Comonad
import cats.parse.{LocationMap, Parser0, Parser as P}

import scala.language.implicitConversions

Expand Down Expand Up @@ -51,11 +50,14 @@ object Span {
str: String,
idx: Int,
len: Int
): FocusedLine = FocusedLine(
str.substring(0, idx),
str.substring(idx, idx + len),
str.substring(idx + len)
)
): FocusedLine = {
val end = idx + len
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Could you wrap the method in {}?
I don't like indentation as scope marking

Copy link
Member Author

Choose a reason for hiding this comment

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

me too

FocusedLine(
str.slice(0, idx),
str.slice(idx, end),
str.slice(end, str.length)
)
}

final case class NumberedLine[T](
number: Int,
Expand Down
14 changes: 5 additions & 9 deletions parser/src/test/scala/aqua/parser/FuncExprSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@ import aqua.AquaSpec
import aqua.parser.expr.*
import aqua.parser.expr.func.*
import aqua.parser.lexer.*
import aqua.parser.lift.LiftParser.Implicits.idLiftParser
import aqua.parser.lift.Span
import aqua.parser.lift.Span.{P0ToSpan, PToSpan}
import aqua.types.ScalarType.*

import cats.Id
import cats.data.{Chain, NonEmptyList}
import cats.{Eval, Id}
import cats.data.Chain.*
import cats.data.Validated.{Invalid, Valid}
import cats.data.{Chain, NonEmptyList}
import cats.free.Cofree
import cats.syntax.foldable.*
import cats.data.Validated.{Invalid, Valid}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.{Inside, Inspectors}
import org.scalatest.matchers.should.Matchers
import cats.~>
import cats.Eval
import org.scalatest.{Inside, Inspectors}

import scala.collection.mutable
import scala.language.implicitConversions

class FuncExprSpec extends AnyFlatSpec with Matchers with Inside with Inspectors with AquaSpec {
import AquaSpec.{given, *}
import AquaSpec.{*, given}

private val parser = Parser.spanParser

Expand Down
Loading