Skip to content

Commit

Permalink
Merge pull request #386 from alephium/remove_root_space
Browse files Browse the repository at this point in the history
Remove redundant root space parsing
  • Loading branch information
simerplaha authored Feb 19, 2025
2 parents ea22a24 + c8edb7f commit 50b088e
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 15 deletions.
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

0 comments on commit 50b088e

Please sign in to comment.