From a5fa5e5fbed62923d9033eb95460ac60541241c0 Mon Sep 17 00:00:00 2001 From: Anton Ekblad Date: Tue, 26 Apr 2022 23:44:27 +0200 Subject: [PATCH] Allow comments to end in CRLF. Fixes #1. --- src/main/antlr/Toml.g4 | 2 +- .../kotlin/cc/ekblad/toml/parser/MiscTests.kt | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/antlr/Toml.g4 b/src/main/antlr/Toml.g4 index 82f6d26..4ecd651 100644 --- a/src/main/antlr/Toml.g4 +++ b/src/main/antlr/Toml.g4 @@ -64,7 +64,7 @@ array_table : '[' '[' key ']' ']' ; WS : [ \t]+ -> skip ; NL : ('\r'? '\n')+ ; -COMMENT : '#' (~[\n])* ; +COMMENT : '#' (~[\r\n])* ; fragment DIGIT : [0-9] ; fragment ALPHA : [A-Za-z] ; diff --git a/src/test/kotlin/cc/ekblad/toml/parser/MiscTests.kt b/src/test/kotlin/cc/ekblad/toml/parser/MiscTests.kt index 47caea1..3579029 100644 --- a/src/test/kotlin/cc/ekblad/toml/parser/MiscTests.kt +++ b/src/test/kotlin/cc/ekblad/toml/parser/MiscTests.kt @@ -147,11 +147,34 @@ class MiscTests : StringTest { assertIs(exception.cause) } + @Test + fun `key-value pair can end in CRLF`() { + assertEquals( + TomlValue.Map("foo" to TomlValue.Integer(123)), + TomlValue.from("foo = 123\r\n") + ) + } + + @Test + fun `comment can end in CRLF`() { + assertEquals( + TomlValue.Map(), + TomlValue.from("# Hello\r\n") + ) + } + @Test fun `throws on unspecified value`() { assertDocumentParseError("foo =") } + @Test + fun `throws on comment containing CR`() { + asciiControlChars.assertAll { + assertDocumentParseError("# this is \r bad") + } + } + @Test fun `throws on comment containing ASCII control char`() { asciiControlChars.assertAll {