Skip to content

Commit e8a887c

Browse files
committed
Simplify a few expressions to improve readability
1 parent 546bb13 commit e8a887c

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

rascal-textmate-core/src/main/rascal/lang/textmate/Conversion.rsc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ RscGrammar preprocess(RscGrammar rsc) {
5555
// Replace occurrences of singleton ranges with just the corresponding
5656
// literal. This makes it easier to identify delimiters.
5757
return visit (rsc) {
58-
case s: \char-class([range(char, char)]) => d
58+
case \char-class([range(char, char)]) => d
5959
when d := \lit("<stringChar(char)>"), isDelimiter(d)
6060
}
6161
}
@@ -132,13 +132,14 @@ list[ConversionUnit] analyze(RscGrammar rsc) {
132132
list[Production] prodsKeywords = [prod(lex(KEYWORDS_PRODUCTION_NAME), [\alt(keywords)], {\tag("category"("keyword.control"))})];
133133
134134
// Return
135-
bool isEmptyProd(prod(_, [\alt(alternatives)], _)) = alternatives == {};
136-
set[ConversionUnit] units
137-
= {unit(rsc, p, false, hasNewline(rsc, p), getOuterDelimiterPair(rsc, p), getInnerDelimiterPair(rsc, p, getOnlyFirst = true)) | p <- prodsNonRecursive}
138-
+ {unit(rsc, p, true, hasNewline(rsc, p), getOuterDelimiterPair(rsc, p), getInnerDelimiterPair(rsc, p, getOnlyFirst = true)) | p <- prodsRecursive}
139-
+ {unit(rsc, p, false, false, <nothing(), nothing()>, <nothing(), nothing()>) | p <- prodsDelimiters, !isEmptyProd(p)}
140-
+ {unit(rsc, p, false, false, <nothing(), nothing()>, <nothing(), nothing()>) | p <- prodsKeywords, !isEmptyProd(p)};
141-
135+
bool isRecursive(Production p)
136+
= p in prodsRecursive;
137+
bool isEmptyProd(prod(_, [\alt(alternatives)], _))
138+
= alternatives == {};
139+
140+
set[ConversionUnit] units = {};
141+
units += {unit(rsc, p, isRecursive(p), hasNewline(rsc, p), getOuterDelimiterPair(rsc, p), getInnerDelimiterPair(rsc, p, getOnlyFirst = true)) | p <- prods};
142+
units += {unit(rsc, p, false, false, <nothing(), nothing()>, <nothing(), nothing()>) | p <- prodsDelimiters + prodsKeywords, !isEmptyProd(p)};
142143
return sort([*removeStrictPrefixes(units)]);
143144
}
144145

rascal-textmate-core/src/main/rascal/lang/textmate/ConversionUnit.rsc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,8 @@ bool isStrictPrefix(ConversionUnit u1, ConversionUnit u2)
165165
= isStrictPrefix(u1.prod.symbols, u2.prod.symbols);
166166
167167
// TODO: This function could be moved to a separate, generic module
168-
private bool isStrictPrefix([], [])
169-
= false;
170-
private bool isStrictPrefix([], [_, *_])
171-
= true;
172-
private bool isStrictPrefix([_, *_], [])
173-
= false;
174-
private bool isStrictPrefix([head1, *tail1], [head2, *tail2])
175-
= head1 == head2 && isStrictPrefix(tail1, tail2);
168+
private bool isStrictPrefix(list[&T] l1, list[&T] l2)
169+
= size(l1) < size(l2) && !any(i <- [0..size(l1)], l1[i] != l2[i]);
176170
177171
@synopsis{
178172
Representation of a *decomposition* of a list of units (i.e., the lists of

0 commit comments

Comments
 (0)