Skip to content

Commit e28fbe8

Browse files
committed
Add tests, and doc.
1 parent df3da02 commit e28fbe8

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

find-useless-parentheses.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,22 @@ compute() {
3636
//block[
3737
(: except not one of these ... :)
3838
39-
(: do not flag "a ( b | c )* d" or with other operator :)
39+
(: do not flag "a ( b | c )* d" or with other operator :)
4040
not(./parent::ebnf/blockSuffix and ./altList/OR) and
4141
42-
(: do not flag "(a ( b | c )* )?" because it is not the same as the '*?'-operator. :)
42+
(: do not flag "(a ( b | c )* )?" because it is not the same as the '*?'-operator. :)
4343
not(./parent::ebnf/blockSuffix/ebnfSuffix/QUESTION and ./altList[count(./*) = 1]/alternative[count(./*) = 1]/element[count(./*) = 1]/ebnf[./block and ./blockSuffix/ebnfSuffix/*]) and
4444
45+
(: do not flag blocks that contain a lot of elements like "(a b c)*" :)
4546
not(./parent::ebnf/blockSuffix and count(./altList/alternative/element) > 1) and
47+
48+
(: do not flag if there are alts *and* it is preceed or followed by an element,
49+
e.g., "a (b | c d)" or "(a | b) c". :)
4650
not(./altList/OR and ../../following-sibling::element) and
4751
not(./altList/OR and ../../preceding-sibling::element) and
4852
49-
(: do not flag "a ( v += b )* c" or with other operator :)
50-
not(./altList/alternative/element/labeledElement/(ASSIGN or PLUS_ASSIGN) and ./parent::ebnf/blockSuffix) and
53+
(: do not flag "a ( v += b )* c" or with other operator :)
54+
not(./altList/alternative/element/labeledElement/(ASSIGN or PLUS_ASSIGN) and ./parent::ebnf/blockSuffix) and
5155
5256
not(./parent::labeledElement/(ASSIGN or PLUS_ASSIGN))
5357
]' | trcaret -- -H > up-output.txt
@@ -72,7 +76,7 @@ compute() {
7276
if [ -s up-output.txt ]
7377
then
7478
echo Found useless parentheses in grammars... 1>&2
75-
found=1
79+
found=1
7680
cat up-output.txt 1>&2
7781
fi
7882
rm -f up-output.txt

tests/grammars/Up4.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
grammar Up4;
2+
start: (a b c)*;

tests/grammars/Up5.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
grammar Up5;
2+
start: a (b | c);

tests/grammars/Up6.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
grammar Up6;
2+
start: (b | c) d;

0 commit comments

Comments
 (0)