3 ms·
# line 36 text.split("#").first This will have trouble with a line like: tweet = "TOML is #awesomesauce" -- # line 43 array = $1.split(",").
by SeoxyS 14y ago
# line 36
text.split("#").first
This will have trouble with a line like:
tweet = "TOML is #awesomesauce"
--
# line 43
array = $1.split(",").map {|s| s.strip.gsub(/\"(.*)\"/, '\1')}
You should recurse into coerce here, or you'll just lose types. (Also you're assuming arrays of strings.)
array = $1.split(",").map {|s| coerce(s) }
--
You're also not dealing with nested key groups. (eg. [servers.alpha]).
--
That being said, naïve string parsing is a terrible way to build a new markup language implementation. It's the reason the Markdown landscape is such a mess[1]. What this really needed is a formal grammar.
[1]: I actually tried to fixed that by writing a formal lexer & informal parser for Markdown in a side-project of mine[2]. It's not quite there yet, because for practicality reasons I wrote my own parser instead of a formal AST-generating parser.
https://gist.github.com/kballenegger/29dabe4b6e762ee221df https://gist.github.com/kballenegger/29dabe4b6e762ee221df
[2]: http://getmacchiato.com http://getmacchiato.com
- jeremymcanally 14y agoYup array handling is weak. I was going to recurse into coerce, but then the examples made it seem like only strings will be accepted in arrays (he put "8000" in there rather than just 8000). I'll get clarification. Made it into a proper project/gem here if you want to file issues: https://github.com/jm/toml https://github.com/jm/toml And good call on the nested key groups. Shouldn't be hard to knock that out.