chiark / gitweb /
Minor fixups
authorJeff Ober <jober@ziprecruiter.com>
Thu, 16 Jan 2020 20:09:49 +0000 (15:09 -0500)
committerJeff Ober <jober@ziprecruiter.com>
Thu, 16 Jan 2020 20:09:49 +0000 (15:09 -0500)
lib/TOML/Tiny/Grammar.pm
lib/TOML/Tiny/Tokenizer.pm

index 73c58ec59e383564407af02fab841538920e8002..1a7e23686b9fbd74f5c9741c1c7dbfc564f01b3d 100644 (file)
@@ -27,13 +27,9 @@ our $TOML = qr{
     | (?&InlineTable)
   )
 
-  (?<NLSeq> \x0D? \x0A)
-  (?<NL> (?&NLSeq) | (?&Comment))
-
-  (?<WSChar> \x20 | \x09)       # (space, tab)
-  (?<WS> (?&WSChar)*)
-
-  (?<Comment> \x23 .* (?&NLSeq)?)
+  (?<WS>   [ \x20 \x09 ]*)         # space, tab
+  (?<CRLF> \x0D? \x0A)             # cr? lf
+  (?<EOL>  (?: \x23 .*)? (?&CRLF)) # crlf or comment -> crlf
 
   #-----------------------------------------------------------------------------
   # Array of tables
@@ -42,9 +38,10 @@ our $TOML = qr{
     (?m)
     (?s)
 
-    \[\[ (?&Key) \]\] \n
+    \[\[ (?&Key) \]\] (?&EOL)
+
     (?:
-        (?: (?&KeyValuePair) (?=(?&NLSeq)) )
+        (?: (?&KeyValuePair) (?=(?&CRLF)) )
       | (?&ArrayOfTables)
       | (?&Table)
     )*
@@ -57,7 +54,7 @@ our $TOML = qr{
   # Table
   #-----------------------------------------------------------------------------
   (?<KeyValuePair> (?&Key) (?&WS) = (?&WS) (?&Value))
-  (?<KeyValuePairDecl> (?&Key) (?&WS) = (?&WS) (?&Value) (?&WS) (?&NL))
+  (?<KeyValuePairDecl> (?&Key) (?&WS) = (?&WS) (?&Value) (?&WS) (?&EOL))
 
   (?<KeyValuePairList>
       (?&KeyValuePair) (?&WS) (?: [,] (?&WS) (?&KeyValuePairList) )?
@@ -72,9 +69,7 @@ our $TOML = qr{
     }
   )
 
-  (?<TableDecl>
-    \[ (?&Key) \] \n
-  )
+  (?<TableDecl> \[ (?&Key) \] (?&EOL))
 
   (?<Table>
     (?&TableDecl)
@@ -91,7 +86,7 @@ our $TOML = qr{
     (?&WS)
     [,]
     (?&WS)
-    (?&NLSeq)?
+    (?&CRLF)?
     (?&WS)
   )
 
@@ -103,11 +98,11 @@ our $TOML = qr{
   (?<Array>
     \[
 
-    (?&WS) (?&NLSeq)? (?&WS)
+    (?&WS) (?&CRLF)? (?&WS)
 
     (?&List)
 
-    (?&WS) (?&NLSeq)? (?&WS)
+    (?&WS) (?&CRLF)? (?&WS)
 
     \]
   )
@@ -216,7 +211,7 @@ our $TOML = qr{
         [^"\\]
       | "{1,2}                # 1-2 quotation marks
       | (?&EscapeChar)        # escape
-      | (?: \\ (?&NLSeq))     # backslash-terminated line
+      | (?: \\ (?&CRLF))     # backslash-terminated line
     )*?
     """                       # closing triple-quote
   )
@@ -258,8 +253,7 @@ Exports C<$TOML>, a regex grammar for parsing TOML source.
 =head1 RULES
 
 =head2 (?&WS)
-=head2 (?&NL)
-=head2 (?&Comment)
+=head2 (?&EOL)
 
 =head2 (?&Value)
 =head3 (?&Boolean)
index 51f78bd86d2af3a4b6ea616a0b5ddb3ab524a998..8b584851f7e1e15450ccedad84e9275794bb8d23 100644 (file)
@@ -217,8 +217,8 @@ sub tokenize_string {
     $str = substr $toml, 3, length($toml) - 6;
     my @newlines = $str =~ /(\x0D?\x0A)/g;
     $self->{line} += scalar @newlines;
-    $str =~ s/^[\x20 \x09]* (?&NL) $TOML//x; # trim leading whitespace
-    $str =~ s/\\(?&NL)\s* $TOML//xgs;  # trim newlines from lines ending in backslash
+    $str =~ s/^[\x20 \x09]* (?&EOL) $TOML//x; # trim leading whitespace
+    $str =~ s/\\(?&EOL)\s* $TOML//xgs;        # trim newlines from lines ending in backslash
   } else {
     $str = substr($toml, 1, length($toml) - 2);
   }