lexing for hidden names

master
Jordan Orelli 10 years ago
parent 16f02b80ef
commit 510d560552

@ -34,3 +34,24 @@ item_one: "this is item one"
# we may reference an item that was defined earlier
item_two: item_one
# items can be hidden. i.e., they're only valid in the parse and eval stage as
# intermediate values internal to the config file; they are *not* visible to
# the host program. This is generally useful for composing larger, more
# complicated things.
.hidden_item: "it has a value"
visible_item: .hidden_item
.person_one: {
name: "the first name here"
age: 28
hometown: "crooklyn"
}
.person_two: {
name: "the second name here"
age: 30
hometown: "tha bronx"
}
people: [.person_one .person_two]

@ -110,6 +110,12 @@ func (l *lexer) next() rune {
return r
}
func (l *lexer) peek() rune {
r := l.next()
l.unread(r)
return r
}
func (l *lexer) keep(r rune) {
if l.buf == nil {
l.buf = make([]rune, 0, 18)
@ -211,7 +217,10 @@ func lexRoot(l *lexer) stateFn {
l.keep(r)
l.emit(t_object_separator)
return lexRoot
case strings.IndexRune(".+-0123456789", r) >= 0:
case r == '.':
l.keep(r)
return lexAfterPeriod
case strings.IndexRune("+-0123456789", r) >= 0:
l.unread(r)
return lexNumber
case unicode.IsSpace(r):
@ -227,6 +236,20 @@ func lexRoot(l *lexer) stateFn {
}
}
func lexAfterPeriod(l *lexer) stateFn {
r := l.next()
switch {
case strings.IndexRune("+-0123456789", r) >= 0:
l.unread(r)
return lexNumber
case unicode.IsLower(r):
l.keep(r)
return lexName
default:
return lexErrorf("unexpected rune after period: %c", r)
}
}
func lexComment(l *lexer) stateFn {
switch r := l.next(); r {
case '\n':

@ -201,6 +201,10 @@ func (n *assignmentNode) eval(ctx map[string]interface{}) (interface{}, error) {
return nil, nil
}
func (n *assignmentNode) isHidden() bool {
return strings.HasPrefix(n.name, ".")
}
type stringNode string
func (s *stringNode) Type() nodeType {
@ -442,7 +446,3 @@ func (v *variableNode) eval(ctx map[string]interface{}) (interface{}, error) {
}
return value, nil
}
func (v *variableNode) isHidden() bool {
return strings.HasPrefix(v.name, ".")
}

Loading…
Cancel
Save