Skip to content

Commit 1a3b465

Browse files
authored
Merge pull request #13 from SWAT-engineering/basic-multiline-highlighting
Basic multiline highlighting
2 parents 6df491d + 46e8198 commit 1a3b465

24 files changed

+1021
-443
lines changed

rascal-textmate-core/src/main/rascal/VSCode.rsc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ RscGrammar getRscGrammar() {
5656
case p: prod(label("real", sort("Literal")), _, _) => setCategory(p, "constant.numeric")
5757
case p: prod(label("rational", sort("Literal")), _, _) => setCategory(p, "constant.numeric")
5858
case p: prod(label("location", sort("Literal")), _, _) => setCategory(p, "markup.underline.link")
59-
case p: prod(label("regExp", sort("Literal")), _, _) => setCategory(p, "string.regexp")
59+
case p: prod(label("regExp", sort("Literal")), _, _) => setCategory(p, "constant.regexp")
6060
case p: prod(lex("StringConstant"), _, _) => setCategory(p, "string.quoted.double")
6161
case p: prod(lex("CaseInsensitiveStringConstant"), _, _) => setCategory(p, "string.quoted.single")
62-
case p: prod(lex("PreStringChars"), _, _) => setCategory(p, "string.interpolated")
63-
case p: prod(lex("MidStringChars"), _, _) => setCategory(p, "string.interpolated")
64-
case p: prod(lex("PostStringChars"), _, _) => setCategory(p, "string.interpolated")
62+
case p: prod(lex("PreStringChars"), _, _) => setCategory(p, "string.quoted.double")
63+
case p: prod(lex("MidStringChars"), _, _) => setCategory(p, "string.quoted.double")
64+
case p: prod(lex("PostStringChars"), _, _) => setCategory(p, "string.quoted.double")
6565
};
6666
}

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import lang::rascal::grammar::analyze::Symbols;
1717

1818
@synopsis{
1919
Converts a set/list of values (presumably: productions, symbols, or
20-
conditions) to a list of regular expressions.
20+
conditions) to a list of regular expressions
2121
}
2222

2323
list[RegExp] toRegExps(Grammar g, set[value] values)
@@ -38,15 +38,22 @@ RegExp toRegExp(Grammar g, prod(def, symbols, attributes), bool guard = false) {
3838

3939
Condition guard = \precede(\alt(alternatives));
4040
Symbol guarded = \conditional(\seq(symbols), {guard});
41-
return toRegExp(g, prod(def, [guarded], attributes));
41+
return toRegExp(g, [guarded], attributes);
4242
}
43-
43+
return toRegExp(g, symbols, attributes);
44+
}
45+
46+
@synopsis{
47+
Converts a list of symbols and a set of attributes to a regular expression
48+
}
49+
50+
RegExp toRegExp(Grammar g, list[Symbol] symbols, set[Attr] attributes) {
4451
RegExp re = infix("", toRegExps(g, symbols)); // Empty separator for concatenation
4552
return /\tag("category"(c)) := attributes ? group(re, category = c) : re;
4653
}
4754
4855
@synopsis{
49-
Converts a symbol to a regular expression.
56+
Converts a symbol to a regular expression
5057
}
5158
5259
// `Type`
@@ -138,7 +145,7 @@ default RegExp toRegExp(Grammar _, Symbol s) {
138145
}
139146
140147
@synopsis{
141-
Converts a condition to a regular expression.
148+
Converts a condition to a regular expression
142149
}
143150
144151
RegExp toRegExp(Grammar g, \follow(symbol))
@@ -165,7 +172,7 @@ default RegExp toRegExp(Grammar _, Condition c) {
165172
}
166173
167174
@synopsis{
168-
Converts a character range to a regular expression.
175+
Converts a character range to a regular expression
169176
}
170177
171178
@@ -175,7 +182,7 @@ RegExp toRegExp(Grammar _, \char-class(ranges))
175182
;
176183
177184
@synopsis{
178-
Encodes a (list of) char(s) to a (list of) code unit(s).
185+
Encodes a (list of) char(s) to a (list of) code unit(s)
179186
}
180187
181188
str encode(list[int] chars, bool withBounds = false)

rascal-textmate-core/src/main/rascal/lang/rascal/grammar/Util.rsc

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ bool tryParse(Grammar g, Symbol s, str input, bool allowAmbiguity = false) {
3131
return false;
3232
}
3333

