Skip to content

Parser: decimal(p,s) type not parseable despite AST and typechecker support #29

@mjm918

Description

@mjm918

Description

NamlType::Decimal { precision, scale } exists in the AST (ast/types.rs:43) and the typechecker maps it to Type::Float (infer.rs:1778, mod.rs:831), but the parser has no branch to parse decimal(p,s) syntax. The lexer also lacks a Keyword::Decimal variant.

As a result, decimal is lexed as an identifier and falls through to parse_named_or_generic_type, causing a type mismatch error.

Steps to Reproduce

fn main() {
    var xx: decimal = 1.0;
}

Expected: Parses decimal as a type (or decimal(10,2) with precision/scale)
Actual: type mismatch: expected float, found Spur(3)

What exists

  • AST: NamlType::Decimal { precision: u8, scale: u8 } in namlc/src/ast/types.rs:43
  • Typechecker: NamlType::Decimal { .. } => Type::Float in infer.rs:1778 and mod.rs:831

What's missing

  1. Lexer: No Keyword::Decimal variant — decimal is lexed as an identifier
  2. Parser: No branch in parse_type() (parser/types.rs:21-46) to handle decimal or decimal(p,s)

Fix

  1. Add Decimal to the Keyword enum in the lexer
  2. Add a parsing branch in parse_type() for Keyword::Decimal
  3. Parse optional (precision, scale) params — e.g. decimal defaults to decimal(10,2), decimal(18,6) sets explicit precision/scale

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions