Skip to content

Commit

Permalink
Make reserved keywords file into a raw txt file
Browse files Browse the repository at this point in the history
- Reserve import related keywords
- Updates for deps
  • Loading branch information
Cypher1 committed Apr 20, 2024
1 parent 6c1ae20 commit 33439a2
Show file tree
Hide file tree
Showing 13 changed files with 1,097 additions and 347 deletions.
1,272 changes: 1,003 additions & 269 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tako/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ takolib = { path = "../takolib", features = [ "native" ] }
tokio = { version = "1.24", features = [ "full" ] }
log = "0.4"
warp = "0.3"
crokey = "0.5"
crossterm = { version = "0.24", features = [ "event-stream" ] }
directories = "4.0"
notify = "5.0"
crokey = "0.6.4"
crossterm = { version = "0.27.0", features = [ "event-stream" ] }
directories = "5.0.1"
notify = "6.1.1"
shutdown_hooks = "0.1"
futures = "0.3"
html-escape = "0.2.13"
47 changes: 25 additions & 22 deletions tako/src/ui/tui.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::cli_options::Options;
use async_trait::async_trait;
use crokey::{key, KeyEventFormat};
use crokey::{key, Combiner, KeyCombination, KeyCombinationFormat};
use crossterm::{
cursor::MoveTo,
event::{Event, EventStream, KeyCode, KeyEvent},
style::{/*Color,*/ Print, ResetColor /*, SetBackgroundColor, SetForegroundColor*/},
event::{Event, EventStream},
style::{Print, ResetColor},
terminal::{disable_raw_mode, enable_raw_mode, size, Clear, ClearType},
QueueableCommand,
};
Expand All @@ -30,7 +30,8 @@ extern "C" fn shutdown() {

#[derive(Debug)]
pub struct Tui {
key_fmt: KeyEventFormat,
key_fmt: KeyCombinationFormat,
key_combiner: Combiner,
should_exit: bool,
input: String,
input_after_cursor: String,
Expand All @@ -42,7 +43,8 @@ impl Tui {
fn new(client: Client) -> Self {
Self {
client,
key_fmt: KeyEventFormat::default(),
key_combiner: Combiner::default(),
key_fmt: KeyCombinationFormat::default(),
should_exit: false,
input: String::new(),
input_after_cursor: String::new(),
Expand Down Expand Up @@ -111,15 +113,18 @@ impl Tui {
let mut characters = String::new();
match event {
Event::Key(key_event) => {
match key_event {
::crokey::__private::crossterm::event::KeyEvent {
modifiers: ::crokey::__private::MODS_CTRL,
code: ::crokey::__private::crossterm::event::KeyCode::Char('c' | 'q'),
} => self.should_exit = true,
key!(Backspace) => {
let combo: KeyCombination =
if let Some(combo) = self.key_combiner.transform(key_event) {
combo
} else {
return Ok(());
};
match combo {
key!(ctrl - c) | key!(ctrl - q) => self.should_exit = true,
key!(backspace) => {
self.input.pop(); // Discard
}
key!(Delete) => {
key!(delete) => {
let mut chars = self.input_after_cursor.chars();
chars.next();
self.input_after_cursor = chars.collect();
Expand Down Expand Up @@ -154,10 +159,10 @@ impl Tui {
self.input_after_cursor = format!("{last}{}", self.input_after_cursor);
}
}
key!(Shift - Enter) => {
key!(shift - enter) => {
self.input.push('\n');
}
key!(Enter) => {
key!(enter) => {
// Submit the expression
let mut line = String::new();
std::mem::swap(&mut self.input, &mut line);
Expand All @@ -169,14 +174,12 @@ impl Tui {
}
self.input_after_cursor = String::new();
}
KeyEvent {
code: KeyCode::Char(letter),
modifiers: _,
} => {
self.input.push(letter);
}
_ => {
// discard
other => {
if let Some(letter) = other.as_letter() {
self.input.push(letter);
} else {
// discard
}
}
};
characters = format!("{characters}{}", self.key_fmt.to_string(key_event));
Expand Down
2 changes: 1 addition & 1 deletion takobench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ bench = ["criterion"]
default = []

[dependencies]
criterion = { version = "0.3", optional = true }
criterion = { version = "0.5.1", optional = true }
takolib = { path = "../takolib" }
14 changes: 7 additions & 7 deletions takolib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ static_assertions = "1.1"
num-traits = "0.2"
enum-kinds = "0.5"
lazy_static = "1.4.0"
env_logger = { version = "0.9", optional = true }
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm15-0"], optional = true }
env_logger = { version = "0.11.3", optional = true }
inkwell = { git = "https://github.com/TheDan64/inkwell", branch = "master", features = ["llvm17-0"], optional = true }
wasm-logger = { version = "0.2.0", optional = true }
melior = { version = "0.3.1", optional = true }
smallvec = { version = "1.10.0", features = [ "const_new", "const_generics", "union" ] }
melior = { version = "0.17.0", optional = true }
smallvec = { version = "2.0.0-alpha.5" }
llamada = { path = "../llamada", features = [ ] }
better-std = { path = "../better-std", features = [ ] }

[dev-dependencies]
strum = "0.24"
strum_macros = "0.24"
strum = "0.26.2"
strum_macros = "0.26.2"
pretty_assertions = "1.0"
rand = "0.8"
rand = "0.9.0-alpha.1"
10 changes: 5 additions & 5 deletions takolib/src/ast/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ make_contains!(atoms, (NodeId, Atom), Atom, AtomId, add_atom);
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct Call {
pub inner: NodeId,
pub args: SmallVec<[NodeId; 2]>,
pub args: SmallVec<NodeId, 2>,
}
make_contains!(calls, (NodeId, Call), Call, CallId, add_call);

Expand All @@ -85,21 +85,21 @@ impl Call {
}
}
#[must_use]
pub fn new(inner: NodeId, args: SmallVec<[NodeId; 2]>) -> Self {
pub fn new(inner: NodeId, args: SmallVec<NodeId, 2>) -> Self {
Self { inner, args }
}
}

#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct Op {
pub op: Symbol,
pub args: SmallVec<[NodeId; 2]>, // TODO: Track L/R?
pub args: SmallVec<NodeId, 2>, // TODO: Track L/R?
}
make_contains!(ops, (NodeId, Op), Op, OpId, add_op);

impl Op {
#[must_use]
pub fn new(op: Symbol, args: SmallVec<[NodeId; 2]>) -> Self {
pub fn new(op: Symbol, args: SmallVec<NodeId, 2>) -> Self {
Self { op, args }
}
}
Expand All @@ -108,7 +108,7 @@ impl Op {
pub struct Definition {
pub mode: BindingMode,
pub name: Identifier,
pub bindings: Option<SmallVec<[NodeId; 2]>>,
pub bindings: Option<SmallVec<NodeId, 2>>,
pub implementation: Option<NodeId>,
}
make_contains!(
Expand Down
4 changes: 2 additions & 2 deletions takolib/src/ast/string_interner.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::location::IndexIntoFile;
use crate::parser::keywords::KEYWORDS;
use crate::parser::KEYWORDS;
use crate::primitives::typed_index::TypedIndex;
use num_traits::Bounded;
use std::collections::BTreeMap;
Expand Down Expand Up @@ -42,7 +42,7 @@ impl Default for StringInterner {
n.pi = n.register_str("pi");
n.forall = n.register_str("forall");
n.exists = n.register_str("exists");
for key in KEYWORDS {
for key in KEYWORDS.iter() {
n.register_str(key);
}
n
Expand Down
4 changes: 3 additions & 1 deletion takolib/src/codegen/backend/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ pub mod tests {
// let zero = llvm.const_int(i32_type, 0);
let argv_0 = llvm.access_into_array(char_star_type.into(), argv.into_pointer_value());
llvm.printf("ARGC: %d, ARGV: %s\n", &[argc, argv_0]);
llvm.builder.build_return(Some(&argc.into_int_value()));
llvm.builder
.build_return(Some(&argc.into_int_value()))
.expect("building return should not fail");

// dbg!(&llvm);
let elf_path = test_build_output_dir().join("hello_world.elf");
Expand Down
10 changes: 6 additions & 4 deletions takolib/src/lowerer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub fn lower(_path: &Path, og_ast: &Ast, root: NodeId) -> Result<Llamada, TError
let location = ast.get(*nodeid).location;
let str = ast.string_interner.get_str_by_loc(location.start);
trace!("GOT NUMERIC AT {:?} => {:?}", &location, str);
let str = str.expect("Got nothing for the string");
let val = str
.expect("Got nothing for the string")
.parse::<u32>()
.expect("Could not parse string as number");
val.into()
Expand All @@ -56,10 +56,12 @@ pub fn lower(_path: &Path, og_ast: &Ast, root: NodeId) -> Result<Llamada, TError
todo!("WHAT?")
};
eprintln!("ABS OVER {}", ast.pretty_node(inner));
let curr = get_expr(&mut expr, inner, Some(Term::Var(1))); // TODO: Reassociate...
let curr = get_expr(&mut expr, *nodeid, Some(Term::Abs(None, curr))); // TODO: Add the type info?
// TODO: Reassociate...
let var = get_expr(&mut expr, inner, Some(Term::Var(1)));
// TODO: Add the type info?
let abs = get_expr(&mut expr, *nodeid, Some(Term::Abs(None, var)));
let node: &mut Node = ast.get_mut(*nodeid);
node.lowered_to = Some(curr);
node.lowered_to = Some(abs);
continue;
}
// TODO!?
Expand Down
27 changes: 0 additions & 27 deletions takolib/src/parser/keywords.rs

This file was deleted.

29 changes: 29 additions & 0 deletions takolib/src/parser/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
False
TRUE
True
any
construct
exists
false
forall
from
given
implies
import
imports
in
include
includes
lambda
module
pi
preserve
read
require
sigma
such
suchthat
that
true
where
write
11 changes: 9 additions & 2 deletions takolib/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub mod keywords;
pub mod semantics;
pub mod tokens;
// use rand::Rng;
use crate::ast::location::Location;
use crate::ast::string_interner::Identifier;
use crate::ast::{Ast, Atom, Call, Contains, Definition, NodeData, NodeId, Op};
Expand All @@ -14,6 +12,15 @@ use std::path::Path;
use thiserror::Error;
use tokens::{assign_op, binding_mode_operation, is_assign, OpBinding, Symbol, Token, TokenType};

use lazy_static::lazy_static;

lazy_static! {
pub static ref KEYWORDS: Vec<String> = include_str!("keywords.txt")
.split("\n")
.map(|s| s.to_string())
.collect();
}

#[derive(Debug, Error, PartialEq, Eq, Ord, PartialOrd, Clone, Hash)]
pub enum ParseError {
UnexpectedEof, // TODO: Add context.
Expand Down
6 changes: 3 additions & 3 deletions takoweb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "takowebui"
name = "takoweb"
version = "0.1.0"
repository = "https://github.com/cypher1/tako"
description = "A web based UI for tako"
Expand All @@ -11,9 +11,9 @@ keywords = ["yew", "trunk"]
categories = ["gui", "wasm", "web-programming"]

[dependencies]
yew = { version="0.20", features=["csr"] }
yew = { version="0.21.0", features=["csr"] }
takolib = { path = "../takolib", features = [ "wasm" ], default-features = false }
tokio = { version = "1.24", features = ["sync", "macros"] }
yew-hooks = "0.2.0"
yew-hooks = "0.3.1"
async-trait = "0.1"
web-sys = "0.3.61"

0 comments on commit 33439a2

Please sign in to comment.