Compare commits
No commits in common. "173ec3ab389afe0d7384eb95f2f82a610ccb0063" and "9ffcf68695be31ac99182ee52e8098955dfefacb" have entirely different histories.
173ec3ab38
...
9ffcf68695
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
.idea
|
.idea
|
||||||
*.swp
|
|
134
src/ast/mod.rs
134
src/ast/mod.rs
@ -1,134 +0,0 @@
|
|||||||
use pest::{iterators::{Pair, Pairs}, Parser};
|
|
||||||
use crate::parser::{DeimosParser, Rule};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct CompilationUnit {
|
|
||||||
namespace: Option<Fqn>,
|
|
||||||
declarations: Vec<Declaration>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Fqn {
|
|
||||||
identifiers: Vec<Identifier>
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Declaration {
|
|
||||||
Interface {
|
|
||||||
identifier: Identifier,
|
|
||||||
type_declaration: TypeDeclaration,
|
|
||||||
},
|
|
||||||
Implementation {
|
|
||||||
identifier: Identifier,
|
|
||||||
type_declaration: TypeDeclaration
|
|
||||||
},
|
|
||||||
Module {
|
|
||||||
identifier: Identifier,
|
|
||||||
declarations: Vec<Declaration>,
|
|
||||||
},
|
|
||||||
Function {
|
|
||||||
identifier: Identifier,
|
|
||||||
statement: Statement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct TypeDeclaration {
|
|
||||||
generics: Vec<GenericParameter>,
|
|
||||||
extends: Vec<Identifier>,
|
|
||||||
declarations: Vec<Declaration>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Identifier {
|
|
||||||
name: String
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct GenericParameter {
|
|
||||||
identifier: Identifier,
|
|
||||||
bound: Option<GenericBound>
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum GenericBound {
|
|
||||||
Extends {
|
|
||||||
identifier: Identifier
|
|
||||||
},
|
|
||||||
Super {
|
|
||||||
identifier: Identifier
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Statement {
|
|
||||||
BlockStatement {
|
|
||||||
statements: Vec<Statement>
|
|
||||||
},
|
|
||||||
CallStatement,
|
|
||||||
AssignmentStatement
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_identifier(pair: Pair<Rule>) -> Identifier {
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::identifier => {
|
|
||||||
Identifier {
|
|
||||||
name: String::from(pair.as_str())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => panic!("Expected an identifier.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_fqn(fqn_pair: Pair<Rule>) -> Fqn {
|
|
||||||
let mut identifiers: Vec<Identifier> = vec![];
|
|
||||||
for pair in fqn_pair.into_inner() {
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::identifier => {
|
|
||||||
identifiers.push(build_identifier(pair));
|
|
||||||
}
|
|
||||||
_ => panic!("Expected only identifiers.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Fqn {
|
|
||||||
identifiers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_compilation_unit(pair: Pair<Rule>)-> CompilationUnit {
|
|
||||||
let mut namespace: Option<Fqn> = None;
|
|
||||||
let mut declarations: Vec<Declaration> = vec![];
|
|
||||||
|
|
||||||
for pair in pair.into_inner() {
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::namespace => {
|
|
||||||
let fqn_pair = pair.into_inner().next().unwrap();
|
|
||||||
namespace = Some(build_fqn(fqn_pair));
|
|
||||||
}
|
|
||||||
Rule::declaration => {
|
|
||||||
todo!();
|
|
||||||
}
|
|
||||||
Rule::EOI => {} // ignore
|
|
||||||
_ => panic!("Expected only namespace, declaration, or EOI rules, found: {}", pair)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CompilationUnit {
|
|
||||||
namespace,
|
|
||||||
declarations
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build_ast(src: &str) -> CompilationUnit {
|
|
||||||
let pair = DeimosParser::parse(Rule::compilation_unit, src)
|
|
||||||
.expect("Unsuccessful parse.")
|
|
||||||
.next()
|
|
||||||
.expect("Expcted compilation_unit.");
|
|
||||||
match pair.as_rule() {
|
|
||||||
Rule::compilation_unit => {
|
|
||||||
build_compilation_unit(pair)
|
|
||||||
},
|
|
||||||
_ => panic!("Expected compilation_unit rule.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
|||||||
use deimos::ast::build_ast;
|
|
||||||
use deimos::vm::dm_type::DmType;
|
use deimos::vm::dm_type::DmType;
|
||||||
use deimos::vm::lib::{DmConstant, DmLib};
|
use deimos::vm::lib::{DmConstant, DmLib};
|
||||||
use deimos::vm::object_type::{DmField, DmFn, DmImplementation, DmInterface, DmMethod};
|
use deimos::vm::object_type::{DmField, DmFn, DmImplementation, DmInterface, DmMethod};
|
||||||
@ -14,9 +13,6 @@ fn main() {
|
|||||||
// - write a single lib with a main()
|
// - write a single lib with a main()
|
||||||
// - call the main fn
|
// - call the main fn
|
||||||
// fn main() { println "Hello, World!" }
|
// fn main() { println "Hello, World!" }
|
||||||
|
|
||||||
let compilation_unit = build_ast("ns hello::test::bye");
|
|
||||||
println!("{:?}", compilation_unit);
|
|
||||||
|
|
||||||
// std/core/array lib
|
// std/core/array lib
|
||||||
let mut array_lib = DmLib::new("std/core/array");
|
let mut array_lib = DmLib::new("std/core/array");
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#![allow(warnings)]
|
|
||||||
mod compiler;
|
mod compiler;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
mod util;
|
mod util;
|
||||||
pub mod vm;
|
pub mod vm;
|
||||||
pub mod ast;
|
|
||||||
|
@ -58,4 +58,4 @@ string_char = {
|
|||||||
| "\\" ~ ( "u" ~ ASCII_HEX_DIGIT{4} )
|
| "\\" ~ ( "u" ~ ASCII_HEX_DIGIT{4} )
|
||||||
}
|
}
|
||||||
|
|
||||||
WHITESPACE = _{ " " | "\t" | "\n" | "\r" }
|
WHITESPACE = _{ " " | "\t" | "\n" | "\r" }
|
Loading…
Reference in New Issue
Block a user