mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parsing: fixed compound assignment operator bug on for loops
This commit is contained in:
parent
ef737c5e61
commit
c1400f725f
@ -128,16 +128,17 @@ fn (s mut Scanner) skip_whitespace() {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (s mut Scanner) get_until_start(pos int) string {
|
fn (s mut Scanner) get_var_name(pos int) string {
|
||||||
mut pos_start = pos
|
mut pos_start = pos
|
||||||
for ; pos_start >= 0 && s.text[pos_start] != `\n`; pos_start-- {}
|
|
||||||
for ; pos_start < pos && (s.text[pos_start] == ` ` || s.text[pos_start] == `\n`); pos_start++ {}
|
for ; pos_start >= 0 && s.text[pos_start] != `\n` && s.text[pos_start] != `;`; pos_start-- {}
|
||||||
|
pos_start++
|
||||||
return s.text.substr(pos_start, pos)
|
return s.text.substr(pos_start, pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CAO stands for Compound Assignment Operators (e.g '+=' )
|
// CAO stands for Compound Assignment Operators (e.g '+=' )
|
||||||
fn (s mut Scanner) cao_change(operator string) {
|
fn (s mut Scanner) cao_change(operator string) {
|
||||||
s.text = s.text.substr(0, s.pos - 2) + ' = ' + s.get_until_start(s.pos - 2) + ' ' + operator + s.text.substr(s.pos + 1, s.text.len)
|
s.text = s.text.substr(0, s.pos - 1) + ' = ' + s.get_var_name(s.pos - 1) + ' ' + operator + ' ' + s.text.substr(s.pos + 1, s.text.len)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (s mut Scanner) scan() ScanRes {
|
fn (s mut Scanner) scan() ScanRes {
|
||||||
|
Loading…
Reference in New Issue
Block a user