-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that alternatives and quantifiers within recurring labeled alt…
…ernatives are numbered uniquely (#240) Until now, the indices of alternatives and quantifiers were restarted from 0 within every function of a recurring labeled alternative (i.e., in `rule_Label_1`, `rule_Label_2`, etc.). This made alternatives and quantifiers within recurring labeled alternatives indistinguishable from each other when it comes to decision models. This commit changes this by making the indices run continuously through functions belonging to the same label.
- Loading branch information
1 parent
f3c0d14
commit b10b085
Showing
3 changed files
with
58 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2024 Renata Hodovan, Akos Kiss. | ||
* | ||
* Licensed under the BSD 3-Clause License | ||
* <LICENSE.rst or https://opensource.org/licenses/BSD-3-Clause>. | ||
* This file may not be copied, modified, or distributed except | ||
* according to those terms. | ||
*/ | ||
|
||
/* | ||
* This test checks whether alternatives and quantifiers within recurring | ||
* labeled alternatives are numbered uniquely. | ||
*/ | ||
|
||
// TEST-PROCESS: {grammar}.g4 -o {tmpdir} | ||
// TEST-GENERATE: {grammar}Generator.{grammar}Generator -r start -m {grammar}Generator.CustomModel -j 1 -o {tmpdir}/{grammar}%d.txt | ||
|
||
grammar RecurringLabeledAlternatives; | ||
|
||
@header { | ||
from grammarinator.runtime import DefaultModel | ||
class CustomModel(DefaultModel): | ||
def choice(self, node, idx, weights): | ||
assert node.name in ['start', 'start_Binary'], node.name | ||
if node.name == 'start_Binary': | ||
assert idx == 1, idx | ||
return super().choice(node, idx, weights) | ||
def quantify(self, node, idx, cnt, start, stop): | ||
assert node.name == 'start_Binary', node.name | ||
assert idx == 1, idx | ||
return super().quantify(node, idx, cnt, start, stop) | ||
} | ||
|
||
start | ||
: {0}? ID (('+' | '-') ID)+ # Binary | ||
| {0}? ('++' | '--') ID # Unary | ||
| ID (('*'|'/') ID)+ # Binary | ||
| {0}? ID ('++' | '--') # Unary | ||
; | ||
|
||
ID : [a-z] ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"t": "p", "n": "start", "c": [{"t": "a", "ai": 0, "i": 1, "c": [{"t": "p", "n": "start_Quantifiers_test", "c": [{"t": "p", "n": "element", "c": [{"t": "l", "n": "<INVALID>", "s": "pass", "z": [1, 1]}, {"t": "q", "i": 0, "b": 0, "e": 1, "c": [{"t": "qd", "c": [{"t": "a", "ai": 0, "i": 0, "c": [{"t": "l", "n": "<INVALID>", "s": "?", "z": [1, 1]}]}]}]}]}, {"t": "q", "i": 0, "b": 1, "e": Infinity, "c": [{"t": "qd", "c": [{"t": "l", "n": "<INVALID>", "s": " | ", "z": [1, 1]}, {"t": "p", "n": "element", "c": [{"t": "l", "n": "<INVALID>", "s": "pass", "z": [1, 1]}, {"t": "q", "i": 0, "b": 0, "e": 1, "c": []}]}]}]}]}]}]} | ||
{"t": "p", "n": "start", "c": [{"t": "a", "ai": 0, "i": 1, "c": [{"t": "p", "n": "start_Quantifiers_test", "c": [{"t": "p", "n": "element", "c": [{"t": "l", "n": "<INVALID>", "s": "pass", "z": [1, 1]}, {"t": "q", "i": 0, "b": 0, "e": 1, "c": [{"t": "qd", "c": [{"t": "a", "ai": 0, "i": 0, "c": [{"t": "l", "n": "<INVALID>", "s": "?", "z": [1, 1]}]}]}]}]}, {"t": "q", "i": 1, "b": 1, "e": Infinity, "c": [{"t": "qd", "c": [{"t": "l", "n": "<INVALID>", "s": " | ", "z": [1, 1]}, {"t": "p", "n": "element", "c": [{"t": "l", "n": "<INVALID>", "s": "pass", "z": [1, 1]}, {"t": "q", "i": 0, "b": 0, "e": 1, "c": []}]}]}]}]}]}]} |