1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-19 19:55:30 +08:00
otto/parser/scope.go
Steven Hartland 026a1d9a9c
chore: lint and naming refactor (#475)
Enable more linters, address the issues and do a major naming refactor
to use golang lower camelCase identifiers for types, functions, methods
and variable names.

Also: 
* Clean up inline generation so it doesn't rely on temporary variables.
* Remove unused functions generated by inline.pl.
2022-12-04 21:49:38 +00:00

45 lines
802 B
Go

package parser
import (
"github.com/robertkrimen/otto/ast"
)
type scope struct {
outer *scope
allowIn bool
inIteration bool
inSwitch bool
inFunction bool
declarationList []ast.Declaration
labels []string
}
func (p *_parser) openScope() {
p.scope = &scope{
outer: p.scope,
allowIn: true,
}
}
func (p *_parser) closeScope() {
p.scope = p.scope.outer
}
func (p *scope) declare(declaration ast.Declaration) {
p.declarationList = append(p.declarationList, declaration)
}
func (p *scope) hasLabel(name string) bool {
for _, label := range p.labels {
if label == name {
return true
}
}
if p.outer != nil && !p.inFunction {
// Crossing a function boundary to look for a label is verboten
return p.outer.hasLabel(name)
}
return false
}