Compare commits
2 Commits
another-at
...
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,10 +5,8 @@ use crate::ast::*;
|
|||||||
//or a tuple of (T, <that type>)
|
//or a tuple of (T, <that type>)
|
||||||
|
|
||||||
pub trait ASTVisitor: Sized {
|
pub trait ASTVisitor: Sized {
|
||||||
type BlockHandler: BlockVisitor = ();
|
|
||||||
fn ast(&mut self, _ast: &AST) {}
|
fn ast(&mut self, _ast: &AST) {}
|
||||||
fn block(&mut self) -> Self::BlockHandler { Self::BlockHandler::new() }
|
fn block(&mut self, _statements: &Vec<Statement>) {}
|
||||||
fn block_finished(&mut self, handler: Self::BlockHandler) {}
|
|
||||||
fn statement(&mut self, _statement: &Statement) {}
|
fn statement(&mut self, _statement: &Statement) {}
|
||||||
fn declaration(&mut self, _declaration: &Declaration) {}
|
fn declaration(&mut self, _declaration: &Declaration) {}
|
||||||
fn signature(&mut self, _signature: &Signature) {}
|
fn signature(&mut self, _signature: &Signature) {}
|
||||||
@@ -41,15 +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 BlockVisitor {
|
|
||||||
fn new() -> Self;
|
|
||||||
fn pre_block(&mut self) {}
|
|
||||||
fn post_block(&mut self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BlockVisitor for () {
|
|
||||||
fn new() -> () { () }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use crate::ast::*;
|
use crate::ast::*;
|
||||||
use crate::ast::visitor::{ASTVisitor, BlockVisitor};
|
use crate::ast::visitor::ASTVisitor;
|
||||||
use crate::util::deref_optional_box;
|
use crate::util::deref_optional_box;
|
||||||
|
|
||||||
pub fn walk_ast<V: ASTVisitor>(v: &mut V, ast: &AST) {
|
pub fn walk_ast<V: ASTVisitor>(v: &mut V, ast: &AST) {
|
||||||
@@ -10,14 +10,10 @@ pub fn walk_ast<V: ASTVisitor>(v: &mut V, ast: &AST) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn walk_block<V: ASTVisitor>(v: &mut V, block: &Vec<Statement>) {
|
fn walk_block<V: ASTVisitor>(v: &mut V, block: &Vec<Statement>) {
|
||||||
let mut block_handler = v.block();
|
|
||||||
block_handler.pre_block();
|
|
||||||
for s in block {
|
for s in block {
|
||||||
v.statement(s);
|
v.statement(s);
|
||||||
statement(v, s);
|
statement(v, s);
|
||||||
}
|
}
|
||||||
block_handler.post_block();
|
|
||||||
v.block_finished(block_handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn statement<V: ASTVisitor>(v: &mut V, statement: &Statement) {
|
fn statement<V: ASTVisitor>(v: &mut V, statement: &Statement) {
|
||||||
@@ -48,6 +44,7 @@ fn declaration<V: ASTVisitor>(v: &mut V, decl: &Declaration) {
|
|||||||
},
|
},
|
||||||
FuncDecl(sig, block) => {
|
FuncDecl(sig, block) => {
|
||||||
v.signature(&sig);
|
v.signature(&sig);
|
||||||
|
v.block(&block);
|
||||||
walk_block(v, block);
|
walk_block(v, block);
|
||||||
},
|
},
|
||||||
TypeDecl { name, body, mutable } => v.type_declaration(name, body, *mutable),
|
TypeDecl { name, body, mutable } => v.type_declaration(name, body, *mutable),
|
||||||
@@ -126,6 +123,7 @@ fn lambda<V: ASTVisitor>(v: &mut V, params: &Vec<FormalParam>, type_anno: Option
|
|||||||
formal_param(v, param);
|
formal_param(v, param);
|
||||||
}
|
}
|
||||||
v.type_annotation(type_anno);
|
v.type_annotation(type_anno);
|
||||||
|
v.block(body);
|
||||||
walk_block(v, body);
|
walk_block(v, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,6 +234,7 @@ fn condition_arm<V: ASTVisitor>(v: &mut V, arm: &ConditionArm) {
|
|||||||
v.expression(guard);
|
v.expression(guard);
|
||||||
expression(v, guard);
|
expression(v, guard);
|
||||||
});
|
});
|
||||||
|
v.block(&arm.body);
|
||||||
walk_block(v, &arm.body);
|
walk_block(v, &arm.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#![feature(associated_type_defaults)] //needed for Visitor trait
|
|
||||||
#![feature(trace_macros)]
|
#![feature(trace_macros)]
|
||||||
|
//#![feature(unrestricted_attribute_tokens)]
|
||||||
#![feature(slice_patterns, box_patterns, box_syntax)]
|
#![feature(slice_patterns, box_patterns, box_syntax)]
|
||||||
|
|
||||||
//! `schala-lang` is where the Schala programming language is actually implemented.
|
//! `schala-lang` is where the Schala programming language is actually implemented.
|
||||||
|
|||||||
Reference in New Issue
Block a user