Unify function naming

This commit is contained in:
Florian Schroedl
2022-08-26 19:08:43 +02:00
parent eb980259cb
commit 4e7c855995

View File

@@ -6,12 +6,10 @@ import std/[
sugar,
]
import fp/[
maybe,
resultM,
]
import fusion/matching
import ../utils/str
import ../utils/fp
{.experimental: "caseStmtMacros".}
@@ -82,7 +80,7 @@ func initParserResult*(
# -- Getters
func tokenStringValue*(x: ParserToken): string =
func toString*(x: ParserToken): string =
## Get the Token value `x` as a string.
case x.kind:
of parserTokenChar:
@@ -90,8 +88,8 @@ func tokenStringValue*(x: ParserToken): string =
of parserTokenString:
x.stringValue
func tokensToString*(tokens: seq[ParserToken]): string =
tokens.foldl(a & b.tokenStringValue(), "")
func toString*(tokens: seq[ParserToken]): string =
tokens.foldl(a & b.toString(), "")
# -- Modifiers
@@ -102,7 +100,7 @@ func flattenParserTokens*(parser: Parser): ParserResult =
tokens: @[
ParserToken(
kind: parserTokenString,
stringValue: parser.tokens.foldl(a & b.tokenStringValue(), "")
stringValue: parser.tokens.foldl(a & b.toString(), "")
)
]
)
@@ -128,7 +126,7 @@ func foldTokens*[T](
func tokensToString*(parserResult: ParserResult, fallback = ""): string =
parserResult.foldTokens(
err => fallback,
xs => xs.tokensToString(),
xs => xs.toString(),
)
func setErrorExpectedField*(err: ParserError, expected: string): ParserError =
@@ -143,7 +141,7 @@ func setErrorExpectedField*(err: ParserError, expected: string): ParserError =
# -- Stringifiers
func pprint*(x: ParserToken): string =
let str = tokenStringValue(x)
let str = toString(x)
let escapedChar = if str == "\n": "\\n"
else: str
&"""ParserToken("{escapedChar}")
@@ -277,15 +275,15 @@ when isMainModule:
D
EFG"""
echo test1.highlightStreamPosition2(test1.find("B"))
echo "=============="
echo test1.highlightStreamPosition2(test1.find("C"))
echo "=============="
echo test1.highlightStreamPosition2(test1.find("D"))
echo "=============="
echo test1.highlightStreamPosition2(test1.find("\n"))
echo "=============="
echo test1.highlightStreamPosition2(test1.find("\n", test1.find("\n") + 1))
# echo test1.highlightStreamPosition2(test1.find("B"))
# echo "=============="
# echo test1.highlightStreamPosition2(test1.find("C"))
# echo "=============="
# echo test1.highlightStreamPosition2(test1.find("D"))
# echo "=============="
# echo test1.highlightStreamPosition2(test1.find("\n"))
# echo "=============="
# echo test1.highlightStreamPosition2(test1.find("\n", test1.find("\n") + 1))
# echo "\n1\n".rfind('\n', 0, 2)