Skip to content

Commit

Permalink
Merge pull request #332 from alephium/a_bit_renaming
Browse files Browse the repository at this point in the history
Renaming
  • Loading branch information
simerplaha authored Dec 2, 2024
2 parents e26952a + abf7289 commit 0b3c6af
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}

private object BlockParser {

def clause[Unknown: P](mandatory: Boolean): P[SoftAST.BlockClause] =
P(Index ~ TokenParser.openCurly(mandatory) ~ spaceOrFail.? ~ body(Some(Token.CloseCurly.lexeme.head)) ~ spaceOrFail.? ~ TokenParser.closeCurly ~ Index) map {
def clause[Unknown: P](required: Boolean): P[SoftAST.BlockClause] =
P(Index ~ TokenParser.openCurly(required) ~ spaceOrFail.? ~ body(Some(Token.CloseCurly.lexeme)) ~ spaceOrFail.? ~ TokenParser.closeCurly ~ Index) map {
case (from, openCurly, preBodySpace, body, postBodySpace, closeCurly, to) =>
SoftAST.BlockClause(
index = range(from, to),
Expand All @@ -38,10 +38,10 @@ private object BlockParser {
}

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

private def body[Unknown: P](stopChar: Option[Char]): P[SoftAST.BlockBody] =
P(Index ~ spaceOrFail.? ~ bodyPart(stopChar).rep ~ Index) map {
private def body[Unknown: P](stopChars: Option[String]): P[SoftAST.BlockBody] =
P(Index ~ spaceOrFail.? ~ bodyPart(stopChars).rep ~ Index) map {
case (from, headSpace, parts, to) =>
SoftAST.BlockBody(
index = range(from, to),
Expand All @@ -50,8 +50,8 @@ private object BlockParser {
)
}

private def bodyPart[Unknown: P](stopChar: Option[Char]): P[SoftAST.BlockBodyPart] =
P(Index ~ part(stopChar) ~ spaceOrFail.? ~ Index) map {
private def bodyPart[Unknown: P](stopChars: Option[String]): P[SoftAST.BlockBodyPart] =
P(Index ~ part(stopChars) ~ spaceOrFail.? ~ Index) map {
case (from, ast, space, to) =>
SoftAST.BlockBodyPart(
index = range(from, to),
Expand All @@ -60,12 +60,12 @@ private object BlockParser {
)
}

private def part[Unknown: P](stopChar: Option[Char]): P[SoftAST.BodyPartAST] =
private def part[Unknown: P](stopChars: Option[String]): P[SoftAST.BodyPartAST] =
P {
TemplateParser.parse |
FunctionParser.parse |
CommentParser.parse |
unresolved(stopChar)
TemplateParser.parseOrFail |
FunctionParser.parseOrFail |
CommentParser.parseOrFail |
unresolved(stopChars)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.SoftAST

private object CommentParser {

def parse[Unknown: P]: P[SoftAST.Comment] =
P(Index ~ TokenParser.doubleForwardSlash ~ spaceOrFail.? ~ text.? ~ Index) map {
def parseOrFail[Unknown: P]: P[SoftAST.Comment] =
P(Index ~ TokenParser.doubleForwardSlashOrFail ~ spaceOrFail.? ~ text.? ~ Index) map {
case (from, doubleForwardSlash, space, text, to) =>
SoftAST.Comment(
index = range(from, to),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private object CommonParser {
)
}

def unresolved[Unknown: P](stopChar: Option[Char]): P[SoftAST.Unresolved] =
P(Index ~ CharsWhileNot(Token.Space.lexeme ++ Token.Newline.lexeme ++ stopChar).! ~ Index) map {
def unresolved[Unknown: P](stopChars: Option[String]): P[SoftAST.Unresolved] =
P(Index ~ CharsWhileNot(Token.Space.lexeme ++ Token.Newline.lexeme ++ stopChars.getOrElse("")).! ~ Index) map {
case (from, text, to) =>
SoftAST.Unresolved(
code = text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.SoftAST

private object FunctionParser {

def parse[Unknown: P]: P[SoftAST.Function] =
P(TokenParser.fn ~ space ~ signature ~ spaceOrFail.? ~ BlockParser.clause(mandatory = false).?) map {
def parseOrFail[Unknown: P]: P[SoftAST.Function] =
P(TokenParser.FnOrFail ~ space ~ signature ~ spaceOrFail.? ~ BlockParser.clause(required = false).?) map {
case (fnDeceleration, headSpace, signature, tailSpace, block) =>
SoftAST.Function(
index = range(fnDeceleration.index.from, signature.index.to),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private object ParameterParser {
}

private def tailParam[Unknown: P]: P[SoftAST.TailParameter] =
P(Index ~ spaceOrFail.? ~ TokenParser.comma ~ spaceOrFail.? ~ oneParameter ~ Index) map {
P(Index ~ spaceOrFail.? ~ TokenParser.commaOrFail ~ spaceOrFail.? ~ oneParameter ~ Index) map {
case (from, headSpace, comma, tailSpace, param, to) =>
SoftAST.TailParameter(
index = range(from, to),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.SoftAST

private object TemplateParser {

def parse[Unknown: P] =
P(Index ~ templateType ~ space ~ identifier ~ spaceOrFail.? ~ ParameterParser.parse ~ spaceOrFail.? ~ BlockParser.clause(mandatory = true) ~ Index) map {
def parseOrFail[Unknown: P] =
P(Index ~ templateType ~ space ~ identifier ~ spaceOrFail.? ~ ParameterParser.parse ~ spaceOrFail.? ~ BlockParser.clause(required = true) ~ Index) map {
case (from, templateType, preIdentifierSpace, identifier, preParamSpace, params, postParamSpace, block, to) =>
SoftAST.Template(
index = range(from, to),
Expand All @@ -24,6 +24,6 @@ private object TemplateParser {
}

private def templateType[Unknown: P]: P[SoftAST.TemplateToken] =
P(TokenParser.Contract | TokenParser.TxScript)
P(TokenParser.ContractOrFail | TokenParser.TxScriptOrFail)

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ private object TokenParser {
SoftAST.CloseParen(range(from, to))
}

def openCurly[Unknown: P](mandatory: Boolean): P[SoftAST.OpenCurlyAST] =
if (mandatory)
def openCurly[Unknown: P](required: Boolean): P[SoftAST.OpenCurlyAST] =
if (required)
openCurly
else
openCurlyOrFail
Expand Down Expand Up @@ -92,7 +92,7 @@ private object TokenParser {
SoftAST.CloseCurlyExpected(range(from, to))
}

def comma[Unknown: P]: P[SoftAST.Comma] =
def commaOrFail[Unknown: P]: P[SoftAST.Comma] =
P(Index ~ Token.Comma.lexeme ~ Index) map {
case (from, to) =>
SoftAST.Comma(range(from, to))
Expand All @@ -107,25 +107,25 @@ private object TokenParser {
SoftAST.ForwardArrowExpected(range(from, to))
}

def doubleForwardSlash[Unknown: P]: P[SoftAST.DoubleForwardSlash] =
def doubleForwardSlashOrFail[Unknown: P]: P[SoftAST.DoubleForwardSlash] =
P(Index ~ Token.DoubleForwardSlash.lexeme ~ Index) map {
case (from, to) =>
SoftAST.DoubleForwardSlash(range(from, to))
}

def Contract[Unknown: P]: P[SoftAST.Contract] =
def ContractOrFail[Unknown: P]: P[SoftAST.Contract] =
P(Index ~ Token.Contract.lexeme ~ Index) map {
case (from, to) =>
SoftAST.Contract(range(from, to))
}

def TxScript[Unknown: P]: P[SoftAST.TxScript] =
def TxScriptOrFail[Unknown: P]: P[SoftAST.TxScript] =
P(Index ~ Token.TxScript.lexeme ~ Index) map {
case (from, to) =>
SoftAST.TxScript(range(from, to))
}

def fn[Unknown: P]: P[SoftAST.Fn] =
def FnOrFail[Unknown: P]: P[SoftAST.Fn] =
P(Index ~ Token.Fn.lexeme ~ Index) map {
case (from, to) =>
SoftAST.Fn(range(from, to))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private object TypeParser {
}

private def commaTypeName[Unknown: P]: P[SoftAST.TailType] =
P(Index ~ TokenParser.comma ~ spaceOrFail.? ~ parse ~ spaceOrFail.? ~ Index) map {
P(Index ~ TokenParser.commaOrFail ~ spaceOrFail.? ~ parse ~ spaceOrFail.? ~ Index) map {
case (from, comma, preTypeNameSpace, typeName, postTypeNameSpace, to) =>
SoftAST.TailType(
index = range(from, to),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ object TestParser {
runParser(SoftParser.parse(_))(code)

def parseTemplate(code: String): SoftAST.Template =
runParser(TemplateParser.parse(_))(code)
runParser(TemplateParser.parseOrFail(_))(code)

def parseFunction(code: String): SoftAST.Function =
runParser(FunctionParser.parse(_))(code)
runParser(FunctionParser.parseOrFail(_))(code)

def parseParameter(code: String): SoftAST.ParameterClauseAST =
runParser(ParameterParser.parse(_))(code)
Expand All @@ -42,7 +42,7 @@ object TestParser {
runParser(BlockParser.body(_))(code)

def parseComment(code: String): SoftAST.Comment =
runParser(CommentParser.parse(_))(code)
runParser(CommentParser.parseOrFail(_))(code)

def parseType(code: String): SoftAST.TypeAST =
runParser(TypeParser.parse(_))(code)
Expand Down

0 comments on commit 0b3c6af

Please sign in to comment.