refactor: Improve const and param parsing logic

- Strip 'const ' prefix from const name
- Handle empty string for void param return type
- Handle empty split for void param return type
- Rename test functions to check functions
- Add `!` to functions that can return errors
This commit is contained in:
Mahmoud-Emad
2025-11-26 10:49:27 +02:00
parent a6d746319c
commit deca6387f2
3 changed files with 34 additions and 17 deletions

View File

@@ -11,8 +11,13 @@ pub fn parse_const(code_ string) !Const {
if !code.contains('=') {
return error('code <${code_}> is not of const')
}
mut name := code.split('=')[0].trim_space()
// Strip 'const ' prefix if present
if name.starts_with('const ') {
name = name.trim_string_left('const ').trim_space()
}
return Const{
name: code.split('=')[0].trim_space()
name: name
value: code.split('=')[1].trim_space()
}
}