From 4e7c855995fa7e44963dd38f75ff7f34d4884cf0 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Fri, 26 Aug 2022 19:08:43 +0200 Subject: [PATCH] Unify function naming --- src_v2/parser/parser_types.nim | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src_v2/parser/parser_types.nim b/src_v2/parser/parser_types.nim index dd6974a..6ff49bd 100644 --- a/src_v2/parser/parser_types.nim +++ b/src_v2/parser/parser_types.nim @@ -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)