2021-07-17 06:31:34 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use engine_q::{ParserState, ParserWorkingSet, Signature, SyntaxShape};
|
2021-06-30 01:42:56 +00:00
|
|
|
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
|
|
if let Some(path) = std::env::args().nth(1) {
|
2021-07-17 06:31:34 +00:00
|
|
|
let mut parser_state = Arc::new(ParserState::new());
|
|
|
|
let mut working_set = ParserWorkingSet::new(Some(parser_state.clone()));
|
2021-06-30 01:42:56 +00:00
|
|
|
|
2021-07-17 19:40:39 +00:00
|
|
|
let sig = Signature::build("foo").named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'));
|
|
|
|
working_set.add_decl(sig.into());
|
2021-07-01 22:40:08 +00:00
|
|
|
|
2021-07-16 06:24:46 +00:00
|
|
|
// let sig = Signature::build("bar")
|
|
|
|
// .named("--jazz", SyntaxShape::Int, "jazz!!", Some('j'))
|
|
|
|
// .switch("--rock", "rock!!", Some('r'));
|
|
|
|
// working_set.add_decl(sig.into());
|
2021-07-08 20:29:00 +00:00
|
|
|
|
2021-07-07 22:55:46 +00:00
|
|
|
let sig =
|
|
|
|
Signature::build("where").required("cond", SyntaxShape::RowCondition, "condition");
|
2021-07-16 06:24:46 +00:00
|
|
|
working_set.add_decl(sig.into());
|
2021-07-07 22:55:46 +00:00
|
|
|
|
|
|
|
let sig = Signature::build("if")
|
|
|
|
.required("cond", SyntaxShape::RowCondition, "condition")
|
|
|
|
.required("then_block", SyntaxShape::Block, "then block")
|
|
|
|
.required(
|
|
|
|
"else",
|
|
|
|
SyntaxShape::Literal(b"else".to_vec()),
|
|
|
|
"else keyword",
|
|
|
|
)
|
|
|
|
.required("else_block", SyntaxShape::Block, "else block");
|
2021-07-16 06:24:46 +00:00
|
|
|
working_set.add_decl(sig.into());
|
2021-07-07 22:55:46 +00:00
|
|
|
|
2021-07-08 06:19:38 +00:00
|
|
|
let sig = Signature::build("let")
|
|
|
|
.required("var_name", SyntaxShape::Variable, "variable name")
|
|
|
|
.required("=", SyntaxShape::Literal(b"=".to_vec()), "equals sign")
|
|
|
|
.required(
|
|
|
|
"value",
|
|
|
|
SyntaxShape::Expression,
|
|
|
|
"the value to set the variable to",
|
|
|
|
);
|
2021-07-16 06:24:46 +00:00
|
|
|
working_set.add_decl(sig.into());
|
2021-07-08 06:19:38 +00:00
|
|
|
|
2021-07-08 07:20:01 +00:00
|
|
|
let sig = Signature::build("alias")
|
|
|
|
.required("var_name", SyntaxShape::Variable, "variable name")
|
|
|
|
.required("=", SyntaxShape::Literal(b"=".to_vec()), "equals sign")
|
|
|
|
.required(
|
|
|
|
"value",
|
|
|
|
SyntaxShape::Expression,
|
|
|
|
"the value to set the variable to",
|
|
|
|
);
|
2021-07-16 06:24:46 +00:00
|
|
|
working_set.add_decl(sig.into());
|
2021-07-08 07:20:01 +00:00
|
|
|
|
2021-07-08 07:49:17 +00:00
|
|
|
let sig = Signature::build("sum").required(
|
|
|
|
"arg",
|
|
|
|
SyntaxShape::List(Box::new(SyntaxShape::Number)),
|
|
|
|
"list of numbers",
|
|
|
|
);
|
2021-07-16 06:24:46 +00:00
|
|
|
working_set.add_decl(sig.into());
|
|
|
|
|
|
|
|
let sig = Signature::build("def")
|
|
|
|
.required("def_name", SyntaxShape::String, "definition name")
|
2021-07-16 21:55:12 +00:00
|
|
|
.required("params", SyntaxShape::Signature, "parameters")
|
2021-07-16 06:24:46 +00:00
|
|
|
.required("block", SyntaxShape::Block, "body of the definition");
|
|
|
|
working_set.add_decl(sig.into());
|
2021-07-08 07:49:17 +00:00
|
|
|
|
2021-07-17 19:34:43 +00:00
|
|
|
let sig = Signature::build("add");
|
|
|
|
working_set.add_decl(sig.into());
|
|
|
|
let sig = Signature::build("add it");
|
|
|
|
working_set.add_decl(sig.into());
|
|
|
|
|
|
|
|
let sig = Signature::build("add it together")
|
|
|
|
.required("x", SyntaxShape::Int, "x value")
|
|
|
|
.required("y", SyntaxShape::Int, "y value");
|
|
|
|
working_set.add_decl(sig.into());
|
|
|
|
|
2021-07-17 06:31:34 +00:00
|
|
|
ParserState::merge_working_set(&mut parser_state, working_set);
|
|
|
|
|
2021-07-16 22:39:30 +00:00
|
|
|
// let file = std::fs::read(&path)?;
|
|
|
|
// let (output, err) = working_set.parse_file(&path, file);
|
2021-07-17 06:31:34 +00:00
|
|
|
|
|
|
|
let mut working_set = ParserWorkingSet::new(Some(parser_state.clone()));
|
|
|
|
let (output, err) = working_set.parse_source(path.as_bytes(), false);
|
2021-07-05 22:58:56 +00:00
|
|
|
println!("{:#?}", output);
|
2021-07-02 06:44:37 +00:00
|
|
|
println!("error: {:?}", err);
|
2021-07-16 06:24:46 +00:00
|
|
|
|
2021-07-16 20:26:40 +00:00
|
|
|
//println!("working set: {:#?}", working_set);
|
2021-07-16 06:24:46 +00:00
|
|
|
|
2021-07-03 03:35:15 +00:00
|
|
|
// println!("{}", size_of::<Statement>());
|
|
|
|
|
2021-07-16 06:24:46 +00:00
|
|
|
// let engine = Engine::new();
|
|
|
|
// let result = engine.eval_block(&output);
|
|
|
|
// println!("{:?}", result);
|
2021-07-16 01:10:22 +00:00
|
|
|
|
2021-07-03 03:35:15 +00:00
|
|
|
// let mut buffer = String::new();
|
|
|
|
// let stdin = std::io::stdin();
|
|
|
|
// let mut handle = stdin.lock();
|
|
|
|
|
|
|
|
// handle.read_to_string(&mut buffer)?;
|
2021-06-30 01:42:56 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
println!("specify file to lex");
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|