Skip to content

Conversation

WilliamRagstad
Copy link
Member

This pull request introduces several significant changes across different parts of the codebase, focusing on improving functionality, simplifying structures, and removing unused features. The most notable updates include enhancements to the lexer and parser, updates to the type system, and changes to operator handling.

Lexer Improvements:

  • Added a new method is_eof_error to the LexerError class to identify end-of-file errors more efficiently. (core/src/lexer/error.rs)
  • Modified peek_token_not in the Lexer to support skipping a specified number of tokens, with optimizations for EOF handling. (core/src/lexer/lexer.rs)
  • Removed the let keyword from the lexer and associated tests, simplifying the token set. (core/src/lexer/lexer.rs, core/src/lexer/tests.rs, core/src/lexer/token.rs) [1] [2] [3]

Parser Enhancements:

  • Introduced a new LiteralType variant to the Ast enum, allowing the representation of literal type expressions. (core/src/parser/ast.rs) [1] [2] [3]
  • Added support for parse-time operators (ParseOperatorHandler) to the operator system, enabling macro-like behavior during parsing. (core/src/parser/op.rs) [1] [2] [3]
  • Updated the Parser to manage a set of known types (types) and enhanced operator handling to include the new parse-time operators. (core/src/parser/parser.rs) [1] [2]

Type System Updates:

  • Refactored TypeAst::Identifier to use a struct-like variant with named fields and added a new Constructor variant for type constructors. (core/src/parser/ast.rs)

Interpreter Changes:

  • Updated the interpreter to handle the new LiteralType in CheckedAst. (core/src/interpreter/eval.rs)
  • Replaced CheckedAst::Identifier with CheckedBindPattern::Variable in assignment handling, aligning with type-checking changes. (core/src/interpreter/eval.rs, core/src/interpreter/tests.rs) [1] [2]

Miscellaneous:

  • Removed the unused is_static field from OperatorInfo, simplifying operator metadata. (core/src/parser/op.rs)
  • Improved error handling in the lexer by adding a fallback for unknown operators. (core/src/lexer/lexer.rs)

@WilliamRagstad WilliamRagstad requested a review from Copilot May 11, 2025 12:33
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR aims to improve the language’s type system and variable assignment by introducing literal type expressions and typed variable assignments, while also refactoring operator handling to support parse-time operators. Key changes include enhancements to the lexer and parser to handle new type expression constructs, adjustments in the type checker for literal types and assignments, and updates to several tests and operator definitions.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
core/src/type_checker/checker.rs Updated type expression checking and assignment handling.
core/src/type_checker/checked_ast.rs Added support for literal type AST nodes and bind patterns.
core/src/stdlib/init.rs Modified operator initialization and type registration.
core/src/parser/parser.rs Extended parsing to support typed definitions and type constructors.
core/src/parser/op.rs Added new constructor for parse-time operators.
core/src/lexer/* Removed the 'let' keyword and updated token peeking logic.
core/src/interpreter/* Adjustments to assignment evaluation and environment management.
Comments suppressed due to low confidence (2)

core/src/type_checker/checked_ast.rs:475

  • [nitpick] Relying on panic when retrieving line info for a wildcard pattern may reduce error resilience. Consider returning an Option<&LineInfo> or a default value instead.
CheckedBindPattern::Wildcard => panic!("Wildcard pattern has no line info"),

core/src/interpreter/env.rs:151

  • [nitpick] Ensure that the error output here clearly communicates that redeclaration of a variable is not allowed, and consider aligning the error messaging style with other parts of the codebase.
).with_label("This is defined somewhere else".to_string(), info.clone()))

Copy link

trag-bot bot commented May 11, 2025

Pull request summary

  • Added a new error label for variable redefinition in the environment to provide clearer feedback.
  • Introduced CheckedBindPattern to represent variable binding patterns, enhancing the type-checking process for assignments.
  • Updated the eval_expr function to handle CheckedBindPattern for assignment targets, improving the evaluation of variable assignments.
  • Enhanced the lexer to support skipping tokens while peeking, allowing for more flexible parsing of expressions.
  • Implemented a new LiteralType AST node to represent type literals directly in the syntax tree.
  • Modified the parser to recognize and handle type annotations in variable assignments, enabling typed definitions.
  • Updated the type checker to validate type annotations against assigned expressions, ensuring type safety.
  • Refactored operator handling to distinguish between static and parse-time operators, improving operator management.
  • Adjusted test cases to cover new features, including typed assignments and literal types, ensuring comprehensive test coverage.
  • Cleaned up unused code and comments, improving overall code readability and maintainability.

@WilliamRagstad WilliamRagstad linked an issue May 11, 2025 that may be closed by this pull request
@WilliamRagstad WilliamRagstad merged commit b2bf294 into main May 11, 2025
1 of 2 checks passed
@WilliamRagstad WilliamRagstad deleted the let branch May 11, 2025 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Function definitions
1 participant