Compare commits
2 Commits
complex_vi
...
parser_com
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc87f8cd90 | ||
|
|
a0955e07dc |
5
Cargo.lock
generated
5
Cargo.lock
generated
@@ -461,6 +461,10 @@ dependencies = [
|
|||||||
"autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "partis"
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf"
|
name = "phf"
|
||||||
version = "0.7.24"
|
version = "0.7.24"
|
||||||
@@ -739,6 +743,7 @@ name = "schala"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"includedir_codegen 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"includedir_codegen 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"partis 0.1.0",
|
||||||
"schala-lang 0.1.0",
|
"schala-lang 0.1.0",
|
||||||
"schala-repl 0.1.0",
|
"schala-repl 0.1.0",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ authors = ["greg <greg.shuflin@protonmail.com>"]
|
|||||||
|
|
||||||
schala-repl = { path = "schala-repl" }
|
schala-repl = { path = "schala-repl" }
|
||||||
schala-lang = { path = "schala-lang/language" }
|
schala-lang = { path = "schala-lang/language" }
|
||||||
|
partis = { path="partis" }
|
||||||
# maaru-lang = { path = "maaru" }
|
# maaru-lang = { path = "maaru" }
|
||||||
# rukka-lang = { path = "rukka" }
|
# rukka-lang = { path = "rukka" }
|
||||||
# robo-lang = { path = "robo" }
|
# robo-lang = { path = "robo" }
|
||||||
|
|||||||
9
partis/Cargo.toml
Normal file
9
partis/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "partis"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["greg <greg.shuflin@protonmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
17
partis/src/lib.rs
Normal file
17
partis/src/lib.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
struct ParseError { }
|
||||||
|
|
||||||
|
enum ParseResult<'a, T> {
|
||||||
|
Success(T, &'a str),
|
||||||
|
Failure(ParseError),
|
||||||
|
Incomplete,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
assert_eq!(2 + 2, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::util::deref_optional_box;
|
|
||||||
|
|
||||||
//TODO maybe these functions should take closures that return a KeepRecursing | StopHere type,
|
//TODO maybe these functions should take closures that return a KeepRecursing | StopHere type,
|
||||||
//or a tuple of (T, <that type>)
|
//or a tuple of (T, <that type>)
|
||||||
@@ -40,126 +39,3 @@ pub trait ASTVisitor: Sized {
|
|||||||
fn prefix_exp(&mut self, _op: &PrefixOp, _arg: &Expression) {}
|
fn prefix_exp(&mut self, _op: &PrefixOp, _arg: &Expression) {}
|
||||||
fn pattern(&mut self, _pat: &Pattern) {}
|
fn pattern(&mut self, _pat: &Pattern) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ASTVisitorNew: Sized {
|
|
||||||
fn expression(&mut self, _expression: &Expression) -> VisitResult { VisitResult::default() }
|
|
||||||
fn expression_kind(&mut self, _kind: &ExpressionKind) -> VisitResult { VisitResult::default() }
|
|
||||||
|
|
||||||
fn type_annotation(&mut self, _id: ItemId, _type_anno: Option<&TypeIdentifier>) -> VisitResult { VisitResult::default() }
|
|
||||||
|
|
||||||
fn named_struct(&mut self, _name: &QualifiedName, _fields: &Vec<(Rc<String>, Expression)>) -> VisitResult { VisitResult::default() }
|
|
||||||
|
|
||||||
fn nat_literal(&mut self, _id: ItemId, _n: u64)-> VisitResult { VisitResult::default() }
|
|
||||||
fn float_literal(&mut self, _id: ItemId, _f: f64) -> VisitResult { VisitResult::default() }
|
|
||||||
fn string_literal(&mut self, _id: ItemId, _s: &Rc<String>) -> VisitResult { VisitResult::default() }
|
|
||||||
fn bool_literal(&mut self, _id: ItemId, _b: bool) -> VisitResult { VisitResult::default() }
|
|
||||||
|
|
||||||
fn qualified_name(&mut self, _id: ItemId, _name: &QualifiedName) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum VisitResult {
|
|
||||||
KeepRecursing,
|
|
||||||
Stop
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::default::Default for VisitResult {
|
|
||||||
fn default() -> VisitResult { VisitResult::KeepRecursing }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn traverse<V: ASTVisitorNew>(visitor: &mut V, expression: &Expression) {
|
|
||||||
expresion(visitor, expresion)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expression<V: ASTVisitorNew>(visitor: &mut V, expression: &Expression) {
|
|
||||||
use ExpressionKind::*;
|
|
||||||
|
|
||||||
let Expression { id, kind, type_anno } = expression;
|
|
||||||
|
|
||||||
let output = match kind {
|
|
||||||
NatLiteral(n) => v.nat_literal(id, *n),
|
|
||||||
FloatLiteral(f) => v.float_literal(id, *f),
|
|
||||||
StringLiteral(s) => v.string_literal(id, s),
|
|
||||||
BoolLiteral(b) => v.bool_literal(d, *b),
|
|
||||||
BinExp(op, lhs, rhs) => {
|
|
||||||
expression(v, lhs);
|
|
||||||
expression(v, rhs);
|
|
||||||
},
|
|
||||||
PrefixExp(op, arg) => {
|
|
||||||
expression(v, arg);
|
|
||||||
}
|
|
||||||
TupleLiteral(exprs) => {
|
|
||||||
for expr in exprs {
|
|
||||||
expression(v, expr);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Value(name) => v.qualified_name(id, name),
|
|
||||||
NamedStruct { name, fields } => {
|
|
||||||
for (_, expr) in fields.iter() {
|
|
||||||
v.expression(expr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Call { f, arguments } => {
|
|
||||||
expression(v, f);
|
|
||||||
for arg in args.iter() {
|
|
||||||
match arg {
|
|
||||||
InvocationArgument::Positional(expr) => {
|
|
||||||
expression(v, expr);
|
|
||||||
},
|
|
||||||
InvocationArgument::Keyword { expr, .. } => {
|
|
||||||
expression(v, expr);
|
|
||||||
},
|
|
||||||
Ignored => (),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Index { indexee, indexers } => {
|
|
||||||
expression(v, indexee);
|
|
||||||
for i in indexers.iter() {
|
|
||||||
expression(v, i);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
IfExpression { discriminator, body } => {
|
|
||||||
discriminator.as_ref().map(|d| expression(v, d));
|
|
||||||
match body {
|
|
||||||
IfExpressionBody::SimpleConditional { then_case, else_case } => {
|
|
||||||
walk_block(v, then_case);
|
|
||||||
else_case.as_ref().map(|block| walk_block(v, block));
|
|
||||||
},
|
|
||||||
IfExpressionBody::SimplePatternMatch { pattern, then_case, else_case } => {
|
|
||||||
v.pattern(pattern);
|
|
||||||
walk_pattern(v, pattern);
|
|
||||||
walk_block(v, then_case);
|
|
||||||
else_case.as_ref().map(|block| walk_block(v, block));
|
|
||||||
},
|
|
||||||
IfExpressionBody::CondList(arms) => {
|
|
||||||
for arm in arms {
|
|
||||||
v.condition_arm(arm);
|
|
||||||
condition_arm(v, arm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
WhileExpression { condition, body } => (),
|
|
||||||
ForExpression { enumerators, body } => (),
|
|
||||||
Lambda { params , type_anno, body } => {
|
|
||||||
for param in params {
|
|
||||||
formal_param(v, param);
|
|
||||||
}
|
|
||||||
v.type_annotation(type_anno);
|
|
||||||
},
|
|
||||||
ListLiteral(exprs) => {
|
|
||||||
for expr in exprs {
|
|
||||||
expression(v, expr);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
output
|
|
||||||
}
|
|
||||||
|
|
||||||
fn formal_param<V: ASTVisitorNew>(v: &mut V, param: &FormalParam) {
|
|
||||||
param.default.as_ref().map(|p| {
|
|
||||||
expression(v, p);
|
|
||||||
});
|
|
||||||
v.type_annotation(param.anno.as_ref());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#![feature(trace_macros)]
|
#![feature(trace_macros)]
|
||||||
#![feature(custom_attribute)]
|
|
||||||
//#![feature(unrestricted_attribute_tokens)]
|
//#![feature(unrestricted_attribute_tokens)]
|
||||||
#![feature(slice_patterns, box_patterns, box_syntax)]
|
#![feature(slice_patterns, box_patterns, box_syntax)]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user