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:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user