Merge pull request #431 from Kindelia/experimental

Fixed string problems
This commit is contained in:
Felipe G 2022-12-01 17:11:02 -03:00 committed by GitHub
commit 8ec30579ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 8 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "kind-cli"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
description = "A pure functional functional language that uses the HVM."
repository = "https://github.com/Kindelia/Kind2"

View File

@ -182,7 +182,7 @@ impl<'a> Visitor for Subst<'a> {
self.visit_expr(val);
self.visit_expr(typ);
}
ExprKind::Lit { lit } => self.visit_literal(lit),
ExprKind::Lit { lit } => self.visit_literal(expr.range, lit),
ExprKind::Binary { op: _, fst, snd } => {
self.visit_expr(fst);
self.visit_expr(snd);

View File

@ -334,7 +334,11 @@ impl Visitor for UnboundCollector {
fn visit_pat(&mut self, pat: &mut Pat) {
match &mut pat.data {
PatKind::Var(ident) => self.visit_pat_ident(ident),
PatKind::Str(_) => (),
PatKind::Str(_) => {
let string = &mut QualifiedIdent::new_static("String", None, pat.range);
self.visit_qualified_ident(&mut string.add_segment("cons").to_generated());
self.visit_qualified_ident(&mut string.add_segment("nil").to_generated());
}
PatKind::U60(_) => (),
PatKind::U120(_) => (),
PatKind::F60(_) => (),
@ -393,6 +397,19 @@ impl Visitor for UnboundCollector {
}
}
fn visit_literal(&mut self, range: Range, lit: &mut kind_tree::concrete::Literal) {
use kind_tree::concrete::Literal::*;
match lit {
String(_) => {
let string = &mut QualifiedIdent::new_static("String", None, range);
self.visit_qualified_ident(&mut string.add_segment("cons").to_generated());
self.visit_qualified_ident(&mut string.add_segment("nil").to_generated());
}
_ => (),
}
}
fn visit_expr(&mut self, expr: &mut Expr) {
match &mut expr.data {
ExprKind::Var { name } => self.visit_ident(name),
@ -439,7 +456,7 @@ impl Visitor for UnboundCollector {
self.visit_expr(val);
self.visit_expr(typ);
}
ExprKind::Lit { lit } => self.visit_literal(lit),
ExprKind::Lit { lit } => self.visit_literal(expr.range, lit),
ExprKind::Binary { op: _, fst, snd } => {
self.visit_expr(fst);
self.visit_expr(snd);

View File

@ -0,0 +1 @@
"ata"

View File

@ -0,0 +1,3 @@
Main : U60 {
"ata"
}

View File

@ -56,8 +56,8 @@ pub trait Visitor: Sized {
walk_syntax_ctx(self, synt);
}
fn visit_literal(&mut self, lit: &mut Literal) {
walk_literal(self, lit);
fn visit_literal(&mut self, range: Range, lit: &mut Literal) {
walk_literal(self, range, lit);
}
fn visit_pat_ident(&mut self, ident: &mut PatIdent) {
@ -145,7 +145,7 @@ pub fn walk_range<T: Visitor>(_: &mut T, _: &mut Range) {}
pub fn walk_syntax_ctx<T: Visitor>(_: &mut T, _: &mut SyntaxCtxIndex) {}
pub fn walk_literal<T: Visitor>(_: &mut T, _: &mut Literal) {}
pub fn walk_literal<T: Visitor>( _: &mut T, _: Range, _: &mut Literal) {}
pub fn walk_constructor<T: Visitor>(ctx: &mut T, cons: &mut Constructor) {
ctx.visit_ident(&mut cons.name);
@ -463,7 +463,7 @@ pub fn walk_expr<T: Visitor>(ctx: &mut T, expr: &mut Expr) {
ctx.visit_expr(typ);
}
ExprKind::Lit { lit } => {
ctx.visit_literal(lit);
ctx.visit_literal(expr.range, lit);
}
ExprKind::Binary { op: _, fst, snd } => {
ctx.visit_expr(fst);