Skip to content

Commit d39648b

Browse files
committed
Merge pull request #13 from koraktor/parslet-newlines
Add support for CR and CRLF newlines
2 parents 7a00092 + 43554a4 commit d39648b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/toml/parslet.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class Parslet < ::Parslet::Parser
3939
space >> key.as(:key) >>
4040
space >> str("=") >>
4141
space >> value.as(:value) >>
42-
space >> comment.maybe >> str("\n") >> all_space
42+
space >> comment.maybe >> newline >> all_space
4343
}
4444
rule(:table) {
4545
space >> str("[") >>
4646
table_name.as(:table) >>
4747
str("]") >>
48-
space >> comment.maybe >> str("\n") >> all_space
48+
space >> comment.maybe >> newline >> all_space
4949
}
5050
rule(:table_array) {
5151
space >> str("[[") >>
@@ -57,11 +57,12 @@ class Parslet < ::Parslet::Parser
5757
rule(:key) { match["^. \t\\]"].repeat(1) }
5858
rule(:table_name) { key.as(:key) >> (str(".") >> key.as(:key)).repeat }
5959

60-
rule(:comment_line) { comment >> str("\n") >> all_space }
60+
rule(:comment_line) { comment >> newline >> all_space }
6161
rule(:comment) { str("#") >> match["^\n"].repeat }
6262

6363
rule(:space) { match[" \t"].repeat }
6464
rule(:all_space) { match[" \t\r\n"].repeat }
65+
rule(:newline) { str("\r").maybe >> str("\n") | str("\r") >> str("\n").maybe }
6566

6667
rule(:string) {
6768
str('"') >> (

0 commit comments

Comments
 (0)