[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 3/4] pkl, testsuite, doc: Allow trailing comma in struct lite
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH 3/4] pkl, testsuite, doc: Allow trailing comma in struct literals |
Date: |
Wed, 26 Feb 2020 10:55:10 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Hi Eric.
* src/pkl-tab.y (opt_comma): New rule.
(array): Use it to simplify trailing comma in arrays.
(struct, expression): Allow trailing comma in struct literals.
* doc/poke.texi (Struct Literals): Document it.
* testsuite/poke.pkl/structs-5.pk: Test it.
* etc/poke.g4 (array, struct): Match the real grammar.
This is OK for master.
Thanks!
---
ChangeLog | 9 +++++++++
doc/poke.texi | 3 ++-
etc/poke.g4 | 11 ++++++++---
src/pkl-tab.y | 19 ++++++++-----------
testsuite/poke.pkl/structs-5.pk | 4 ++++
5 files changed, 31 insertions(+), 15 deletions(-)
create mode 100644 testsuite/poke.pkl/structs-5.pk
diff --git a/ChangeLog b/ChangeLog
index 1323835d..fa8bb600 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2020-02-25 Eric Blake <address@hidden>
+
+ * src/pkl-tab.y (opt_comma): New rule.
+ (array): Use it to simplify trailing comma in arrays.
+ (struct, expression): Allow trailing comma in struct literals.
+ * doc/poke.texi (Struct Literals): Document it.
+ * testsuite/poke.pkl/structs-5.pk: Test it.
+ * etc/poke.g4 (array, struct): Match the real grammar.
+
2020-02-25 Eric Blake <address@hidden>
maint: Fix syntax-check
diff --git a/doc/poke.texi b/doc/poke.texi
index 5b729262..6951db15 100644
--- a/doc/poke.texi
+++ b/doc/poke.texi
@@ -2389,7 +2389,8 @@ Struct Literals
The contents of the struct literal is a possibly empty set of fields.
Each field has an optional name @var{field_name} and a value
-@var{exp}. The expression for the value can be of any type.
+@var{exp}. The expression for the value can be of any type. For
+convenience, a trailing comma is accepted but not required.
@c XXX document struct constructors once they are supported.
diff --git a/etc/poke.g4 b/etc/poke.g4
index 23cd046d..3aebbecb 100644
--- a/etc/poke.g4
+++ b/etc/poke.g4
@@ -113,7 +113,7 @@ expression:
| expression 'in' expression
| expression 'as' simple_type_specifier
| expression 'isa' simple_type_specifier
- | TYPENAME '{' struct_field_list '}'
+ | TYPENAME '{' struct_field_list opt_comma '}'
| UNIT
| expression UNIT
| struct
@@ -161,8 +161,13 @@ funcall_arg:
expression
;
+opt_comma:
+ /* Empty */
+ | ','
+ ;
+
struct:
- 'struct' '{' struct_field_list '}'
+ 'struct' '{' struct_field_list opt_comma '}'
;
struct_field_list:
@@ -177,7 +182,7 @@ struct_field:
;
array:
- '[' array_initializer_list ']'
+ '[' array_initializer_list opt_comma ']'
;
array_initializer_list:
diff --git a/src/pkl-tab.y b/src/pkl-tab.y
index d06500d7..cf63b3b7 100644
--- a/src/pkl-tab.y
+++ b/src/pkl-tab.y
@@ -724,7 +724,7 @@ expression:
$1, $3, $5);
PKL_AST_LOC ($$) = @$;
}
- | TYPENAME '{' struct_field_list '}'
+ | TYPENAME '{' struct_field_list opt_comma '}'
{
pkl_ast_node type;
pkl_ast_node astruct;
@@ -929,8 +929,13 @@ funcall_arg:
}
;
+opt_comma:
+ %empty
+ | ','
+ ;
+
struct:
- STRUCT '{' struct_field_list '}'
+ STRUCT '{' struct_field_list opt_comma '}'
{
$$ = pkl_ast_make_struct (pkl_parser->ast,
0 /* nelem */, $3);
@@ -967,15 +972,7 @@ struct_field:
;
array:
- '[' array_initializer_list ']'
- {
- $$ = pkl_ast_make_array (pkl_parser->ast,
- 0 /* nelem */,
- 0 /* ninitializer */,
- $2);
- PKL_AST_LOC ($$) = @$;
- }
- | '[' array_initializer_list ',' ']'
+ '[' array_initializer_list opt_comma ']'
{
$$ = pkl_ast_make_array (pkl_parser->ast,
0 /* nelem */,
diff --git a/testsuite/poke.pkl/structs-5.pk
b/testsuite/poke.pkl/structs-5.pk
new file mode 100644
index 00000000..fdf73424
--- /dev/null
+++ b/testsuite/poke.pkl/structs-5.pk
@@ -0,0 +1,4 @@
+/* { dg-do run } */
+
+/* { dg-command { struct { 1, 2, } } } */
+/* { dg-output "struct {1,2}" } */
- [PATCH 0/4] vaious build patches, Eric Blake, 2020/02/25
- [PATCH 3/4] pkl, testsuite, doc: Allow trailing comma in struct literals, Eric Blake, 2020/02/25
- Re: [PATCH 3/4] pkl, testsuite, doc: Allow trailing comma in struct literals,
Jose E. Marchesi <=
- [PATCH 2/4] maint: Fix syntax-check, Eric Blake, 2020/02/25
- [PATCH 4/4] maint: Ignore even more testsuite leftovers, Eric Blake, 2020/02/25
- [PATCH 1/4] maint: Saner diff output, Eric Blake, 2020/02/25