Files
herolib/lib/code/codemodel/model_import.v
2024-12-25 08:40:56 +01:00

25 lines
523 B
V

module codemodel
pub struct Import {
pub mut:
mod string
types []string
}
pub fn (mut i Import) add_types(types []string) {
i.types << types.filter(it !in i.types)
}
pub fn parse_import(code_ string) Import {
code := code_.trim_space().trim_string_left('import').trim_space()
types_str := if code.contains(' ') { code.all_after(' ').trim('{}') } else { '' }
return Import{
mod: code.all_before(' ')
types: if types_str != '' {
types_str.split(',').map(it.trim_space())
} else {
[]string{}
}
}
}