Skip to content

Commit

Permalink
Merge pull request #349 from alephium/refactoring
Browse files Browse the repository at this point in the history
Refactoring & resolves a TODO
  • Loading branch information
simerplaha authored Jan 14, 2025
2 parents 62511f6 + 2635af6 commit ac02d8d
Show file tree
Hide file tree
Showing 31 changed files with 351 additions and 242 deletions.
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

0 comments on commit ac02d8d

Please sign in to comment.