conlang: deprecate the AST
This commit is contained in:
parent
6bb2f3774f
commit
5e2f365f45
@ -7,7 +7,7 @@
|
|||||||
//! [`Identifier`]` := `[`IDENTIFIER`](crate::token::token_type::Type::Identifier)
|
//! [`Identifier`]` := `[`IDENTIFIER`](crate::token::token_type::Type::Identifier)
|
||||||
//!
|
//!
|
||||||
//! See [statement], [literal], and [expression] for more information.
|
//! See [statement], [literal], and [expression] for more information.
|
||||||
|
#![deprecated]
|
||||||
pub mod preamble {
|
pub mod preamble {
|
||||||
#![allow(deprecated)]
|
#![allow(deprecated)]
|
||||||
//! Common imports for working with the [ast](super)
|
//! Common imports for working with the [ast](super)
|
||||||
@ -123,12 +123,30 @@ pub mod statement {
|
|||||||
/// # Syntax
|
/// # Syntax
|
||||||
/// [`Fn`](Stmt::Fn) := `"fn"` [`Identifier`] `'('` `Args...` `')'` [`Block`]
|
/// [`Fn`](Stmt::Fn) := `"fn"` [`Identifier`] `'('` `Args...` `')'` [`Block`]
|
||||||
Fn(FnDecl),
|
Fn(FnDecl),
|
||||||
|
/// Contains a module declaration
|
||||||
|
/// # Syntax
|
||||||
|
/// [`Mod`](Stmt::Mod) := `"mod"` [`Identifier`] `'{'`
|
||||||
|
///
|
||||||
|
/// `'}'`
|
||||||
/// Contains an expression statement
|
/// Contains an expression statement
|
||||||
/// # Syntax
|
/// # Syntax
|
||||||
/// [`Expr`](Stmt::Expr) := [`Expr`] `;`
|
/// [`Expr`](Stmt::Expr) := [`Expr`] `;`
|
||||||
Expr(Expr),
|
Expr(Expr),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Contains the declarations allowed in a module
|
||||||
|
///
|
||||||
|
/// # Syntax
|
||||||
|
/// [Mod](Module::Mod) := "mod" [Identifier] '{' [Module] '}'
|
||||||
|
/// [`Let`](Module::Let) := `"let"` [`Identifier`] (`:` `Type`)? (`=` [`Expr`])? `;`
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum Module {
|
||||||
|
Struct(StructDecl),
|
||||||
|
Mod(ModuleDecl),
|
||||||
|
Let(Let),
|
||||||
|
Fn(FnDecl),
|
||||||
|
}
|
||||||
|
|
||||||
/// Contains a variable declaration
|
/// Contains a variable declaration
|
||||||
/// # Syntax
|
/// # Syntax
|
||||||
/// [`Let`] := `let` [`Identifier`] (`:`) `Type`)? (`=` [`Expr`])? `;`
|
/// [`Let`] := `let` [`Identifier`] (`:`) `Type`)? (`=` [`Expr`])? `;`
|
||||||
@ -160,7 +178,22 @@ pub mod statement {
|
|||||||
pub ty: Option<TypeExpr>,
|
pub ty: Option<TypeExpr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Contains the name and declaration
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct ModuleDecl {}
|
||||||
|
|
||||||
// TODO: Create closure, transmute fndecl into a name and closure
|
// TODO: Create closure, transmute fndecl into a name and closure
|
||||||
|
/// Contains the name and field information for a struct
|
||||||
|
///
|
||||||
|
/// # Syntax
|
||||||
|
/// [`StructDecl`]` := "struct" `[`Identifier`]` '{'
|
||||||
|
/// (`[`Identifier`]` ':' `[`TypeExpr`]`),*
|
||||||
|
/// '}'`
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct StructDecl {
|
||||||
|
pub name: Identifier,
|
||||||
|
pub data: Vec<(Identifier, TypeExpr)>,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod path {
|
pub mod path {
|
||||||
@ -324,6 +357,10 @@ pub mod expression {
|
|||||||
pub callee: Box<Primary>,
|
pub callee: Box<Primary>,
|
||||||
pub args: Vec<Tuple>,
|
pub args: Vec<Tuple>,
|
||||||
}
|
}
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub fn FnCall(callee: Box<Primary>, args: Vec<Tuple>) -> FnCall {
|
||||||
|
FnCall { callee, args }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod tuple {
|
pub mod tuple {
|
||||||
@ -762,6 +799,16 @@ pub mod todo {
|
|||||||
//! traits, modules, etc.
|
//! traits, modules, etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod module {
|
||||||
|
//! Module support
|
||||||
|
//! - [ ] Add Module Declaration type : ModDecl = "mod" Identifier '{' Module '}' ;
|
||||||
|
//! - [ ] Change Program to Module : Module = (ModDecl | FnDecl | Let)*
|
||||||
|
//! - [ ] Implementer's note: Modules must be traversed breadth-first, with no
|
||||||
|
//! alpha-renaming
|
||||||
|
//! - [ ] Blocks should probably also be traversed breadth-first, and Let declarations
|
||||||
|
//! hoisted up, leaving initialization assignments in-place
|
||||||
|
}
|
||||||
|
|
||||||
pub mod structure {
|
pub mod structure {
|
||||||
//! Struct support
|
//! Struct support
|
||||||
//! - [ ] Add struct declaration expression (returns a struct declaration)
|
//! - [ ] Add struct declaration expression (returns a struct declaration)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//! Parses [tokens](super::token) into an [AST](super::ast)
|
//! Parses [tokens](super::token) into an [AST](super::ast)
|
||||||
|
#![deprecated]
|
||||||
|
#![allow(deprecated)]
|
||||||
use super::{ast::preamble::*, lexer::Lexer, token::preamble::*};
|
use super::{ast::preamble::*, lexer::Lexer, token::preamble::*};
|
||||||
use error::{Error, *};
|
use error::{Error, *};
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
//! A [Printer] pretty-prints a Conlang [syntax tree](crate::ast)
|
//! A [Printer] pretty-prints a Conlang [syntax tree](crate::ast)
|
||||||
|
#![deprecated]
|
||||||
|
#![allow(deprecated)]
|
||||||
use super::ast::preamble::*;
|
use super::ast::preamble::*;
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
//! This will hopefully become a fully fledged static resolution pass in the future
|
//! This will hopefully become a fully fledged static resolution pass in the future
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::ast::preamble::*;
|
|
||||||
|
|
||||||
use scopeguard::Scoped;
|
use scopeguard::Scoped;
|
||||||
pub mod scopeguard {
|
pub mod scopeguard {
|
||||||
//! Implements a generic RAII scope-guard
|
//! Implements a generic RAII scope-guard
|
||||||
@ -488,7 +486,10 @@ pub trait Resolve {
|
|||||||
Ok(Type::Empty)
|
Ok(Type::Empty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mod ast1 {
|
||||||
|
#![allow(deprecated)]
|
||||||
|
use super::*;
|
||||||
|
use crate::ast::preamble::*;
|
||||||
impl Resolve for Start {
|
impl Resolve for Start {
|
||||||
fn resolve(&mut self, resolver: &mut Resolver) -> TyResult<Type> {
|
fn resolve(&mut self, resolver: &mut Resolver) -> TyResult<Type> {
|
||||||
let Self(program) = self;
|
let Self(program) = self;
|
||||||
@ -516,7 +517,8 @@ impl Resolve for Stmt {
|
|||||||
}
|
}
|
||||||
impl Resolve for Let {
|
impl Resolve for Let {
|
||||||
fn resolve(&mut self, resolver: &mut Resolver) -> TyResult<Type> {
|
fn resolve(&mut self, resolver: &mut Resolver) -> TyResult<Type> {
|
||||||
let Let { name: Name { symbol: Identifier { name, index }, mutable, ty: _ }, init } = self;
|
let Let { name: Name { symbol: Identifier { name, index }, mutable, ty: _ }, init } =
|
||||||
|
self;
|
||||||
debugln!("ty> let {name} ...");
|
debugln!("ty> let {name} ...");
|
||||||
if let Some(init) = init {
|
if let Some(init) = init {
|
||||||
let ty = init.resolve(resolver)?;
|
let ty = init.resolve(resolver)?;
|
||||||
@ -641,7 +643,11 @@ impl Resolver {
|
|||||||
Ok(first)
|
Ok(first)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn resolve_unary_operator(&mut self, operand: Type, op: &operator::Unary) -> TyResult<Type> {
|
fn resolve_unary_operator(
|
||||||
|
&mut self,
|
||||||
|
operand: Type,
|
||||||
|
op: &operator::Unary,
|
||||||
|
) -> TyResult<Type> {
|
||||||
// TODO: Allow more expressive unary operator type conversions
|
// TODO: Allow more expressive unary operator type conversions
|
||||||
todo!("Resolve unary operators {op:?} {operand}")
|
todo!("Resolve unary operators {op:?} {operand}")
|
||||||
}
|
}
|
||||||
@ -844,6 +850,10 @@ impl Resolve for Return {
|
|||||||
expr.resolve(resolver)
|
expr.resolve(resolver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod ast2 {}
|
||||||
|
|
||||||
// heakc yea man, generics
|
// heakc yea man, generics
|
||||||
impl<T: Resolve> Resolve for Option<T> {
|
impl<T: Resolve> Resolve for Option<T> {
|
||||||
fn resolve(&mut self, resolver: &mut Resolver) -> TyResult<Type> {
|
fn resolve(&mut self, resolver: &mut Resolver) -> TyResult<Type> {
|
||||||
|
Loading…
Reference in New Issue
Block a user