@@ -29,17 +29,20 @@ def process_lines(str)
2929 # set groups
3030 str . gsub! /"groups" \( .*\s *s\( \s *any\s *\) \s *\) / , <<-EOS . strip
3131 "groups" arg ( /* Configuration groups */
32- "when" ( /* Specify additional conditions for groups */
33- c(
34- "chassis" arg /* Chassis id */,
35- "member" arg /* Member of virtual chassis */,
36- "model" arg /* Model name */,
37- "node" arg /* Node of cluster */,
38- "peers" arg /* Hosts on which this group should be effective */,
39- "routing-engine" arg /* Routing Engine */,
40- "time" ( /* Time at which group should be effective */
41- "to" arg /* End time([yyyy-mm-dd.]hh:mm) */,
42- arg
32+ c(
33+ this.configuration({ groups: false }),
34+ "when" ( /* Specify additional conditions for groups */
35+ c(
36+ "chassis" arg /* Chassis id */,
37+ "member" arg /* Member of virtual chassis */,
38+ "model" arg /* Model name */,
39+ "node" arg /* Node of cluster */,
40+ "peers" arg /* Hosts on which this group should be effective */,
41+ "routing-engine" arg /* Routing Engine */,
42+ "time" ( /* Time at which group should be effective */
43+ "to" arg /* End time([yyyy-mm-dd.]hh:mm) */,
44+ arg
45+ )
4346 )
4447 )
4548 )
@@ -91,8 +94,8 @@ def remove_undefined_variables(str)
9194 end
9295
9396 def process_common_syntax ( str )
94- # rule(:foo) do -> foo(...args ) {
95- str . gsub! ( /^rule\( :(\S +)\) do/ ) { "#$1(...args ) { return_next_line" }
97+ # rule(:foo) do -> foo(opts ) {
98+ str . gsub! ( /^rule\( :(\S +)\) do/ ) { "#$1(opts ) { return_next_line" }
9699 # end -> }
97100 str . gsub! ( /^(\s *)end$/ ) { "#$1}" }
98101
@@ -167,12 +170,12 @@ def process_argument_syntax(str)
167170 end
168171
169172 def process_structural_syntax ( str )
170- # "foo" ( /* doc */ -> "foo | doc": (...args ) => {
173+ # "foo" ( /* doc */ -> "foo | doc": (opts ) => {
171174 str . gsub! ( %r|^(\s *)"(\S +)" \( /\* (.*) \* /| ) { "#$1\" #$2 | #$3\" : {" }
172- # "foo" ( -> "foo": (...args ) => {
175+ # "foo" ( -> "foo": (opts ) => {
173176 str . gsub! ( %r|^(\s *)"(\S +)" \( $| ) { "#$1\" #$2\" : {" }
174177
175- # "foo" arg ( /* doc */ -> "foo | doc": (...args ) => {
178+ # "foo" arg ( /* doc */ -> "foo | doc": (opts ) => {
176179 str . gsub! ( %r|^(\s *)"(\S +)" arg \( /\* (.*) \* /| ) { "#$1\" #$2 | #$3\" : {" }
177180
178181 str
@@ -286,6 +289,8 @@ def finalize(lines)
286289
287290 # "arg" -> "arg_1"
288291 lines . gsub ( '"arg":' ) { %["arg_#{ sequence } ":] }
292+
293+ conditional_groups ( lines )
289294 end
290295
291296 # } -> )
@@ -349,6 +354,17 @@ def objectize_arg_of_s(lines)
349354 lines
350355 end
351356
357+ def conditional_groups ( lines )
358+ # "null_13264": this.configuration(false),
359+ # ->
360+ # (opts === undefined || opts?.configuration !== false) && { "null_13264": this.configuration(false) },
361+ #
362+ # ref: process_lines()
363+ lines . gsub ( /("groups\( arg\) \| .*":) {/ ) {
364+ "#{ $1} opts?.groups !== false && {"
365+ }
366+ end
367+
352368 def rule_header
353369 <<~EOS
354370 /* eslint-disable semi */
0 commit comments