Skip to content

Commit

Permalink
Merge pull request #13 from SWAT-engineering/basic-multiline-highligh…
Browse files Browse the repository at this point in the history
…ting

Basic multiline highlighting
  • Loading branch information
sungshik authored Aug 23, 2024
2 parents 6df491d + 46e8198 commit 1a3b465
Show file tree
Hide file tree
Showing 24 changed files with 1,021 additions and 443 deletions.
8 changes: 4 additions & 4 deletions rascal-textmate-core/src/main/rascal/VSCode.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ RscGrammar getRscGrammar() {
case p: prod(label("real", sort("Literal")), _, _) => setCategory(p, "constant.numeric")
case p: prod(label("rational", sort("Literal")), _, _) => setCategory(p, "constant.numeric")
case p: prod(label("location", sort("Literal")), _, _) => setCategory(p, "markup.underline.link")
case p: prod(label("regExp", sort("Literal")), _, _) => setCategory(p, "string.regexp")
case p: prod(label("regExp", sort("Literal")), _, _) => setCategory(p, "constant.regexp")
case p: prod(lex("StringConstant"), _, _) => setCategory(p, "string.quoted.double")
case p: prod(lex("CaseInsensitiveStringConstant"), _, _) => setCategory(p, "string.quoted.single")
case p: prod(lex("PreStringChars"), _, _) => setCategory(p, "string.interpolated")
case p: prod(lex("MidStringChars"), _, _) => setCategory(p, "string.interpolated")
case p: prod(lex("PostStringChars"), _, _) => setCategory(p, "string.interpolated")
case p: prod(lex("PreStringChars"), _, _) => setCategory(p, "string.quoted.double")
case p: prod(lex("MidStringChars"), _, _) => setCategory(p, "string.quoted.double")
case p: prod(lex("PostStringChars"), _, _) => setCategory(p, "string.quoted.double")
};
}
21 changes: 14 additions & 7 deletions rascal-textmate-core/src/main/rascal/lang/oniguruma/Conversion.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import lang::rascal::grammar::analyze::Symbols;

@synopsis{
Converts a set/list of values (presumably: productions, symbols, or
conditions) to a list of regular expressions.
conditions) to a list of regular expressions
}

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

Condition guard = \precede(\alt(alternatives));
Symbol guarded = \conditional(\seq(symbols), {guard});
return toRegExp(g, prod(def, [guarded], attributes));
return toRegExp(g, [guarded], attributes);
}

return toRegExp(g, symbols, attributes);
}

@synopsis{
Converts a list of symbols and a set of attributes to a regular expression
}

RegExp toRegExp(Grammar g, list[Symbol] symbols, set[Attr] attributes) {
RegExp re = infix("", toRegExps(g, symbols)); // Empty separator for concatenation
return /\tag("category"(c)) := attributes ? group(re, category = c) : re;
}
@synopsis{
Converts a symbol to a regular expression.
Converts a symbol to a regular expression
}
// `Type`
Expand Down Expand Up @@ -138,7 +145,7 @@ default RegExp toRegExp(Grammar _, Symbol s) {
}
@synopsis{
Converts a condition to a regular expression.
Converts a condition to a regular expression
}
RegExp toRegExp(Grammar g, \follow(symbol))
Expand All @@ -165,7 +172,7 @@ default RegExp toRegExp(Grammar _, Condition c) {
}
@synopsis{
Converts a character range to a regular expression.
Converts a character range to a regular expression
}
Expand All @@ -175,7 +182,7 @@ RegExp toRegExp(Grammar _, \char-class(ranges))
;
@synopsis{
Encodes a (list of) char(s) to a (list of) code unit(s).
Encodes a (list of) char(s) to a (list of) code unit(s)
}
str encode(list[int] chars, bool withBounds = false)
Expand Down
36 changes: 34 additions & 2 deletions rascal-textmate-core/src/main/rascal/lang/rascal/grammar/Util.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ bool tryParse(Grammar g, Symbol s, str input, bool allowAmbiguity = false) {
return false;
}

@synopsis{
Gets the terminals that occur in production `p`, possibly recursively
(default: `true`)
}

set[Symbol] getTerminals(Grammar g, Production p, bool recur = true)
= {s | s <- p.symbols, !isNonTerminalType(s)}
+ {*getTerminals(g, child) | recur, s <- p.symbols, child <- lookup(g, s)};

@synopsis{
Lookups a list of productions for symbol `s` in grammar `g`, replacing
formal parameters with actual parameters when needed
Expand Down Expand Up @@ -79,13 +88,36 @@ Symbol delabel(label(_, Symbol s)) = s;
default Symbol delabel(Symbol s) = s;
@synopsis{
Gets from set `symbols` each symbol that is a strict prefix of any other
Removes operators `?` and `*` from symbol `s`, if any
}
Symbol destar(label(name, symbol))
= label(name, destar(symbol));
Symbol destar(\opt(symbol))
= destar(symbol);
Symbol destar(\iter-star(symbol))
= \iter(destar(symbol));
Symbol destar(\iter-star-seps(symbol, separators))
= \iter-seps(destar(symbol), separators);
default Symbol destar(Symbol s) = s;
@synopsis{
Retain from set `symbols` each symbol that is a strict prefix of any other
symbol in `symbols`
}
set[Symbol] getStrictPrefixes(set[Symbol] symbols)
set[Symbol] retainStrictPrefixes(set[Symbol] symbols)
= {s1 | s1 <- symbols, any(s2 <- symbols, isStrictPrefix(s1, s2))};
@synopsis{
Removes from set `symbols` each symbol that is a strict prefix of any other
symbol in `symbols`
}
set[Symbol] removeStrictPrefixes(set[Symbol] symbols)
= symbols - retainStrictPrefixes(symbols);
@synopsis{
Checks if symbol `s1` is a strict prefix of symbol `s2`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import lang::rascal::grammar::Util;
}

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

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

Dependencies deps(Graph[Production] g) {
Dependencies filterProds(Predicate[Production] p)
= deps(filterNodes(g, getNodes(g, p)));
Dependencies retainProds(Predicate[Production] p)
= deps(retainNodes(g, getNodes(g, p)));
Dependencies removeProds(Predicate[Production] p, bool removeAncestors)
= deps(removeNodes(g, getNodes(g, p, getAncestors = removeAncestors)));
list[Production] getProds()
= toList(g.nodes);

return deps(filterProds, removeProds, getProds);
return deps(retainProds, removeProds, getProds);
}

@synopsis{
Expand Down Expand Up @@ -110,10 +110,10 @@ set[&Node] getNodes(Graph[&Node] g, Predicate[&Node] p,
}
@synopsis{
Filters nodes (and connected edges) from graph `g`
Retains nodes (and connected edges) from graph `g`
}
Graph[&Node] filterNodes(Graph[&Node] g, set[&Node] nodes)
Graph[&Node] retainNodes(Graph[&Node] g, set[&Node] nodes)
= <g.nodes & nodes, carrierR(g.edges, nodes)>;
@synopsis{
Expand Down
Loading

0 comments on commit 1a3b465

Please sign in to comment.