Conlang v0.0.5: Pratternization

cl-token:
- Minimize data redundancy by consolidating TokenKind::Literal; TokenData::{String, Identifier}
- Rename Op to Punct

cl-ast:
- Remove ExprKind::{Member, Call} in favor of making them
'binary' operators
- Consolidate boxes (TODO: consolidate more boxes)
- Remove repetition vecs in favor of boxes (this may come with performance tradeoffs!)

cl-lexer:
- Reflect changes from cl-token

cl-interpret, cl-repl/src/examples:
- Reflect changes from cl-ast

cl-parser:
- Switch to Pratt parsing for expressions
  - TODO: Code cleanup
  - TODO: Use total ordering for Precedence instead of binding powers (that's what the binding powers are there for anyway)
- Switch functional parsers to take Punct instead of TokenKind
  - It's not like we need a `for`-separated list
- Remove `binary` macro. No longer needed with precedence climbing.
- Repurpose `operator` macro to produce both the operator and the respective Precedence
- Remove several of the smaller parser functions, since they've been consolidated into the larger `exprkind`
This commit is contained in:
2024-04-13 03:33:26 -05:00
parent 2c36ccc0cf
commit fc3cbbf450
11 changed files with 636 additions and 778 deletions

View File

@@ -363,8 +363,6 @@ pub mod yamlify {
ExprKind::Assign(k) => k.yaml(y),
ExprKind::Binary(k) => k.yaml(y),
ExprKind::Unary(k) => k.yaml(y),
ExprKind::Member(k) => k.yaml(y),
ExprKind::Call(k) => k.yaml(y),
ExprKind::Index(k) => k.yaml(y),
ExprKind::Path(k) => k.yaml(y),
ExprKind::Literal(k) => k.yaml(y),
@@ -386,18 +384,25 @@ pub mod yamlify {
}
impl Yamlify for Assign {
fn yaml(&self, y: &mut Yamler) {
let Self { head, op: _, tail } = self;
y.key("Assign").pair("head", head).pair("tail", tail);
let Self { kind, parts } = self;
y.key("Assign")
.pair("kind", kind)
.pair("head", &parts.0)
.pair("tail", &parts.1);
}
}
impl Yamlify for AssignKind {
fn yaml(&self, y: &mut Yamler) {
y.value(self);
}
}
impl Yamlify for Binary {
fn yaml(&self, y: &mut Yamler) {
let Self { head, tail } = self;
let mut y = y.key("Binary");
y.pair("head", head);
for (op, expr) in tail {
y.key("tail").pair("op", op).pair("expr", expr);
}
let Self { kind, parts } = self;
y.key("Binary")
.pair("kind", kind)
.pair("head", &parts.0)
.pair("tail", &parts.1);
}
}
impl Yamlify for BinaryKind {
@@ -407,12 +412,8 @@ pub mod yamlify {
}
impl Yamlify for Unary {
fn yaml(&self, y: &mut Yamler) {
let Self { ops, tail } = self;
let mut y = y.key("Unary");
for op in ops {
y.pair("op", op);
}
y.pair("tail", tail);
let Self { kind, tail } = self;
y.key("Unary").pair("kind", kind).pair("tail", tail);
}
}
impl Yamlify for UnaryKind {
@@ -420,18 +421,6 @@ pub mod yamlify {
y.value(self);
}
}
impl Yamlify for Member {
fn yaml(&self, y: &mut Yamler) {
let Self { head, tail } = self;
y.key("Member").pair("head", head).pair("tail", tail);
}
}
impl Yamlify for Call {
fn yaml(&self, y: &mut Yamler) {
let Self { callee, args } = self;
y.key("Call").pair("callee", callee).pair("args", args);
}
}
impl Yamlify for Tuple {
fn yaml(&self, y: &mut Yamler) {
let Self { exprs } = self;
@@ -444,12 +433,6 @@ pub mod yamlify {
y.key("Index").pair("head", head).list(indices);
}
}
impl Yamlify for Indices {
fn yaml(&self, y: &mut Yamler) {
let Self { exprs } = self;
y.key("Indices").list(exprs);
}
}
impl Yamlify for Array {
fn yaml(&self, y: &mut Yamler) {
let Self { values } = self;
@@ -466,8 +449,11 @@ pub mod yamlify {
}
impl Yamlify for AddrOf {
fn yaml(&self, y: &mut Yamler) {
let Self { count: _, mutable, expr } = self;
y.key("Addr").yaml(mutable).pair("expr", expr);
let Self { count, mutable, expr } = self;
y.key("AddrOf")
.yaml(mutable)
.pair("count", count)
.pair("expr", expr);
}
}
impl Yamlify for Group {