From 12c200b13fac1066398508117d294152adb04835 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Tue, 17 Jun 2025 14:00:58 +1000 Subject: [PATCH] Commit (unimplemented) parser & AST --- src/TODO_READ_THIS_SHITRN_OMG | 1 + src/noether/lexer/lstream.nim | 2 +- src/noether/lexer/{tokens.nim => tok.nim} | 3 +++ src/noether/lexer/tokstream.nim | 2 -- src/noether/parser/arborist.nim | 7 +++++++ src/noether/parser/nodes.nim | 18 ++++++++++++++++++ 6 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/TODO_READ_THIS_SHITRN_OMG rename src/noether/lexer/{tokens.nim => tok.nim} (97%) create mode 100644 src/noether/parser/arborist.nim create mode 100644 src/noether/parser/nodes.nim diff --git a/src/TODO_READ_THIS_SHITRN_OMG b/src/TODO_READ_THIS_SHITRN_OMG new file mode 100644 index 0000000..9970c30 --- /dev/null +++ b/src/TODO_READ_THIS_SHITRN_OMG @@ -0,0 +1 @@ +rename nlTok.tokType to nlTok.tType diff --git a/src/noether/lexer/lstream.nim b/src/noether/lexer/lstream.nim index 5bc79f2..862eb7b 100644 --- a/src/noether/lexer/lstream.nim +++ b/src/noether/lexer/lstream.nim @@ -1,7 +1,7 @@ import std/streams import std/options -include tokens +include tok type # Character streaming for the nlTokStream diff --git a/src/noether/lexer/tokens.nim b/src/noether/lexer/tok.nim similarity index 97% rename from src/noether/lexer/tokens.nim rename to src/noether/lexer/tok.nim index 6e18151..dc5d00a 100644 --- a/src/noether/lexer/tokens.nim +++ b/src/noether/lexer/tok.nim @@ -23,6 +23,7 @@ type SQUO, # ' Single Quotation Marking DQUO, # " Double Quotation Marking GRVA, # ` Grave Accent + HASH, # # Number Sign (Hashtag) nlTok = object tokType*: nlTokType @@ -92,5 +93,7 @@ proc getTokType(c: char): nlTokType = result = nlTokType.DQUO of '`': result = nlTokType.GRVA + of '#': + result = nlTokType.HASH else: result = nlTokType.WORD diff --git a/src/noether/lexer/tokstream.nim b/src/noether/lexer/tokstream.nim index 443d3fb..4b7832b 100644 --- a/src/noether/lexer/tokstream.nim +++ b/src/noether/lexer/tokstream.nim @@ -1,7 +1,5 @@ include lstream -import os # TEMP import - type # Provides a stream-like interface for lexing nlToks # Internally reliant on the functionality of nlLStream diff --git a/src/noether/parser/arborist.nim b/src/noether/parser/arborist.nim new file mode 100644 index 0000000..42888c8 --- /dev/null +++ b/src/noether/parser/arborist.nim @@ -0,0 +1,7 @@ +# Attempt to form an nlAST from a nlTokStream +proc arborise(tokStream: nlTokStream): nlNode = + for tok in toks(tokStream): + case tok.tokType: + of nlTokType.DQUO: + # Attempt to parse string literal + parse_strl() diff --git a/src/noether/parser/nodes.nim b/src/noether/parser/nodes.nim new file mode 100644 index 0000000..fdb78e1 --- /dev/null +++ b/src/noether/parser/nodes.nim @@ -0,0 +1,18 @@ +from ../lexer/tok import nlTok +from ../lexer/tokstraem import + +type + # NOTE: by the end of parsing NO nodes should + # NOTE: have nlNodeType.NONE + nlNodeType = enum + NONE, # Placeholder Value + TERM, # Indicates the tree has terminated + STRL, # String Literal + CHRL, # Character Literal + nlNode {.acyclic.} = ref object of RootObj + nType: nlNodeType + toks: seq[nlTok] # nodes store the tokens that build them + left, right: nlNode + +proc parse() +