supper bare strings, break variables

this is a HUGE change to the syntax, but I'm really excited about it!
It was @avleen that convinced me this was worth looking into.
master
Jordan Orelli 10 years ago
parent bdf11713ea
commit 9591212531

@ -224,7 +224,7 @@ func lexRoot(l *lexer) stateFn {
return lexRoot
case unicode.IsLower(r), unicode.IsUpper(r):
l.keep(r)
return lexName
return lexNameOrString
default:
return lexErrorf("unexpected rune in lexRoot: %c", r)
}
@ -238,7 +238,7 @@ func lexAfterPeriod(l *lexer) stateFn {
return lexNumber
case unicode.IsLower(r):
l.keep(r)
return lexName
return lexNameOrString
default:
return lexErrorf("unexpected rune after period: %c", r)
}
@ -281,19 +281,29 @@ func lexQuotedString(delim rune) stateFn {
}
}
func lexName(l *lexer) stateFn {
func lexNameOrString(l *lexer) stateFn {
r := l.next()
switch {
case unicode.IsLetter(r), unicode.IsDigit(r), r == '_':
l.keep(r)
return lexName
case r == eof:
l.emit(t_name)
return nil
default:
case r == '\n', r == ';':
l.emit(t_string)
return lexRoot
case r == ':':
l.emit(t_name)
l.unread(r)
l.keep(r)
l.emit(t_object_separator)
return lexRoot
case r == '\\':
rr := l.next()
if rr == eof {
return lexErrorf("unexpected eof in string or name")
}
l.keep(rr)
return lexNameOrString
case r == '#':
return lexComment
default:
l.keep(r)
return lexNameOrString
}
}

@ -1,8 +1,10 @@
errant_name
this whole line is one string value, y'all!
no_value:
key: var_name
key: a bare string is here
key: "string"
one: the first string; two: the second string

@ -1,9 +1,15 @@
{t_name errant_name}
{t_string this whole line is one string value, y'all!}
{t_name no_value}
{t_object_separator :}
{t_name key}
{t_object_separator :}
{t_name var_name}
{t_string a bare string is here}
{t_name key}
{t_object_separator :}
{t_string string}
{t_name one}
{t_object_separator :}
{t_string the first string}
{t_name two}
{t_object_separator :}
{t_string the second string}

@ -1,8 +1,8 @@
empty_object: {}
crazy_object: {
key: variable
key_two: "string here"
key: bare string here
key_two: "quoted string here"
key_three: [1 2 3]
key_four: {
nested_one: "alright"

@ -7,10 +7,10 @@
{t_object_start {}
{t_name key}
{t_object_separator :}
{t_name variable}
{t_string bare string here}
{t_name key_two}
{t_object_separator :}
{t_string string here}
{t_string quoted string here}
{t_name key_three}
{t_object_separator :}
{t_list_start [}

@ -1,2 +1,7 @@
an_item: "this is the value of the item"
a_variable: an_item
# this was original a variable test case, but I'm changing it to be a bare
# string / quoted string test. The variable test will come after; variables
# are broken right now.
quoted_string: "this is a quoted string"
bare_string: this is a bare string
name with space: that name has spaces in it, and you know what? that's ok!

@ -1,13 +1,19 @@
root:
assign:
name:
an_item
quoted_string
value:
string:
this is the value of the item
this is a quoted string
assign:
name:
a_variable
bare_string
value:
variable:
an_item
string:
this is a bare string
assign:
name:
name with space
value:
string:
that name has spaces in it, and you know what? that's ok!

Loading…
Cancel
Save