mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-03 22:20:17 +00:00
fix(compiler): Incorrect focus on error [LNG-274] (#959)
This commit is contained in:
parent
3b0d31325a
commit
6e6b567f8e
@ -62,9 +62,9 @@ runner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rewrite {
|
rewrite.rules = [Imports]
|
||||||
rules = [
|
rewrite.imports.sort = ascii
|
||||||
SortImports
|
rewrite.imports.groups = [
|
||||||
]
|
["aqua\\..*"]
|
||||||
}
|
]
|
||||||
#runner.dialect = scala3
|
#runner.dialect = scala3
|
||||||
|
@ -1,6 +1,2 @@
|
|||||||
alias Troll: u32
|
func arr(strs: []string) -> []string
|
||||||
|
<- strs
|
||||||
func test() -> i8:
|
|
||||||
MyAbility = Troll(f = "sf")
|
|
||||||
|
|
||||||
<- 42
|
|
@ -1,17 +1,14 @@
|
|||||||
package aqua
|
package aqua
|
||||||
|
|
||||||
import aqua.compiler.AquaError.{ParserError as AquaParserError, *}
|
|
||||||
import aqua.compiler.*
|
import aqua.compiler.*
|
||||||
|
import aqua.compiler.AquaError.{ParserError as AquaParserError, *}
|
||||||
import aqua.files.FileModuleId
|
import aqua.files.FileModuleId
|
||||||
import aqua.io.AquaFileError
|
import aqua.io.AquaFileError
|
||||||
import aqua.parser.lift.{FileSpan, Span}
|
import aqua.parser.lift.{FileSpan, Span}
|
||||||
import aqua.parser.{ArrowReturnError, BlockIndentError, LexerError, ParserError}
|
import aqua.parser.{ArrowReturnError, BlockIndentError, LexerError, ParserError}
|
||||||
import aqua.semantics.{HeaderError, RulesViolated, SemanticWarning, WrongAST}
|
import aqua.semantics.{HeaderError, RulesViolated, SemanticWarning, WrongAST}
|
||||||
|
|
||||||
import cats.parse.LocationMap
|
import cats.Show
|
||||||
import cats.parse.Parser.Expectation
|
|
||||||
import cats.parse.Parser.Expectation.*
|
|
||||||
import cats.{Eval, Show}
|
|
||||||
|
|
||||||
object Rendering {
|
object Rendering {
|
||||||
|
|
||||||
|
35
io/src/test/scala/aqua/RenderingSpec.scala
Normal file
35
io/src/test/scala/aqua/RenderingSpec.scala
Normal file
@ -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")
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,17 @@
|
|||||||
package aqua.parser
|
package aqua.parser
|
||||||
|
|
||||||
import aqua.parser.Ast.Tree
|
|
||||||
import aqua.parser.{Ast, LexerError, ParserError}
|
|
||||||
import aqua.parser.expr.RootExpr
|
import aqua.parser.expr.RootExpr
|
||||||
import aqua.parser.head.HeadExpr
|
import aqua.parser.head.HeadExpr
|
||||||
import aqua.parser.lexer.Token
|
|
||||||
import aqua.parser.lift.LiftParser.LiftErrorOps
|
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}
|
import cats.data.{Validated, ValidatedNec}
|
||||||
import cats.parse.{LocationMap, Parser as P, Parser0 as P0}
|
import cats.parse.{Parser as P, Parser0 as P0}
|
||||||
import cats.{~>, Comonad, Eval, Id}
|
import cats.{Comonad, ~>}
|
||||||
|
|
||||||
object Parser extends scribe.Logging {
|
object Parser extends scribe.Logging {
|
||||||
|
lazy val spanParser: P0[ValidatedNec[ParserError[S], Ast[S]]] = parserSchema
|
||||||
import Span.spanLiftParser
|
|
||||||
lazy val spanParser = parserSchema
|
|
||||||
import LiftParser.Implicits.idLiftParser
|
|
||||||
|
|
||||||
def parserSchema: P0[ValidatedNec[ParserError[Span.S], Ast[Span.S]]] = {
|
def parserSchema: P0[ValidatedNec[ParserError[Span.S], Ast[Span.S]]] = {
|
||||||
logger.trace("creating schema...")
|
logger.trace("creating schema...")
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package aqua.parser.lift
|
package aqua.parser.lift
|
||||||
|
|
||||||
import cats.data.NonEmptyList
|
import cats.Comonad
|
||||||
import cats.parse.{LocationMap, Parser as P, Parser0}
|
import cats.parse.{LocationMap, Parser0, Parser as P}
|
||||||
import cats.{Comonad, Eval}
|
|
||||||
|
|
||||||
import scala.language.implicitConversions
|
import scala.language.implicitConversions
|
||||||
|
|
||||||
@ -51,11 +50,14 @@ object Span {
|
|||||||
str: String,
|
str: String,
|
||||||
idx: Int,
|
idx: Int,
|
||||||
len: Int
|
len: Int
|
||||||
): FocusedLine = FocusedLine(
|
): FocusedLine = {
|
||||||
str.substring(0, idx),
|
val end = idx + len
|
||||||
str.substring(idx, idx + len),
|
FocusedLine(
|
||||||
str.substring(idx + len)
|
str.slice(0, idx),
|
||||||
)
|
str.slice(idx, end),
|
||||||
|
str.slice(end, str.length)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
final case class NumberedLine[T](
|
final case class NumberedLine[T](
|
||||||
number: Int,
|
number: Int,
|
||||||
|
@ -4,28 +4,24 @@ import aqua.AquaSpec
|
|||||||
import aqua.parser.expr.*
|
import aqua.parser.expr.*
|
||||||
import aqua.parser.expr.func.*
|
import aqua.parser.expr.func.*
|
||||||
import aqua.parser.lexer.*
|
import aqua.parser.lexer.*
|
||||||
import aqua.parser.lift.LiftParser.Implicits.idLiftParser
|
|
||||||
import aqua.parser.lift.Span
|
import aqua.parser.lift.Span
|
||||||
import aqua.parser.lift.Span.{P0ToSpan, PToSpan}
|
|
||||||
import aqua.types.ScalarType.*
|
import aqua.types.ScalarType.*
|
||||||
|
|
||||||
import cats.Id
|
import cats.{Eval, Id}
|
||||||
import cats.data.{Chain, NonEmptyList}
|
|
||||||
import cats.data.Chain.*
|
import cats.data.Chain.*
|
||||||
|
import cats.data.Validated.{Invalid, Valid}
|
||||||
|
import cats.data.{Chain, NonEmptyList}
|
||||||
import cats.free.Cofree
|
import cats.free.Cofree
|
||||||
import cats.syntax.foldable.*
|
import cats.syntax.foldable.*
|
||||||
import cats.data.Validated.{Invalid, Valid}
|
|
||||||
import org.scalatest.flatspec.AnyFlatSpec
|
import org.scalatest.flatspec.AnyFlatSpec
|
||||||
import org.scalatest.{Inside, Inspectors}
|
|
||||||
import org.scalatest.matchers.should.Matchers
|
import org.scalatest.matchers.should.Matchers
|
||||||
import cats.~>
|
import org.scalatest.{Inside, Inspectors}
|
||||||
import cats.Eval
|
|
||||||
|
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import scala.language.implicitConversions
|
import scala.language.implicitConversions
|
||||||
|
|
||||||
class FuncExprSpec extends AnyFlatSpec with Matchers with Inside with Inspectors with AquaSpec {
|
class FuncExprSpec extends AnyFlatSpec with Matchers with Inside with Inspectors with AquaSpec {
|
||||||
import AquaSpec.{given, *}
|
import AquaSpec.{*, given}
|
||||||
|
|
||||||
private val parser = Parser.spanParser
|
private val parser = Parser.spanParser
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user