|
23 | 23 | folder string // the folder in which the repl will write its temporary source files |
24 | 24 | last_output string // the last repl output |
25 | 25 |
|
26 | | - modules []string // all the import modules |
27 | | - alias map[string]string // all the alias used in the import |
28 | | - includes []string // all the #include statements |
29 | | - functions []string // all the user function declarations |
30 | | - functions_name []string // all the user function names |
31 | | - structs []string // all the struct definitions |
32 | | - enums []string // all the enum definitions |
33 | | - consts []string // all the const definitions |
34 | | - types []string // all the type definitions |
35 | | - interfaces []string // all the interface definitions |
36 | | - lines []string // all the other lines/statements |
37 | | - temp_lines []string // all the temporary expressions/printlns |
38 | | - vstartup_lines []string // lines in the `VSTARTUP` file |
39 | | - eval_func_lines []string // same line of the `VSTARTUP` file, but used to test fn type |
| 26 | + modules map[string][]string // all the import modules |
| 27 | + alias map[string]string // all the alias used in the import |
| 28 | + includes []string // all the #include statements |
| 29 | + functions []string // all the user function declarations |
| 30 | + functions_name []string // all the user function names |
| 31 | + structs []string // all the struct definitions |
| 32 | + enums []string // all the enum definitions |
| 33 | + consts []string // all the const definitions |
| 34 | + types []string // all the type definitions |
| 35 | + interfaces []string // all the interface definitions |
| 36 | + lines []string // all the other lines/statements |
| 37 | + temp_lines []string // all the temporary expressions/printlns |
| 38 | + vstartup_lines []string // lines in the `VSTARTUP` file |
| 39 | + eval_func_lines []string // same line of the `VSTARTUP` file, but used to test fn type |
40 | 40 | } |
41 | 41 |
|
42 | 42 | const is_stdin_a_pipe = os.is_atty(0) == 0 |
@@ -91,7 +91,11 @@ fn new_repl(folder string) Repl { |
91 | 91 | skip_empty: true |
92 | 92 | } |
93 | 93 | folder: folder |
94 | | - modules: ['os', 'time', 'math'] |
| 94 | + modules: { |
| 95 | + 'os': [] |
| 96 | + 'time': [] |
| 97 | + 'math': [] |
| 98 | + } |
95 | 99 | vstartup_lines: vstartup_source |
96 | 100 | // Test file used to check if a function as a void return or a value return. |
97 | 101 | eval_func_lines: vstartup_source |
@@ -205,11 +209,18 @@ fn (r &Repl) is_function_call(line string) bool { |
205 | 209 | // to a sequence of V source code lines |
206 | 210 | fn (r &Repl) import_to_source_code() []string { |
207 | 211 | mut imports_line := []string{} |
208 | | - for mod in r.modules { |
| 212 | + for mod, value in r.modules { |
209 | 213 | mut import_str := 'import ${mod}' |
210 | 214 | if mod in r.alias { |
211 | 215 | import_str += ' as ${r.alias[mod]}' |
212 | 216 | } |
| 217 | + if value.len > 0 { |
| 218 | + import_str += '{ ' |
| 219 | + for val in value { |
| 220 | + import_str += '${val}, ' |
| 221 | + } |
| 222 | + import_str += '}' |
| 223 | + } |
213 | 224 | imports_line << endline_if_missed(import_str) |
214 | 225 | } |
215 | 226 | return imports_line |
@@ -312,17 +323,25 @@ fn (mut r Repl) parse_import(line string) { |
312 | 323 | tokens := r.line.fields() |
313 | 324 | // module name |
314 | 325 | mod := tokens[1] |
315 | | - if mod !in r.modules { |
316 | | - r.modules << mod |
317 | | - } |
318 | | - // Check if the import contains an alias |
319 | | - // import mod_name as alias_mod |
| 326 | + // set alias |
320 | 327 | if line.contains('as ') && tokens.len >= 4 { |
321 | 328 | alias := tokens[3] |
322 | 329 | if mod !in r.alias { |
323 | 330 | r.alias[mod] = alias |
324 | 331 | } |
325 | 332 | } |
| 333 | + |
| 334 | + // set value |
| 335 | + if line.contains('{') && line.contains('}') { |
| 336 | + values := line.split('{')[1].split('}')[0] |
| 337 | + for value in values.split(',') { |
| 338 | + r.modules[mod] << value |
| 339 | + } |
| 340 | + } else { |
| 341 | + if mod !in r.modules { |
| 342 | + r.modules[mod] = []string{} |
| 343 | + } |
| 344 | + } |
326 | 345 | } |
327 | 346 |
|
328 | 347 | // clear the screen, then list source code |
|
0 commit comments