Skip to content

Parse pallene types file#657

Merged
igrvlhlb merged 7 commits intomasterfrom
parse-pallene-types-file
Mar 31, 2026
Merged

Parse pallene types file#657
igrvlhlb merged 7 commits intomasterfrom
parse-pallene-types-file

Conversation

@igrvlhlb
Copy link
Copy Markdown
Contributor

@igrvlhlb igrvlhlb commented Dec 2, 2025

This pull request introduces support for Pallene type declaration files (.d.pln), allowing the compiler to parse and verify/typecheck type files in addition to regular Pallene source files. The changes include updates to the parser, typechecker, driver, CLI, and utility functions to handle the new file format, as well as new tests to verify correct parsing and type checking of type declaration files.

Type Declaration File Support

  • Added a new AST union TypeFile in src/pallene/ast.lua to represent type declaration files and their components (Typealias, Record, Decl).
  • Implemented parsing logic for .d.pln files in src/pallene/parser.lua, including the TypeDeclarationFile parser method and extension-based dispatch in the main parse function. [1] [2]
  • Extended the typechecker to handle type declaration file ASTs, adding the check_type_file method in src/pallene/typechecker.lua. [1] [2]

Compiler and CLI Integration (Extra)

  • Added a new CLI flag --emit-types to src/pallene/pallenec.lua, enabling users to generate .d.pln files, and integrated it into the main command dispatch. [1] [2]

Utilities and Testing

  • Introduced utility functions in src/pallene/util.lua to correctly split and recognize multi-part extensions like .d.pln, supporting robust file name handling.
  • Added tests for parsing and type checking type declaration files in spec/parser_spec.lua.

@igrvlhlb igrvlhlb force-pushed the parse-pallene-types-file branch from 7868a52 to c04903a Compare December 2, 2025 22:20
Comment thread src/pallene/parser.lua
else
self:unexpected_token_error("a type declaration")
end
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we encounter an invalid token, the while loop will exit and this function will return as if there was not a problem.

  1. I think the while should be "while not end-of-file"
  2. Please create test cases for the "expected a type declaration" errors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the while should be "while not end-of-file"

Should we still throw an error if we don't find at least one declaration? If so, we can go with a repeat-until

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should allow empty files, in case the module exports nothing. (Also test that...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to write the error test in a assert_program_error() fashion, but I couldn't get it to work. So I wrote it another way (src/spec/parser_spec.lua:979-990)

Comment thread src/pallene/typechecker.lua Outdated
Comment thread src/pallene/util.lua Outdated
* Fix logic in `split_ext` and remove unnecessary new functions;
* Fix `.d.pln` parsing loop that could stop before file end;
* Create a new function for `.d.pln` typechecking.
* Add tests
@igrvlhlb igrvlhlb force-pushed the parse-pallene-types-file branch from 764279d to e31345a Compare December 3, 2025 13:50
@igrvlhlb igrvlhlb requested a review from hugomg December 3, 2025 14:05
Copy link
Copy Markdown
Member

@hugomg hugomg left a comment

Choose a reason for hiding this comment

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

Acho que precisamos de funções separadas para o compile_internal e o parser.parse.

Pense em qual seria o tipo de parser.parse. Hoje é uma função que as vezes retorna um ast.Program e as vezes retorna um ast.TypeFile. Isso até dá pra escrever em Lua, que é uma linguagem dinâmica, mas não funcionaria se quisessemos converter esse código para Pallene no futuro.

Um problema semelhante acontece na compile_internal, que hoje está com um if que verifica a extensão e retorna tipos de dados diferentes dependendo do valor da extensão.

@igrvlhlb igrvlhlb merged commit ed2f7ae into master Mar 31, 2026
2 checks passed
@igrvlhlb igrvlhlb deleted the parse-pallene-types-file branch March 31, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants