chiark / gitweb /
Apparently inline tables are forbidden to have newlines in them. Who knew?
authorJeff Ober <jober@ziprecruiter.com>
Fri, 10 Jan 2020 18:36:14 +0000 (13:36 -0500)
committerJeff Ober <jober@ziprecruiter.com>
Fri, 10 Jan 2020 18:36:14 +0000 (13:36 -0500)
lib/TOML/Tiny/Grammar.pm
lib/TOML/Tiny/Parser.pm
lib/TOML/Tiny/Tokenizer.pm

index 03fc43c0ed64f7e61f11ccd5972342fc41185d35..784b53a70024e5c3639cd3bec42a165eb59df486 100644 (file)
@@ -58,16 +58,8 @@ our $TOML = qr{
   (?<KeyValuePair> (?&Key) (?&WS) = (?&WS) (?&Value))
   (?<KeyValuePairDecl> (?&Key) (?&WS) = (?&WS) (?&Value) (?&WS) (?&NL))
 
-  (?<InlineTableSep>
-    (?&WS)
-    [,]
-    (?&WS)
-    (?&NLSeq)?
-    (?&WS)
-  )
-
   (?<KeyValuePairList>
-      (?&KeyValuePair) (?&InlineTableSep) (?&KeyValuePairList)?
+      (?&KeyValuePair) (?&WS) [,] (?&WS) (?&KeyValuePairList)?
     | (?&KeyValuePair)
   )
 
index ff2f753039737f5cab0f5a90e181262ff243a711..daf83c513d97e0f723e082556823098f5d2ee9f9 100644 (file)
@@ -33,7 +33,8 @@ sub new {
 sub next_token {
   my $self = shift;
   return unless $self->{tokenizer};
-  $self->{tokenizer}->next_token;
+  my $token = $self->{tokenizer}->next_token;
+  return $token;
 }
 
 sub parse {
@@ -85,7 +86,7 @@ $src
 
 sub expect_type {
   my ($self, $token, $expected) = @_;
-  my $actual = $token->type;
+  my $actual = eval{ $token->type }; use Carp; confess $@ if $@;
   $self->parse_error($token, "expected $expected, but found $actual")
     unless $actual eq $expected;
 }
@@ -144,16 +145,23 @@ sub parse_table {
   my $token = shift // $self->next_token;
   $self->expect_type($token, 'table');
   $self->push_keys($token);
-
-  my $node = $self->scan_to_key([$self->get_keys]);
+  $self->scan_to_key([$self->get_keys]);
 
   TOKEN: while (my $token = $self->next_token) {
     for ($token->type) {
+      next TOKEN when /EOL/;
+
       when (/key/) {
         $self->expect_type($self->next_token, 'assign');
         $self->push_keys($token);
         $self->set_keys;
         $self->pop_keys;
+
+        if (my $eol = $self->next_token) {
+          $self->expect_type($eol, 'EOL');
+        } else {
+          return;
+        }
       }
 
       when (/array_table/) {
@@ -189,6 +197,8 @@ sub parse_array_table {
 
   TOKEN: while (my $token = $self->next_token) {
     for ($token->type) {
+      next TOKEN when /EOL/;
+
       when (/key/) {
         $self->expect_type($self->next_token, 'assign');
         $self->push_keys($token);
@@ -282,6 +292,7 @@ sub parse_inline_array {
   TOKEN: while (my $token = $self->next_token) {
     for ($token->type) {
       next TOKEN when /comma/;
+      next TOKEN when /EOL/;
       last TOKEN when /inline_array_close/;
 
       default{
index 46c9a0695af7d24724f7721abb979a3155044912..60b1b5c8b128667fdacf1f27e41b336273cc8ecf 100644 (file)
@@ -56,6 +56,7 @@ sub next_token {
     for ($self->{source}) {
       when (/\G (?&NL) $TOML/xgc) {
         ++$self->{line};
+        $token = $self->_make_token('EOL');
       }
 
       when (/\G (?&WSChar)+ $TOML/xgc) {