Variable references belonging to the parent scope added ('@')

This commit is contained in:
2024-04-04 12:54:26 +02:00
parent 8c3254a8f2
commit d073d11ad3
8 changed files with 94 additions and 36 deletions
+12 -1
View File
@@ -7,6 +7,7 @@ package expr
import (
"bufio"
"errors"
"fmt"
"io"
"strconv"
"strings"
@@ -190,7 +191,17 @@ func (self *scanner) fetchNextToken() (tk *Token) {
case '#':
tk = self.makeToken(SymHash, ch)
case '@':
tk = self.makeToken(SymAt, ch)
if next, _ := self.peek(); (next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z') {
self.readChar()
if tk = self.fetchIdentifier(next); tk.Sym == SymIdentifier {
//tk.Sym = SymIdRef
tk.source = "@" + tk.source
} else {
tk = self.makeErrorToken(fmt.Errorf("invalid variable reference %q", tk.source))
}
} else {
tk = self.makeToken(SymAt, ch)
}
case '_':
tk = self.makeToken(SymUndescore, ch)
case '=':