@@ -9,7 +9,6 @@ import term
9
9
import rand
10
10
import time
11
11
import v.pref
12
- import v.vmod
13
12
import v.util.recompilation
14
13
import v.util.vflags
15
14
import runtime
@@ -76,136 +75,6 @@ pub fn set_vroot_folder(vroot_path string) {
76
75
os.setenv ('VCHILD' , 'true' , true )
77
76
}
78
77
79
- // resolve_vmodroot replaces all occurences of `@VMODROOT` in `str`, with an absolute path,
80
- // formed by resolving, where the nearest `v.mod` is, given the folder `dir`.
81
- pub fn resolve_vmodroot (str string , dir string ) ! string {
82
- mut mcache := vmod.get_cache ()
83
- vmod_file_location := mcache.get_by_folder (dir)
84
- if vmod_file_location.vmod_file.len == 0 {
85
- // There was no actual v.mod file found.
86
- return error ('To use @VMODROOT, you need to have a "v.mod" file in ${dir} , or in one of its parent folders.' )
87
- }
88
- vmod_path := vmod_file_location.vmod_folder
89
- return str.replace ('@VMODROOT' , os.real_path (vmod_path))
90
- }
91
-
92
- // resolve_env_value replaces all occurrences of `$env('ENV_VAR_NAME')`
93
- // in `str` with the value of the env variable `$ENV_VAR_NAME`.
94
- pub fn resolve_env_value (str string , check_for_presence bool ) ! string {
95
- env_ident := "\$ env('"
96
- at := str.index (env_ident) or {
97
- return error ('no "${env_ident} ' + '...\' )" could be found in "${str} ".' )
98
- }
99
- mut ch := u8 (`.` )
100
- mut env_lit := ''
101
- for i := at + env_ident.len; i < str.len && ch != `)` ; i++ {
102
- ch = u8 (str[i])
103
- if ch.is_letter () || ch.is_digit () || ch == `_` {
104
- env_lit + = ch.ascii_str ()
105
- } else {
106
- if ! (ch == `'` || ch == `)` ) {
107
- if ch == `$` {
108
- return error ('cannot use string interpolation in compile time \$ env() expression' )
109
- }
110
- return error ('invalid environment variable name in "${str} ", invalid character "${ch.ascii_str()} "' )
111
- }
112
- }
113
- }
114
- if env_lit == '' {
115
- return error ('supply an env variable name like HOME, PATH or USER' )
116
- }
117
- mut env_value := ''
118
- if check_for_presence {
119
- env_value = os.environ ()[env_lit] or {
120
- return error ('the environment variable "${env_lit} " does not exist.' )
121
- }
122
- if env_value == '' {
123
- return error ('the environment variable "${env_lit} " is empty.' )
124
- }
125
- } else {
126
- env_value = os.getenv (env_lit)
127
- }
128
- rep := str.replace_once (env_ident + env_lit + "'" + ')' , env_value)
129
- if rep.contains (env_ident) {
130
- return resolve_env_value (rep, check_for_presence)
131
- }
132
- return rep
133
- }
134
-
135
- const d_sig = "\$ d('"
136
-
137
- // resolve_d_value replaces all occurrences of `$d('ident','value')`
138
- // in `str` with either the default `'value'` param or a compile value passed via `-d ident=value`.
139
- pub fn resolve_d_value (compile_values map [string ]string , str string ) ! string {
140
- at := str.index (d_sig) or {
141
- return error ('no "${d_sig} ' + '...\' )" could be found in "${str} ".' )
142
- }
143
- mut all_parsed := d_sig
144
- mut ch := u8 (`.` )
145
- mut d_ident := ''
146
- mut i := 0
147
- for i = at + d_sig.len; i < str.len && ch != `'` ; i++ {
148
- ch = u8 (str[i])
149
- all_parsed + = ch.ascii_str ()
150
- if ch.is_letter () || ch.is_digit () || ch == `_` {
151
- d_ident + = ch.ascii_str ()
152
- } else {
153
- if ! (ch == `'` ) {
154
- if ch == `$` {
155
- return error ('cannot use string interpolation in compile time \$ d() expression' )
156
- }
157
- return error ('invalid `\$ d` identifier in "${str} ", invalid character "${ch.ascii_str()} "' )
158
- }
159
- }
160
- }
161
- if d_ident == '' {
162
- return error ('first argument of `\$ d` must be a string identifier' )
163
- }
164
-
165
- // at this point we should have a valid identifier in `d_ident`.
166
- // Next we parse out the default string value
167
-
168
- // advance past the `,` and the opening `'` in second argument, or ... eat whatever is there
169
- for i < str.len {
170
- ch = str[i]
171
- if ch in [` ` , `,` ] {
172
- i++
173
- all_parsed + = u8 (ch).ascii_str ()
174
- continue
175
- }
176
- if ch == `'` {
177
- i++
178
- all_parsed + = u8 (ch).ascii_str ()
179
- }
180
- break
181
- }
182
- // Rinse, repeat for the expected default value string
183
- ch = u8 (`.` )
184
- mut d_default_value := ''
185
- for ; i < str.len && ch != `'` ; i++ {
186
- ch = u8 (str[i])
187
- all_parsed + = ch.ascii_str ()
188
- if ! (ch == `'` ) {
189
- d_default_value + = ch.ascii_str ()
190
- }
191
- if ch == `$` {
192
- return error ('cannot use string interpolation in compile time \$ d() expression' )
193
- }
194
- }
195
- if d_default_value == '' {
196
- return error ('second argument of `\$ d` must be a pure literal' )
197
- }
198
- // at this point we have the identifier and the default value.
199
- // now we need to resolve which one to use from `compile_values`.
200
- d_value := compile_values[d_ident] or { d_default_value }
201
- // if more `$d()` calls remains, resolve those as well:
202
- rep := str.replace_once (all_parsed + ')' , d_value)
203
- if rep.contains (d_sig) {
204
- return resolve_d_value (compile_values, rep)
205
- }
206
- return rep
207
- }
208
-
209
78
// is_escape_sequence returns `true` if `c` is considered a valid escape sequence denoter.
210
79
@[inline]
211
80
pub fn is_escape_sequence (c u8 ) bool {
0 commit comments