Fixed StrLit + ChrLit matching beyond EOL, also greed excludes satisfier

This commit is contained in:
Emile Clark-Boman 2025-06-19 02:33:13 +10:00
parent f8f90fe92d
commit 8e6c0bbbfc
2 changed files with 8 additions and 8 deletions

View file

@ -15,16 +15,14 @@ proc parseMatchLine(parser: var nlParser, matchType: nlTokKind): nlParseStat =
) )
proc parseStrLit(parser: var nlParser): nlParseStat = proc parseStrLit(parser: var nlParser): nlParseStat =
result = parser.parseMatch(tkDQUO) result = parser.parseMatchLine(tkDQUO)
proc parseChrLit(parser: var nlParser): nlParseStat = proc parseChrLit(parser: var nlParser): nlParseStat =
result = parser.parseMatch(tkSQUO) result = parser.parseMatchLine(tkSQUO)
proc parseStmt(parser: var nlParser): nlParseStat = proc parseStmt(parser: var nlParser): nlParseStat =
# initialise build node as none just for the hell of it
while parser.stream.progress(): while parser.stream.progress():
echo "Current Token: ", parser.stream.currTok echo "----- Current Token: ", parser.stream.currTok
case parser.stream.currTok.tKind case parser.stream.currTok.tKind
of tkDQUO: of tkDQUO:
# Attempt to parse string literal # Attempt to parse string literal

View file

@ -50,18 +50,20 @@ proc newParser*(tokStream: var nlTokStream): nlParser =
proc greed(parser: var nlParser, proc greed(parser: var nlParser,
satisfy: proc(tok: nlTok): bool): nlParseStat = satisfy: proc(tok: nlTok): bool): nlParseStat =
while parser.stream.progress(): while parser.stream.progress():
parser.bnode.addTok(parser.stream.currTok)
if satisfy(parser.stream.currTok): if satisfy(parser.stream.currTok):
return nlParseStat.OK return nlParseStat.OK
# NOTE: the matched token is currently excluded
parser.bnode.addTok(parser.stream.currTok)
result = nlParseStat.UNMATCHED result = nlParseStat.UNMATCHED
proc greedLine(parser: var nlParser, proc greedLine(parser: var nlParser,
satisfy: proc(tok: nlTok): bool): nlParseStat = satisfy: proc(tok: nlTok): bool): nlParseStat =
while parser.stream.progress(): while parser.stream.progress():
parser.bnode.addTok(parser.stream.currTok)
if satisfy(parser.stream.currTok): if satisfy(parser.stream.currTok):
return nlParseStat.OK return nlParseStat.OK
elif parser.stream.currTok.tKind == tkEOL: # NOTE: the matched token is currently excluded
parser.bnode.addTok(parser.stream.currTok)
if parser.stream.currTok.tKind == tkEOL:
return nlParseStat.UNMATCHED return nlParseStat.UNMATCHED
result = nlParseStat.UNMATCHED result = nlParseStat.UNMATCHED