Conversation
7868a52 to
c04903a
Compare
| else | ||
| self:unexpected_token_error("a type declaration") | ||
| end | ||
| end |
There was a problem hiding this comment.
If we encounter an invalid token, the while loop will exit and this function will return as if there was not a problem.
- I think the while should be "while not end-of-file"
- Please create test cases for the "expected a type declaration" errors
There was a problem hiding this comment.
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
There was a problem hiding this comment.
We should allow empty files, in case the module exports nothing. (Also test that...)
There was a problem hiding this comment.
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)
* 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
764279d to
e31345a
Compare
hugomg
left a comment
There was a problem hiding this comment.
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.
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
TypeFileinsrc/pallene/ast.luato represent type declaration files and their components (Typealias,Record,Decl)..d.plnfiles insrc/pallene/parser.lua, including theTypeDeclarationFileparser method and extension-based dispatch in the main parse function. [1] [2]check_type_filemethod insrc/pallene/typechecker.lua. [1] [2]Compiler and CLI Integration (Extra)
--emit-typestosrc/pallene/pallenec.lua, enabling users to generate.d.plnfiles, and integrated it into the main command dispatch. [1] [2]Utilities and Testing
src/pallene/util.luato correctly split and recognize multi-part extensions like.d.pln, supporting robust file name handling.spec/parser_spec.lua.