Skip to content

Commit

Permalink
Allow comments to end in CRLF. Fixes #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
valderman committed Apr 26, 2022
1 parent 80a0a1b commit a5fa5e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/antlr/Toml.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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] ;
Expand Down
23 changes: 23 additions & 0 deletions src/test/kotlin/cc/ekblad/toml/parser/MiscTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,34 @@ class MiscTests : StringTest {
assertIs<InputMismatchException>(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 {
Expand Down

0 comments on commit a5fa5e5

Please sign in to comment.