58 lines
1.8 KiB
Nim
58 lines
1.8 KiB
Nim
import strutils
|
|
include parser
|
|
|
|
# NOTE: Matching between two tokens will fill `node` with everything
|
|
# NOTE: between those two tokens EXCLUDING the two tokens themselves.
|
|
proc parseMatch(parser: var nlParser, matchType: nlTokKind): nlParseStat =
|
|
result = greed(
|
|
parser,
|
|
satisfyMatch(matchType),
|
|
)
|
|
proc parseMatchLine(parser: var nlParser, matchType: nlTokKind): nlParseStat =
|
|
result = greedLine(
|
|
parser,
|
|
satisfyMatch(matchType),
|
|
)
|
|
|
|
proc parseStrLit(parser: var nlParser): nlParseStat =
|
|
result = parser.parseMatchLine(tkDQUO)
|
|
|
|
proc parseChrLit(parser: var nlParser): nlParseStat =
|
|
result = parser.parseMatchLine(tkSQUO)
|
|
|
|
proc parseStmt(parser: var nlParser): nlParseStat =
|
|
while parser.progressStream():
|
|
echo "----- Current Token: ", parser.currTok
|
|
case parser.currTok.tKind
|
|
of tkDQUO:
|
|
# Attempt to parse string literal
|
|
if parser.parseStrLit() != nlParseStat.OK:
|
|
echo "Unmatched Double Quotation! Malformed String Literal"
|
|
echo parser.line
|
|
echo repeat(" ", parser.currTok.startPos), '^', '\n'
|
|
else:
|
|
echo "Parsed String Literal"
|
|
echo parser.bnode[], '\n'
|
|
of tkSQUO:
|
|
# Attempt to parse string literal
|
|
if parser.parseChrLit() != nlParseStat.OK:
|
|
echo "Unmatched Single Quotation! Malformed Character Literal"
|
|
echo parser.line
|
|
echo repeat(" ", parser.currTok.startPos), '^', '\n'
|
|
else:
|
|
echo "Parsed Character Literal"
|
|
echo parser.bnode[], '\n'
|
|
of tkEOL:
|
|
# TODO: handle this case, don't just discard
|
|
discard
|
|
else:
|
|
echo "blah blah unhandled case\n"
|
|
result = nlParseStat.OK
|
|
|
|
# Attempt to parse nlAST from nlTokStream
|
|
proc parse*(tokStream: var nlTokStream): nlAST =
|
|
var parser = newParser(tokStream)
|
|
echo ' '
|
|
discard parser.parseStmt()
|
|
|
|
result = parser.ast
|