@@ -72,8 +72,7 @@ def check_stag_with_instance(
7272const_string_stag_grammar = [
7373 (
7474 {"type" : "const_string" , "value" : "Hello!" },
75- r"""const_string ::= (("Hello!"))
76- root ::= ((const_string))
75+ r"""root ::= (("Hello!"))
7776""" ,
7877 )
7978]
@@ -178,8 +177,7 @@ def test_qwen_parameter_xml_format(
178177 {"type" : "json_schema" , "json_schema" : {"type" : "number" }},
179178 ],
180179 },
181- r"""const_string ::= (("Hello!"))
182- basic_number ::= ((basic_number_7 basic_number_3 basic_number_6))
180+ r"""basic_number ::= ((basic_number_7 basic_number_3 basic_number_6))
183181root ::= ((basic_number))
184182basic_number_1 ::= ("" | ("-")) (=([1-9] [0-9]*))
185183basic_number_2 ::= (([0-9] basic_number_2) | ([0-9]))
@@ -188,7 +186,7 @@ def test_qwen_parameter_xml_format(
188186basic_number_5 ::= (([0-9] basic_number_5) | ([0-9]))
189187basic_number_6 ::= ("" | ([eE] basic_number_4 basic_number_5))
190188basic_number_7 ::= (("0") | (basic_number_1 [1-9] [0-9]*)) (=(basic_number_3 basic_number_6))
191- sequence ::= ((const_string root))
189+ sequence ::= (("Hello!" root))
192190root_1 ::= ((sequence))
193191""" ,
194192 )
@@ -222,8 +220,7 @@ def test_sequence_format(
222220 {"type" : "json_schema" , "json_schema" : {"type" : "number" }},
223221 ],
224222 },
225- r"""const_string ::= (("Hello!"))
226- basic_number ::= ((basic_number_7 basic_number_3 basic_number_6))
223+ r"""basic_number ::= ((basic_number_7 basic_number_3 basic_number_6))
227224root ::= ((basic_number))
228225basic_number_1 ::= ("" | ("-")) (=([1-9] [0-9]*))
229226basic_number_2 ::= (([0-9] basic_number_2) | ([0-9]))
@@ -232,7 +229,7 @@ def test_sequence_format(
232229basic_number_5 ::= (([0-9] basic_number_5) | ([0-9]))
233230basic_number_6 ::= ("" | ([eE] basic_number_4 basic_number_5))
234231basic_number_7 ::= (("0") | (basic_number_1 [1-9] [0-9]*)) (=(basic_number_3 basic_number_6))
235- or ::= ((const_string ) | (root))
232+ or ::= (("Hello!" ) | (root))
236233root_1 ::= ((or))
237234""" ,
238235 )
@@ -266,7 +263,7 @@ def test_or_format(
266263 "end" : "END" ,
267264 },
268265 r"""basic_number ::= ((basic_number_7 basic_number_3 basic_number_6))
269- root ::= ((basic_number))
266+ root ::= ((basic_number)) (=("END"))
270267basic_number_1 ::= ("" | ("-")) (=([1-9] [0-9]*))
271268basic_number_2 ::= (([0-9] basic_number_2) | ([0-9]))
272269basic_number_3 ::= ("" | ("." basic_number_2)) (=(basic_number_6))
@@ -334,8 +331,7 @@ def test_any_text_format(
334331any_text_only_stag_grammar = [
335332 (
336333 {"type" : "any_text" },
337- r"""any_text ::= (([\0-\U0010ffff]*))
338- root ::= ((any_text))
334+ r"""root ::= (([\0-\U0010ffff]*))
339335""" ,
340336 )
341337]
@@ -370,8 +366,8 @@ def _get_triggered_tag_format(at_least_one: bool, stop_after_first: bool):
370366 (
371367 0 ,
372368 _get_triggered_tag_format (at_least_one = False , stop_after_first = False ),
373- r"""const_string ::= (("L1"))
374- const_string_1 ::= (("L2"))
369+ r"""const_string ::= (("L1")) (=("A"))
370+ const_string_1 ::= (("L2")) (=("A"))
375371triggered_tags_group ::= (("1" const_string "A") | ("2" const_string_1 "A"))
376372triggered_tags ::= TagDispatch(
377373 ("A", triggered_tags_group),
@@ -388,7 +384,7 @@ def _get_triggered_tag_format(at_least_one: bool, stop_after_first: bool):
388384 r"""const_string ::= (("L1"))
389385const_string_1 ::= (("L2"))
390386triggered_tags_group ::= (("1" const_string "A") | ("2" const_string_1 "A"))
391- triggered_tags_first ::= (("A1" const_string "A") | ("A2" const_string_1 "A"))
387+ triggered_tags_first ::= (("A1" const_string "A") | ("A2" const_string_1 "A")) (=(triggered_tags_sub))
392388triggered_tags_sub ::= TagDispatch(
393389 ("A", triggered_tags_group),
394390 stop_eos=true,
@@ -402,8 +398,8 @@ def _get_triggered_tag_format(at_least_one: bool, stop_after_first: bool):
402398 (
403399 2 ,
404400 _get_triggered_tag_format (at_least_one = False , stop_after_first = True ),
405- r"""const_string ::= (("L1"))
406- const_string_1 ::= (("L2"))
401+ r"""const_string ::= (("L1")) (=("A"))
402+ const_string_1 ::= (("L2")) (=("A"))
407403triggered_tags_group ::= (("1" const_string "A") | ("2" const_string_1 "A"))
408404triggered_tags ::= TagDispatch(
409405 ("A", triggered_tags_group),
@@ -417,8 +413,8 @@ def _get_triggered_tag_format(at_least_one: bool, stop_after_first: bool):
417413 (
418414 3 ,
419415 _get_triggered_tag_format (at_least_one = True , stop_after_first = True ),
420- r"""const_string ::= (("L1"))
421- const_string_1 ::= (("L2"))
416+ r"""const_string ::= (("L1")) (=("A"))
417+ const_string_1 ::= (("L2")) (=("A"))
422418triggered_tags ::= (("A1" const_string "A") | ("A2" const_string_1 "A"))
423419root ::= ((triggered_tags))
424420""" ,
@@ -466,8 +462,7 @@ def test_triggered_tag_format(
466462 }
467463 ],
468464 },
469- r"""const_string ::= (("[TEXT]"))
470- triggered_tags_group ::= (("" const_string "<end>"))
465+ r"""triggered_tags_group ::= (("[TEXT]" "<end>"))
471466triggered_tags ::= TagDispatch(
472467 ("<start>", triggered_tags_group),
473468 stop_eos=true,
@@ -527,8 +522,8 @@ def _get_triggered_tag_with_outside_tag(at_least_one: bool, stop_after_first: bo
527522 (
528523 0 ,
529524 _get_triggered_tag_with_outside_tag (at_least_one = False , stop_after_first = False ),
530- r"""const_string ::= (("L1"))
531- const_string_1 ::= (("L2"))
525+ r"""const_string ::= (("L1")) (=("A"))
526+ const_string_1 ::= (("L2")) (=("A"))
532527triggered_tags_group ::= (("1" const_string "A") | ("2" const_string_1 "A"))
533528triggered_tags ::= TagDispatch(
534529 ("A", triggered_tags_group),
@@ -546,7 +541,7 @@ def _get_triggered_tag_with_outside_tag(at_least_one: bool, stop_after_first: bo
546541 r"""const_string ::= (("L1"))
547542const_string_1 ::= (("L2"))
548543triggered_tags_group ::= (("1" const_string "A") | ("2" const_string_1 "A"))
549- triggered_tags_first ::= (("A1" const_string "A") | ("A2" const_string_1 "A"))
544+ triggered_tags_first ::= (("A1" const_string "A") | ("A2" const_string_1 "A")) (=(triggered_tags_sub))
550545triggered_tags_sub ::= TagDispatch(
551546 ("A", triggered_tags_group),
552547 stop_eos=false,
@@ -561,8 +556,8 @@ def _get_triggered_tag_with_outside_tag(at_least_one: bool, stop_after_first: bo
561556 (
562557 2 ,
563558 _get_triggered_tag_with_outside_tag (at_least_one = False , stop_after_first = True ),
564- r"""const_string ::= (("L1"))
565- const_string_1 ::= (("L2"))
559+ r"""const_string ::= (("L1")) (=("A"))
560+ const_string_1 ::= (("L2")) (=("A"))
566561triggered_tags_group ::= (("1" const_string "A") | ("2" const_string_1 "A"))
567562triggered_tags ::= TagDispatch(
568563 ("A", triggered_tags_group),
@@ -577,9 +572,9 @@ def _get_triggered_tag_with_outside_tag(at_least_one: bool, stop_after_first: bo
577572 (
578573 3 ,
579574 _get_triggered_tag_with_outside_tag (at_least_one = True , stop_after_first = True ),
580- r"""const_string ::= (("L1"))
581- const_string_1 ::= (("L2"))
582- triggered_tags_sub ::= (("A1" const_string "A") | ("A2" const_string_1 "A"))
575+ r"""const_string ::= (("L1")) (=("A"))
576+ const_string_1 ::= (("L2")) (=("A"))
577+ triggered_tags_sub ::= (("A1" const_string "A") | ("A2" const_string_1 "A")) (=("end"))
583578triggered_tags ::= ((triggered_tags_sub "end"))
584579tag ::= (("begin" triggered_tags))
585580root ::= ((tag))
@@ -632,47 +627,47 @@ def _get_tags_with_separator_format(at_least_one: bool, stop_after_first: bool):
632627 (
633628 0 ,
634629 _get_tags_with_separator_format (at_least_one = False , stop_after_first = False ),
635- r"""const_string ::= (("L1"))
630+ r"""const_string ::= (("L1")) (=("A"))
636631tag ::= (("A1" const_string "A"))
637- const_string_1 ::= (("L2"))
632+ const_string_1 ::= (("L2")) (=("A"))
638633tag_1 ::= (("A2" const_string_1 "A"))
639634tags_with_separator_tags ::= ((tag) | (tag_1))
640- tags_with_separator_sub ::= (("AA" tags_with_separator_tags tags_with_separator_sub) | "" )
641- tags_with_separator ::= ((tags_with_separator_tags tags_with_separator_sub) | "" )
635+ tags_with_separator_sub ::= ("" | ("AA" tags_with_separator_tags tags_with_separator_sub))
636+ tags_with_separator ::= ("" | (tags_with_separator_tags tags_with_separator_sub))
642637root ::= ((tags_with_separator))
643638""" ,
644639 ),
645640 (
646641 1 ,
647642 _get_tags_with_separator_format (at_least_one = True , stop_after_first = False ),
648- r"""const_string ::= (("L1"))
643+ r"""const_string ::= (("L1")) (=("A"))
649644tag ::= (("A1" const_string "A"))
650- const_string_1 ::= (("L2"))
645+ const_string_1 ::= (("L2")) (=("A"))
651646tag_1 ::= (("A2" const_string_1 "A"))
652647tags_with_separator_tags ::= ((tag) | (tag_1))
653- tags_with_separator_sub ::= (("AA" tags_with_separator_tags tags_with_separator_sub) | "" )
648+ tags_with_separator_sub ::= ("" | ("AA" tags_with_separator_tags tags_with_separator_sub))
654649tags_with_separator ::= ((tags_with_separator_tags tags_with_separator_sub))
655650root ::= ((tags_with_separator))
656651""" ,
657652 ),
658653 (
659654 2 ,
660655 _get_tags_with_separator_format (at_least_one = False , stop_after_first = True ),
661- r"""const_string ::= (("L1"))
656+ r"""const_string ::= (("L1")) (=("A"))
662657tag ::= (("A1" const_string "A"))
663- const_string_1 ::= (("L2"))
658+ const_string_1 ::= (("L2")) (=("A"))
664659tag_1 ::= (("A2" const_string_1 "A"))
665660tags_with_separator_tags ::= ((tag) | (tag_1))
666- tags_with_separator ::= ((tags_with_separator_tags) | "" )
661+ tags_with_separator ::= ("" | (tags_with_separator_tags) )
667662root ::= ((tags_with_separator))
668663""" ,
669664 ),
670665 (
671666 3 ,
672667 _get_tags_with_separator_format (at_least_one = True , stop_after_first = True ),
673- r"""const_string ::= (("L1"))
668+ r"""const_string ::= (("L1")) (=("A"))
674669tag ::= (("A1" const_string "A"))
675- const_string_1 ::= (("L2"))
670+ const_string_1 ::= (("L2")) (=("A"))
676671tag_1 ::= (("A2" const_string_1 "A"))
677672tags_with_separator_tags ::= ((tag) | (tag_1))
678673tags_with_separator ::= ((tags_with_separator_tags))
@@ -729,9 +724,9 @@ def _get_tags_with_separator_format_with_outside_tag(at_least_one: bool, stop_af
729724 _get_tags_with_separator_format_with_outside_tag (
730725 at_least_one = False , stop_after_first = False
731726 ),
732- r"""const_string ::= (("L1"))
727+ r"""const_string ::= (("L1")) (=("A"))
733728tag ::= (("A1" const_string "A"))
734- const_string_1 ::= (("L2"))
729+ const_string_1 ::= (("L2")) (=("A"))
735730tag_1 ::= (("A2" const_string_1 "A"))
736731tags_with_separator_tags ::= ((tag) | (tag_1))
737732tags_with_separator_sub ::= (("AA" tags_with_separator_tags tags_with_separator_sub) | ("end"))
@@ -743,9 +738,9 @@ def _get_tags_with_separator_format_with_outside_tag(at_least_one: bool, stop_af
743738 (
744739 1 ,
745740 _get_tags_with_separator_format_with_outside_tag (at_least_one = True , stop_after_first = False ),
746- r"""const_string ::= (("L1"))
741+ r"""const_string ::= (("L1")) (=("A"))
747742tag ::= (("A1" const_string "A"))
748- const_string_1 ::= (("L2"))
743+ const_string_1 ::= (("L2")) (=("A"))
749744tag_1 ::= (("A2" const_string_1 "A"))
750745tags_with_separator_tags ::= ((tag) | (tag_1))
751746tags_with_separator_sub ::= (("AA" tags_with_separator_tags tags_with_separator_sub) | ("end"))
@@ -757,11 +752,11 @@ def _get_tags_with_separator_format_with_outside_tag(at_least_one: bool, stop_af
757752 (
758753 2 ,
759754 _get_tags_with_separator_format_with_outside_tag (at_least_one = False , stop_after_first = True ),
760- r"""const_string ::= (("L1"))
755+ r"""const_string ::= (("L1")) (=("A"))
761756tag ::= (("A1" const_string "A"))
762- const_string_1 ::= (("L2"))
757+ const_string_1 ::= (("L2")) (=("A"))
763758tag_1 ::= (("A2" const_string_1 "A"))
764- tags_with_separator_tags ::= ((tag) | (tag_1))
759+ tags_with_separator_tags ::= ((tag) | (tag_1)) (=("end"))
765760tags_with_separator ::= ((tags_with_separator_tags "end") | ("end"))
766761tag_2 ::= (("begin" tags_with_separator))
767762root ::= ((tag_2))
@@ -770,11 +765,11 @@ def _get_tags_with_separator_format_with_outside_tag(at_least_one: bool, stop_af
770765 (
771766 3 ,
772767 _get_tags_with_separator_format_with_outside_tag (at_least_one = True , stop_after_first = True ),
773- r"""const_string ::= (("L1"))
768+ r"""const_string ::= (("L1")) (=("A"))
774769tag ::= (("A1" const_string "A"))
775- const_string_1 ::= (("L2"))
770+ const_string_1 ::= (("L2")) (=("A"))
776771tag_1 ::= (("A2" const_string_1 "A"))
777- tags_with_separator_tags ::= ((tag) | (tag_1))
772+ tags_with_separator_tags ::= ((tag) | (tag_1)) (=("end"))
778773tags_with_separator ::= ((tags_with_separator_tags "end"))
779774tag_2 ::= (("begin" tags_with_separator))
780775root ::= ((tag_2))
@@ -1049,13 +1044,12 @@ def test_compound_format(
10491044 },
10501045 "end" : "<end>" ,
10511046 },
1052- r"""const_string ::= (("[TEXT]"))
1053- any_text ::= TagDispatch(
1047+ r"""any_text ::= TagDispatch(
10541048 stop_eos=false,
10551049 stop_str=("<end>"),
10561050 loop_after_dispatch=false
10571051)
1058- sequence ::= ((const_string any_text))
1052+ sequence ::= (("[TEXT]" any_text))
10591053tag ::= (("<start>" sequence))
10601054root ::= ((tag))
10611055""" ,
@@ -1105,22 +1099,21 @@ def test_compound_format(
11051099 stop_str=("<end2>"),
11061100 loop_after_dispatch=false
11071101)
1108- triggered_tags_group ::= ((">" any_text "" ))
1109- triggered_tags_first ::= (("<start2>" any_text "" ))
1102+ triggered_tags_group ::= ((">" any_text))
1103+ triggered_tags_first ::= (("<start2>" any_text)) (=(triggered_tags_sub ))
11101104triggered_tags_sub ::= TagDispatch(
11111105 ("<start2", triggered_tags_group),
11121106 stop_eos=false,
11131107 stop_str=("<end>"),
11141108 loop_after_dispatch=true
11151109)
11161110triggered_tags ::= ((triggered_tags_first triggered_tags_sub))
1117- const_string ::= (("[TEXT2]"))
11181111any_text_1 ::= TagDispatch(
11191112 stop_eos=false,
11201113 stop_str=("<end>"),
11211114 loop_after_dispatch=false
11221115)
1123- sequence ::= ((const_string any_text_1))
1116+ sequence ::= (("[TEXT2]" any_text_1))
11241117any_text_2 ::= TagDispatch(
11251118 stop_eos=false,
11261119 stop_str=("<end3>"),
@@ -1192,30 +1185,28 @@ def test_compound_format(
11921185 stop_str=("<end2>"),
11931186 loop_after_dispatch=false
11941187)
1195- triggered_tags_group ::= ((">" any_text "" ))
1196- triggered_tags_first ::= (("<start2>" any_text "" ))
1188+ triggered_tags_group ::= ((">" any_text))
1189+ triggered_tags_first ::= (("<start2>" any_text)) (=(triggered_tags_sub ))
11971190triggered_tags_sub ::= TagDispatch(
11981191 ("<start2", triggered_tags_group),
11991192 stop_eos=true,
12001193 stop_str=(),
12011194 loop_after_dispatch=true
12021195)
12031196triggered_tags ::= ((triggered_tags_first triggered_tags_sub))
1204- const_string ::= (("[TEXT]"))
12051197any_text_1 ::= (([\0-\U0010ffff]*))
1206- sequence ::= ((const_string any_text_1))
1198+ sequence ::= (("[TEXT]" any_text_1))
12071199any_text_2 ::= TagDispatch(
12081200 stop_eos=false,
12091201 stop_str=("<end3>"),
12101202 loop_after_dispatch=false
12111203)
12121204tag ::= (("<start3>" any_text_2))
12131205tags_with_separator_tags ::= ((tag))
1214- tags_with_separator_sub ::= (("<sep>" tags_with_separator_tags tags_with_separator_sub) | "" )
1206+ tags_with_separator_sub ::= ("" | ("<sep>" tags_with_separator_tags tags_with_separator_sub))
12151207tags_with_separator ::= ((tags_with_separator_tags tags_with_separator_sub))
1216- const_string_1 ::= (("[TEXT2]"))
12171208any_text_3 ::= (([\0-\U0010ffff]*))
1218- sequence_1 ::= ((const_string_1 any_text_3))
1209+ sequence_1 ::= (("[TEXT2]" any_text_3))
12191210or ::= ((tags_with_separator) | (sequence_1))
12201211or_1 ::= ((triggered_tags) | (sequence) | (or))
12211212root ::= ((or_1))
0 commit comments