Skip to content

Commit

Permalink
[TODROP] Println and debug for parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
yannham committed Nov 20, 2024
1 parent fee6f82 commit 74f9906
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
9 changes: 7 additions & 2 deletions core/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod tests;
/// nickel>foo
/// 1
/// ```
#[derive(Debug)]
pub enum ExtendedTerm<T> {
Term(T),
ToplevelLet(LocIdent, T),
Expand Down Expand Up @@ -211,9 +212,13 @@ macro_rules! generate_compat_impl {
file_id: FileId,
lexer: lexer::Lexer,
) -> Result<($output, ParseErrors), ParseError> {
println!("Parsing with compat");

let alloc = AstAlloc::new();
self.parse_tolerant(&alloc, file_id, lexer)
.map(|(t, e)| (t.to_mainline(), e))
let (t, e) = self.parse_tolerant(&alloc, file_id, lexer)?;

println!("New AST representation: {t:?}");
Ok((t.to_mainline(), e))
}

fn parse_strict_compat(
Expand Down
17 changes: 15 additions & 2 deletions core/src/parser/uniterm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use std::{
/// it here). If, on the other hand, we enter the rule for an infix operator as in `a + 1`, `a` will
/// be converted to a `Term::Var` and the resulting uniterm will be
/// `UniTermNode::Term(Term::Op2(..))`.
#[derive(Debug)]
pub enum UniTermNode<'ast> {
/// A variable. Can refer both to a term variable or a type variable.
Var(LocIdent),
Expand All @@ -57,6 +58,7 @@ pub enum UniTermNode<'ast> {
}

/// A uniterm with positional information.
#[derive(Debug)]
pub struct UniTerm<'ast> {
node: UniTermNode<'ast>,
pos: TermPos,
Expand Down Expand Up @@ -101,6 +103,7 @@ impl<'ast> TryConvert<'ast, UniTerm<'ast>> for Type<'ast> {
type Error = ParseError;

fn try_convert(alloc: &'ast AstAlloc, ut: UniTerm<'ast>) -> Result<Self, ParseError> {
println!("Trying converting uniterm {ut:?} to type");
let pos = ut.pos;

let typ = match ut.node {
Expand Down Expand Up @@ -135,6 +138,7 @@ impl<'ast> TryConvert<'ast, UniTerm<'ast>> for Ast<'ast> {
type Error = ParseError;

fn try_convert(alloc: &'ast AstAlloc, ut: UniTerm<'ast>) -> Result<Self, ParseError> {
println!("Trying converting uniterm {ut:?} to term");
let UniTerm { node, pos } = ut;

let node = match node {
Expand All @@ -158,6 +162,8 @@ impl<'ast> TryConvert<'ast, UniTerm<'ast>> for Ast<'ast> {

impl<'ast> From<Ast<'ast>> for UniTerm<'ast> {
fn from(ast: Ast<'ast>) -> Self {
println!("Converting ast {ast:?} to uniterm");

let pos = ast.pos;

UniTerm {
Expand All @@ -169,6 +175,8 @@ impl<'ast> From<Ast<'ast>> for UniTerm<'ast> {

impl<'ast> From<Node<'ast>> for UniTerm<'ast> {
fn from(node: Node<'ast>) -> Self {
println!("Converting node {node:?} to uniterm");

UniTerm {
node: UniTermNode::Term(node.into()),
pos: TermPos::None,
Expand All @@ -178,6 +186,8 @@ impl<'ast> From<Node<'ast>> for UniTerm<'ast> {

impl<'ast> From<Type<'ast>> for UniTerm<'ast> {
fn from(ty: Type<'ast>) -> Self {
println!("Converting type {ty:?} to uniterm");

let pos = ty.pos;
UniTerm {
node: UniTermNode::Type(ty),
Expand All @@ -188,6 +198,7 @@ impl<'ast> From<Type<'ast>> for UniTerm<'ast> {

impl<'ast> From<UniRecord<'ast>> for UniTerm<'ast> {
fn from(ur: UniRecord<'ast>) -> Self {
println!("Converting unirecord {ur:?} to uniterm");
let pos = ur.pos;

UniTerm {
Expand All @@ -209,7 +220,7 @@ where
}

/// A record in the `UniTerm` syntax.
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct UniRecord<'ast> {
pub fields: Vec<FieldDef<'ast>>,
pub tail: Option<(RecordRows<'ast>, TermPos)>,
Expand Down Expand Up @@ -632,7 +643,7 @@ impl VarKindCell {

pub(super) trait FixTypeVars<'ast>
where
Self: Sized,
Self: Sized + std::fmt::Debug,
{
/// Post-process a type at the right hand side of an annotation by replacing each unbound type
/// variable `TypeF::Var(id)` by a term variable with the same identifier seen as a custom
Expand Down Expand Up @@ -694,6 +705,8 @@ where
/// forall a. [| 'foo, 'bar; a |] -> {foo : Str, bar: Str; a}
/// ```
fn fix_type_vars(self, alloc: &'ast AstAlloc, span: RawSpan) -> Result<Self, ParseError> {
println!("Calling to fix_type_vars on {self:?}");

Ok(self
.fix_type_vars_env(alloc, BoundVarEnv::new(), span)?
.unwrap_or(self))
Expand Down
4 changes: 2 additions & 2 deletions core/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ impl<'a> Pretty<'a, Allocator> for &Term {
.group()
],
},
Var(id) => allocator.as_string(id),
Var(id) => docs![allocator, "~", allocator.as_string(id)],
Enum(id) => allocator.text("'").append(allocator.text(ident_quoted(id))),
EnumVariant { tag, arg, attrs: _ } => allocator
.text("'")
Expand Down Expand Up @@ -1252,7 +1252,7 @@ impl<'a> Pretty<'a, Allocator> for &Type {
ForeignId => allocator.text("ForeignId"),
Symbol => allocator.text("Symbol"),
Contract(t) => t.pretty(allocator),
Var(var) => allocator.as_string(var),
Var(var) => docs![allocator, "!", allocator.as_string(var)],
Forall { var, ref body, .. } => {
let mut curr = body.as_ref();
let mut foralls = vec![var];
Expand Down

0 comments on commit 74f9906

Please sign in to comment.