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

Remove redundant root space parsing #386

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}
* ↑______________↑
* }}}
*/
private case object AssignmentParser {
private object AssignmentParser {

/**
* Parses a required assignment and reports errors if it is missing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ private object BlockParser {
P {
Index ~
TokenParser.parseOrFail(Token.OpenCurly) ~
SpaceParser.parseOrFail.? ~
BlockBodyParser.parseOrFailChild(Token.CloseCurly) ~
SpaceParser.parseOrFail.? ~
TokenParser.parse(Token.CloseCurly) ~
Index
} map {
case (from, openCurly, preBodySpace, body, postBodySpace, closeCurly, to) =>
case (from, openCurly, body, closeCurly, to) =>
SoftAST.Block(
index = range(from, to),
openCurly = openCurly,
preBodySpace = preBodySpace,
body = body,
postBodySpace = postBodySpace,
closeCurly = closeCurly
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.SoftAST

object ExpressionBlockParser {
private object ExpressionBlockParser {

/**
* Parses two or more expressions as a block.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.SoftAST

private case object InfixCallParser {
private object InfixCallParser {

def parseOrFail[Unknown: P]: P[SoftAST.InfixExpression] =
P {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private case object MethodCallParser {
private object MethodCallParser {

def parseOrFail[Unknown: P]: P[SoftAST.MethodCall] =
P {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private case object ParameterParser {
private object ParameterParser {

def parse[Unknown: P]: P[SoftAST.Group[Token.OpenParen.type, Token.CloseParen.type]] =
GroupParser.parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.{point, range}
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

object StringLiteralParser {
private object StringLiteralParser {

/**
* Parses text enclosed in quotes, e.g. `"some text"`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ object SoftAST {
case class Block(
index: SourceIndex,
openCurly: TokenDocExpectedAST[Token.OpenCurly.type],
preBodySpace: Option[Space],
body: BlockBody,
postBodySpace: Option[Space],
closeCurly: TokenDocExpectedAST[Token.CloseCurly.type])
extends ExpressionAST

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft

import org.alephium.ralph.lsp.access.compiler.parser.soft.TestParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.TestSoftAST.SpaceOne
import org.alephium.ralph.lsp.access.util.TestCodeUtil._
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand Down Expand Up @@ -51,8 +52,8 @@ class FunctionBlockSpec extends AnyWordSpec with Matchers {

block.body shouldBe
SoftAST.BlockBody(
index = indexOf("fn -> { >><<}"),
prePartsSpace = None,
index = indexOf("fn -> {>> <<}"),
prePartsSpace = Some(SpaceOne(indexOf("fn -> {>> <<}"))),
parts = Seq.empty
)
}
Expand Down