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 return lexRoot
case unicode.IsLower(r), unicode.IsUpper(r): case unicode.IsLower(r), unicode.IsUpper(r):
l.keep(r) l.keep(r)
return lexName return lexNameOrString
default: default:
return lexErrorf("unexpected rune in lexRoot: %c", r) return lexErrorf("unexpected rune in lexRoot: %c", r)
} }
@ -238,7 +238,7 @@ func lexAfterPeriod(l *lexer) stateFn {
return lexNumber return lexNumber
case unicode.IsLower(r): case unicode.IsLower(r):
l.keep(r) l.keep(r)
return lexName return lexNameOrString
default: default:
return lexErrorf("unexpected rune after period: %c", r) 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() r := l.next()
switch { switch {
case unicode.IsLetter(r), unicode.IsDigit(r), r == '_': case r == '\n', r == ';':
l.keep(r) l.emit(t_string)
return lexName return lexRoot
case r == eof: case r == ':':
l.emit(t_name)
return nil
default:
l.emit(t_name) l.emit(t_name)
l.unread(r) l.keep(r)
l.emit(t_object_separator)
return lexRoot 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: no_value:
key: var_name key: a bare string is here
key: "string" 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_name no_value}
{t_object_separator :} {t_object_separator :}
{t_name key} {t_name key}
{t_object_separator :} {t_object_separator :}
{t_name var_name} {t_string a bare string is here}
{t_name key} {t_name key}
{t_object_separator :} {t_object_separator :}
{t_string string} {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: {} empty_object: {}
crazy_object: { crazy_object: {
key: variable key: bare string here
key_two: "string here" key_two: "quoted string here"
key_three: [1 2 3] key_three: [1 2 3]
key_four: { key_four: {
nested_one: "alright" nested_one: "alright"

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

@ -1,2 +1,7 @@
an_item: "this is the value of the item" # this was original a variable test case, but I'm changing it to be a bare
a_variable: an_item # 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: root:
assign: assign:
name: name:
an_item quoted_string
value: value:
string: string:
this is the value of the item this is a quoted string
assign: assign:
name: name:
a_variable bare_string
value: value:
variable: string:
an_item 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