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