Skip to content

Commit

Permalink
progress check and save
Browse files Browse the repository at this point in the history
  • Loading branch information
ibx34 committed Dec 4, 2024
1 parent 82c0626 commit f62451e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
49 changes: 49 additions & 0 deletions ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class TT(Enum):
OPEN_PAREN = "("
CLOSE_PAREN = ")"
OPEN_SQUARE = "["
PIPE = "|"
CLOSE_SQUARE = "]"
IDENT = "IDENT"
LITERAL = "LITERAL"
COMMENT = "COMMENT"
PRIME_FORM = "PRIME_FORM"


operators = {
Expand Down Expand Up @@ -147,6 +149,9 @@ def lex(self) -> Token:
return Token(TT.LITERAL, prim_ty=PrimitiveTypes.STR, val=string)
elif c not in TT and (is_valid_ident(c) or c == "."):
self.advance()
if (next := self.current()) and next == "'" and c == "d":
# self.advance()
return Token(TT.PRIME_FORM)

def identifier_check(c: str | None, rest: str) -> bool:
if (c is None) or (not is_valid_ident(c)) and c != ".":
Expand Down Expand Up @@ -436,10 +441,18 @@ def __init__(self, input: list[Token]) -> None:
self.current_number_of_advances = 0
self.already_parsing_sya = False

def resolve_type(self, ty: Expr) -> None:
pass

def advance(self) -> None:
self.current_number_of_advances += 1
return super().advance()

def peek(self, amt: int = 1) -> Token | None:
if self.at + amt > len(self.input):
return None
return self.input[self.at + amt]

def lookup(self, name: str, symbol_table_id: int | None = None) -> Symbol | None:
symbol_table_id = self.using_st if symbol_table_id is None else symbol_table_id
if symbol_table_id is None or symbol_table_id not in self.symbol_tables:
Expand All @@ -465,6 +478,42 @@ def parse(self) -> Expr | None:
result: Expr | None = None
if c is None:
result = None
elif c.ty == TT.PRIME_FORM:
self.advance()
if (next := self.current()) and next.ty != TT.IDENT:
raise Exception(
f"Expected double colon after the prime form...got {next}"
)
ident = self.parse()
self.advance()
parts: list[Expr] = []
print(f"{self.current()}")
while True:
c = self.current()
print(c)
if c is None:
break
elif c.ty == TT.PIPE:
self.advance()
continue
part = self.parse()
if (
not isinstance(part, Tuple)
and not isinstance(part, Reference)
and not isinstance(part, PrimitiveType)
and (
not isinstance(part, Identifier)
or (isinstance(part, Identifier) and part.for_assignment)
)
):
self.at -= 1
break
parts.append(part)
continue

print(f"Handling prime form!! {ident} = {parts}")
result = TypeDef(ident)

elif c.ty == TT.LITERAL:
if c.prim_ty is None or c.val is None:
raise Exception("Invalid primitive type...how?")
Expand Down
5 changes: 4 additions & 1 deletion boot.dal
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Enums are super simple!
d'Option :: Some | Empty

return_float\ x int :: float → 2.32

// Who is whatever and why are we doing them...?

do_whatever\ :: (float, int) → (return_float 23, 54)
do_whatever\ :: (float, int) → (3.32, 54)

0 comments on commit f62451e

Please sign in to comment.