34+
@synopsis{
35+
Gets the terminals that occur in production `p`, possibly recursively
36+
(default: `true`)
37+
}
38+
39+
set[Symbol] getTerminals(Grammar g, Production p, bool recur = true)
40+
= {s | s <- p.symbols, !isNonTerminalType(s)}
41+
+ {*getTerminals(g, child) | recur, s <- p.symbols, child <- lookup(g, s)};
42+
3443
@synopsis{
3544
Lookups a list of productions for symbol `s` in grammar `g`, replacing
3645
formal parameters with actual parameters when needed
@@ -79,13 +88,36 @@ Symbol delabel(label(_, Symbol s)) = s;
7988
default Symbol delabel(Symbol s) = s;
8089
8190
@synopsis{
82-
Gets from set `symbols` each symbol that is a strict prefix of any other
91+
Removes operators `?` and `*` from symbol `s`, if any
92+
}
93+
94+
Symbol destar(label(name, symbol))
95+
= label(name, destar(symbol));
96+
Symbol destar(\opt(symbol))
97+
= destar(symbol);
98+
Symbol destar(\iter-star(symbol))
99+
= \iter(destar(symbol));
100+
Symbol destar(\iter-star-seps(symbol, separators))
101+
= \iter-seps(destar(symbol), separators);
102+
103+
default Symbol destar(Symbol s) = s;
104+
105+
@synopsis{
106+
Retain from set `symbols` each symbol that is a strict prefix of any other
83107
symbol in `symbols`
84108
}
85109
86-
set[Symbol] getStrictPrefixes(set[Symbol] symbols)
110+
set[Symbol] retainStrictPrefixes(set[Symbol] symbols)
87111
= {s1 | s1 <- symbols, any(s2 <- symbols, isStrictPrefix(s1, s2))};
88112
113+
@synopsis{
114+
Removes from set `symbols` each symbol that is a strict prefix of any other
115+
symbol in `symbols`
116+
}
117+
118+
set[Symbol] removeStrictPrefixes(set[Symbol] symbols)
119+
= symbols - retainStrictPrefixes(symbols);
120+
89121
@synopsis{
90122
Checks if symbol `s1` is a strict prefix of symbol `s2`
91123
}

rascal-textmate-core/src/main/rascal/lang/rascal/grammar/analyze/Dependencies.rsc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import lang::rascal::grammar::Util;
2525
}
2626

2727
data Dependencies = deps(
28-
// Filters productions that satisfy a predicate (and their dependencies)
28+
// Retains productions that satisfy a predicate (and their dependencies)
2929
// from the underlying dependency graph
30-
Dependencies(Predicate[Production]) filterProds,
30+
Dependencies(Predicate[Production]) retainProds,
3131

3232
// Removes productions that satisfy a predicate (and their dependencies),
3333
// from the underlying dependency graph, optionally including (for removal)
@@ -43,14 +43,14 @@ data Dependencies = deps(
4343
}
4444

4545
Dependencies deps(Graph[Production] g) {
46-
Dependencies filterProds(Predicate[Production] p)
47-
= deps(filterNodes(g, getNodes(g, p)));
46+
Dependencies retainProds(Predicate[Production] p)
47+
= deps(retainNodes(g, getNodes(g, p)));
4848
Dependencies removeProds(Predicate[Production] p, bool removeAncestors)
4949
= deps(removeNodes(g, getNodes(g, p, getAncestors = removeAncestors)));
5050
list[Production] getProds()
5151
= toList(g.nodes);
5252

53-
return deps(filterProds, removeProds, getProds);
53+
return deps(retainProds, removeProds, getProds);
5454
}
5555

5656
@synopsis{
@@ -110,10 +110,10 @@ set[&Node] getNodes(Graph[&Node] g, Predicate[&Node] p,
110110
}
111111
112112
@synopsis{
113-
Filters nodes (and connected edges) from graph `g`
113+
Retains nodes (and connected edges) from graph `g`
114114
}
115115
116-
Graph[&Node] filterNodes(Graph[&Node] g, set[&Node] nodes)
116+
Graph[&Node] retainNodes(Graph[&Node] g, set[&Node] nodes)
117117
= <g.nodes & nodes, carrierR(g.edges, nodes)>;
118118
119119
@synopsis{

0 commit comments

Comments
 (0)