Skip to content

Commit

Permalink
TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
Cypher1 committed May 5, 2024
1 parent 5ee5781 commit 33d56dd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/enums.tk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env tako
// test: todo
// test: todo type error

boolean = Enum.new(
true=1,
Expand All @@ -10,7 +10,7 @@ boolean.import_literals()

color = Enum
.based_on(
byte[3]
[byte; 3]
)
.open(
red=#ff0000,
Expand Down
6 changes: 3 additions & 3 deletions examples/generic_abstract_data_types.tk
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

// A simple, untyped implementation of S expressions.
SExpr: Type = struct.new(
func: (args: Value[n]),
args: SExpr[n],
func: (args: [Value; n]),
args: [SExpr; n],
{n: Int},
)

// A well typed, but little, language using GADTs.
Expr(
SubExpr(R: AllowedType): Reference(Expr(SubExpr, R))=Expr,
R: AllowedType,
with {AllowedType = Integer|Boolean}
{AllowedType = Integer|Boolean}
) = gadt.new(

// Control flow:
Expand Down
12 changes: 12 additions & 0 deletions takolib/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ impl<'src, 'toks, T: Iterator<Item = &'toks Token>> ParseState<'src, 'toks, T> {
self.number_literal(token, location)
} else if let Ok(token) = self.token_of_type(TokenType::StringLit) {
self.string_literal(token, location)
} else if let Ok(token) = self.token_of_type(TokenType::ColorLit) {
self.color_literal(token, location)
} else {
return Err(ParseError::UnexpectedTokenTypeInExpression {
got: token.kind,
Expand Down Expand Up @@ -642,6 +644,16 @@ impl<'src, 'toks, T: Iterator<Item = &'toks Token>> ParseState<'src, 'toks, T> {
self.ast.add_literal(Literal::Text, location)
}

fn color_literal(&mut self, res: Token, location: Location) -> NodeId {
assert!(res.kind == TokenType::ColorLit);
trace!("Saving literal: {res:?}");
let _id = self
.ast
.string_interner
.register_str_by_loc(res.get_src(self.contents), location.start);
self.ast.add_literal(Literal::Color, location)
}

fn number_literal(&mut self, res: Token, location: Location) -> NodeId {
assert!(res.kind == TokenType::NumberLit);
trace!("Saving literal: {res:?}");
Expand Down
4 changes: 2 additions & 2 deletions takolib/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Integration tests
use log::{debug, info};
use log::{trace, info};
use std::fs;
use std::path::PathBuf;
use walkdir::{DirEntry, WalkDir};
Expand Down Expand Up @@ -105,7 +105,7 @@ fn parse_example_files() {
let tokens = crate::parser::tokens::lex(&contents)
.expect(&format!("Should be able to lex: {file:?}"));

debug!("Tokens: {tokens:#?}");
trace!("Tokens: {tokens:#?}");

// TODO: Use tasks to get 'decorate_error:
let _ast = crate::parser::parse(&file, &contents, &tokens)
Expand Down

0 comments on commit 33d56dd

Please sign in to comment.