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

Refactoring & resolves a TODO #349

Merged
merged 11 commits into from
Jan 14, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object AccessModifierParser {
Expand All @@ -28,13 +27,13 @@ private object AccessModifierParser {
P {
Index ~
TokenParser.parseOrFail(Token.Pub) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
Index
} map {
case (from, doubleForwardSlash, space, to) =>
case (from, pub, space, to) =>
SoftAST.AccessModifier(
index = range(from, to),
doubleForwardSlash,
pub = pub,
postTokenSpace = space
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object AnnotationParser {
Expand All @@ -40,11 +39,11 @@ private object AnnotationParser {
P {
Index ~
TokenParser.parseOrFail(Token.At) ~
spaceOrFail.? ~
identifier ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
IdentifierParser.parse ~
SpaceParser.parseOrFail.? ~
TupleParser.parseOrFail.? ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
Index
} map {
case (from, at, preIdentifierSpace, identifier, postIdentifierSpace, tuple, postTupleSpace, to) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object AssignmentAccessModifierParser {
Expand All @@ -28,7 +27,7 @@ private object AssignmentAccessModifierParser {
P {
Index ~
(TokenParser.parseOrFail(Token.Let) | TokenParser.parseOrFail(Token.Mut)) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
Index
} map {
case (from, dataAssignment, space, to) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object AssignmentParser {
Expand All @@ -12,10 +11,10 @@ private object AssignmentParser {
P {
Index ~
AssignmentAccessModifierParser.parseOrFail.rep ~
identifierOrFail ~
spaceOrFail.? ~
IdentifierParser.parseOrFail ~
SpaceParser.parseOrFail.? ~
TokenParser.parseOrFail(Token.Equal) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
ExpressionParser.parse ~
Index
} map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object BlockParser {
Expand All @@ -28,9 +27,9 @@ private object BlockParser {
P {
Index ~
TokenParser.parse(required, Token.OpenCurly) ~
spaceOrFail.? ~
body(Some(Token.CloseCurly.lexeme)) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
body(Token.CloseCurly) ~
SpaceParser.parseOrFail.? ~
TokenParser.parse(Token.CloseCurly) ~
Index
} map {
Expand All @@ -46,13 +45,13 @@ private object BlockParser {
}

def body[Unknown: P]: P[SoftAST.BlockBody] =
body(stopChars = None)
body()

private def body[Unknown: P](stopChars: Option[String]): P[SoftAST.BlockBody] =
private def body[Unknown: P](stop: Token*): P[SoftAST.BlockBody] =
P {
Index ~
spaceOrFail.? ~
bodyPart(stopChars).rep ~
SpaceParser.parseOrFail.? ~
bodyPart(stop).rep ~
Index
} map {
case (from, headSpace, parts, to) =>
Expand All @@ -63,11 +62,11 @@ private object BlockParser {
)
}

private def bodyPart[Unknown: P](stopChars: Option[String]): P[SoftAST.BlockBodyPart] =
private def bodyPart[Unknown: P](stop: Seq[Token]): P[SoftAST.BlockBodyPart] =
P {
Index ~
part(stopChars) ~
spaceOrFail.? ~
part(stop) ~
SpaceParser.parseOrFail.? ~
Index
} map {
case (from, ast, space, to) =>
Expand All @@ -78,14 +77,14 @@ private object BlockParser {
)
}

private def part[Unknown: P](stopChars: Option[String]): P[SoftAST.BodyPartAST] =
private def part[Unknown: P](stop: Seq[Token]): P[SoftAST.BodyPartAST] =
P {
TemplateParser.parseOrFail |
DataTemplateParser.parseOrFail |
FunctionParser.parseOrFail |
ExpressionParser.parseOrFail |
CommentParser.parseOrFail |
unresolved(stopChars)
UnresolvedParser.parseOrFail(stop: _*)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object CommentParser {
Expand All @@ -39,9 +38,9 @@ private object CommentParser {
def parseOrFail[Unknown: P]: P[SoftAST.Comments] =
P {
Index ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
one.rep(1) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
Index
} map {
case (from, preSpace, comments, postSpace, to) =>
Expand All @@ -64,9 +63,9 @@ private object CommentParser {
P {
Index ~
TokenParser.parseOrFailUndocumented(Token.DoubleForwardSlash) ~
spaceOrFail.? ~
text.? ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
TextParser.parseOrFail(Token.Newline).? ~
SpaceParser.parseOrFail.? ~
Index
} map {
case (from, doubleForwardSlash, preTextSpace, text, postTextSpace, to) =>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object DataTemplateParser {
Expand All @@ -12,9 +11,9 @@ private object DataTemplateParser {
P {
Index ~
(TokenParser.parseOrFail(Token.Struct) | TokenParser.parseOrFail(Token.Enum) | TokenParser.parseOrFail(Token.Event)) ~
space ~
identifier ~
spaceOrFail.? ~
SpaceParser.parse ~
IdentifierParser.parse ~
SpaceParser.parseOrFail.? ~
ParameterParser.parse ~
Index
} map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.SoftAST

private object ExpressionParser {
Expand Down Expand Up @@ -84,7 +83,7 @@ private object ExpressionParser {
ReferenceCallParser.parseOrFail |
AnnotationParser.parseOrFail |
TupleParser.parseOrFail |
identifierOrFail
IdentifierParser.parseOrFail
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft
import fastparse._
import fastparse.NoWhitespace.noWhitespaceImplicit
import org.alephium.ralph.lsp.access.compiler.message.SourceIndexExtra.range
import org.alephium.ralph.lsp.access.compiler.parser.soft.CommonParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object ForLoopParser {
Expand All @@ -12,21 +11,21 @@ private object ForLoopParser {
P {
Index ~
TokenParser.parseOrFail(Token.For) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
TokenParser.parse(Token.OpenParen) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
ExpressionParser.parse ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
TokenParser.parse(Token.Semicolon) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
ExpressionParser.parse ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
TokenParser.parse(Token.Semicolon) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
ExpressionParser.parse ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
TokenParser.parse(Token.CloseParen) ~
spaceOrFail.? ~
SpaceParser.parseOrFail.? ~
BlockParser.clause(required = true) ~
Index
} map {
Expand Down
Loading
Loading