Skip to content

Commit

Permalink
Improves handling of odd newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-huxtable committed Apr 27, 2018
1 parent bf9a58e commit 30f596a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: config
version: 0.1.1
version: 0.1.2

authors:
- Chris Huxtable <chris@huxtable.ca>
Expand Down
5 changes: 4 additions & 1 deletion spec/config_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ describe Config::Parser do
it_parses "foo: {bar: 1}", { "foo" => {"bar" => 1} }
it_parses "foo: {bar: 1, foo: 1.5}", { "foo" => {"bar" => 1, "foo" => 1.5} }
it_parses "foo: {bar: 1\n foo: 1.5}", { "foo" => {"bar" => 1, "foo" => 1.5} }

it_parses "foo \t\n: \t\nbar", { "foo" => "bar" }
it_parses "foo:\n{\nbar: 1\n}", { "foo" => {"bar" => 1} }
end

it "parses odd entries" do
Expand Down Expand Up @@ -139,7 +142,7 @@ describe Config::Parser do
it_raises_on_parse "foo: \"unterminated string"
it_raises_on_parse "foo: "

it_raises_on_parse "foo \t\n: \t\nbar"

end

it "allows macros" do
Expand Down
15 changes: 10 additions & 5 deletions src/config/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ class Config::Parser
key = token.string_value()
is_macro = token.type?(:macro)

next_token()
next_data_token()
expect_type(:":", :"=")

is_assignment = token.type?(:"=")
next_token()
next_data_token()

if ( is_macro )
if ( is_assignment )
Expand Down Expand Up @@ -100,9 +99,9 @@ class Config::Parser
expect_type(:string)
key = token.string_value()

next_token()
next_data_token()
expect_type(:":")
next_token()
next_data_token()

object[key] = parse_value()
expect_type(:",", :"\n", :"}")
Expand Down Expand Up @@ -137,6 +136,12 @@ class Config::Parser
return value
end

private def next_data_token() : Token
token = next_token()
skip_seporators()
return token
end


# Nesting

Expand Down

0 comments on commit 30f596a

Please sign in to comment.