Skip to content

Commit

Permalink
Merge branch 'main' into fix-issue-in-isoverlapping
Browse files Browse the repository at this point in the history
  • Loading branch information
sungshik committed Nov 8, 2024
2 parents a0a22a7 + 0eea46e commit 904f0be
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 63 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.40.13-SNAPSHOT</version>
<version>0.40.18-SNAPSHOT</version>
<packaging>jar</packaging>

<scm>
<developerConnection>scm:git:ssh://[email protected]/usethesource/rascal.git</developerConnection>
<tag>v0.40.12</tag>
<tag>v0.40.16</tag>
</scm>

<!-- dependency resolution configuration (usethesource) -->
Expand All @@ -32,7 +32,7 @@
<exec.mainClass>org.rascalmpl.shell.RascalShell</exec.mainClass>
<rascal.test.memory>2</rascal.test.memory>
<maven.compiler.release>11</maven.compiler.release>
<rascal-maven.version>0.28.7-BOOT3</rascal-maven.version>
<rascal-maven.version>0.28.9-BOOT1</rascal-maven.version>
</properties>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

import io.usethesource.vallang.ISourceLocation;

/**
* This is a injected configuration parameter of a Rascal run-time
* environment like IRascalMonitor and IDEServices. The goal is
* to find all the file names that have the given `fileName` in
* the current run-time environment. For compiled Rascal this would
* be ClassLoader.findResources, while for the interpreter it is
* typically a search through all the roots of the source folders.
*/
public interface IResourceLocationProvider {
Set<ISourceLocation> findResources(String fileName);
}
3 changes: 2 additions & 1 deletion src/org/rascalmpl/interpreter/utils/JavaBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.rascalmpl.exceptions.JavaCompilation;
import org.rascalmpl.exceptions.JavaMethodLink;
import org.rascalmpl.exceptions.RuntimeExceptionFactory;
import org.rascalmpl.ideservices.BasicIDEServices;
import org.rascalmpl.ideservices.IDEServices;
import org.rascalmpl.interpreter.Configuration;
import org.rascalmpl.interpreter.IEvaluator;
Expand Down Expand Up @@ -445,7 +446,7 @@ else if (formals[i].isAssignableFrom(IDEServices.class)) {
args[i] = (IDEServices) monitor;
}
else {
throw new IllegalArgumentException("no IDE services are available in this environment");
args[i] = new BasicIDEServices(err, monitor);
}
}
else if (formals[i].isAssignableFrom(IResourceLocationProvider.class)) {
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/library/Content.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Content


@synopsis{Content wraps the HTTP Request/Response API to support interactive visualization types
on the terminal ((RascalShell)).}
on the terminal.}
@description{
Values wrapped in a `Content` wrapper will be displayed by interactive
Rascal applications such as the IDE, the REPL terminal and the documentation pages.
Expand Down
26 changes: 5 additions & 21 deletions src/org/rascalmpl/library/List.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ dup([3, 1, 5, 3, 1, 7, 1, 2]);
list[&T] dup(list[&T] lst)
= ([] | (ix in it) ? it : it + [ix] | &T ix <- lst);

@deprecated{
Use a list index instead
}
@deprecated{Use a list index instead}
@javaClass{org.rascalmpl.library.Prelude}
java &T elementAt(list[&T] lst, int index);

Expand Down Expand Up @@ -420,7 +418,7 @@ list[&T] mix(list[&T] l, list[&T] r){
sizeL = size(l);
sizeR = size(r);
minSize = sizeL < sizeR ? sizeL : sizeR;
return [elementAt(l,i),elementAt(r,i)| i <- [0 .. minSize]] + drop(sizeR,l) + drop(sizeL,r);
return [l[i],r[i] | i <- [0 .. minSize]] + drop(sizeR,l) + drop(sizeL,r);
}
@synopsis{Compute all permutations of a list.}
Expand Down Expand Up @@ -481,7 +479,8 @@ push("eagle", ["zebra", "elephant", "snake", "owl"]);
list[&T] push(&T elem, list[&T] lst) = [elem] + lst;
@synopsis{Apply a function to successive elements of list and combine the results (__deprecated__).}
@synopsis{Apply a function to successive elements of list and combine the results.}
@deprecated{This function is deprecated. Use a reducer expression instead, like `(init | f(it, e) | e <- lst)`.}
@description{
Apply the function `fn` to successive elements of list `lst` starting with `unit`.
}
Expand All @@ -492,22 +491,7 @@ int add(int x, int y) { return x + y; }
reducer([10, 20, 30, 40], add, 0);
```
}
@benefits{
}
@pitfalls{
:::warning
This function is *deprecated*, use a reducer expression instead. E.g. `(init | f(it, e) | e <- lst)`.
:::
}
&T reducer(list[&T] lst, &T (&T, &T) fn, &T unit)
{
&T result = unit;
for(&T elm <- lst){
result = fn(result, elm);
}
return result;
}
&T reducer(list[&T] lst, &T (&T, &T) fn, &T unit) = (unit | fn(it, elm) | elm <- lst);
list[&T] remove(list[&T] lst, int indexToDelete) =
[ lst[i] | i <- index(lst), i != indexToDelete ];
Expand Down
8 changes: 2 additions & 6 deletions src/org/rascalmpl/library/Set.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ power1({1,2,3,4});
}
public set[set[&T]] power1(set[&T] st) = power(st) - {{}};

@synopsis{Apply a function to successive elements of a set and combine the results (__deprecated__).}
@synopsis{Apply a function to successive elements of a set and combine the results.}
@description{
Apply the function `fn` to successive elements of set `s` starting with `unit`.
}
Expand All @@ -229,11 +229,7 @@ int add(int x, int y) { return x + y; }
reducer({10, 20, 30, 40}, add, 0);
```
}
@pitfalls{
:::warning
This function is *deprecated*, use a reducer expression instead, such as `(init | fn(it,e) | e <- st)`.
:::
}
@deprecated{Use a reducer expression instead, such as `(init | fn(it,e) | e <- st)`.}
public &T reducer(set[&T] st, &T (&T,&T) fn, &T unit) =
(unit | fn(it,elm) | elm <- st);

Expand Down
57 changes: 54 additions & 3 deletions src/org/rascalmpl/library/analysis/diff/edits/TextEdits.rsc
Original file line number Diff line number Diff line change
@@ -1,15 +1,66 @@
@license{
Copyright (c) 2022, NWO-I Centrum Wiskunde & Informatica (CWI)
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
@synopsis{Intermediate representation for file creation, removal and changing, including textual (string) rewriting.}
@description{
((DocumentEdit))s can be produced by source-to-source transformation tools, and then executed
via ((executeDocumentEdits)) in the REPL or ((applyDocumentsEdits)) by the IDE.
}
@benefits{
* Document edits can be attached to ((data:CodeAction))s and error ((util::IDEServices-Message))s, to achieve interactive
source code rewriting utilities.
* Document edits can be tested via ((executeDocumentEdits))
* Document edits can be "high fidelity", avoiding unnecessary damage to a source text.
}
@pitfalls{
* Code edits depend on a specific state of the source file that may be transient while editing. Use the ((CodeAction)) interface
to avoid racing for the state of the source file.
}
module analysis::diff::edits::TextEdits

@synopsis{File changing operations}
data DocumentEdit
= removed(loc file)
| created(loc file)
| renamed(loc from, loc to)
| changed(loc file, list[TextEdit] edits)
;

@synopsis{Shorthand for file changes.}
DocumentEdit changed(list[TextEdit] edits:[replace(loc l, str _), *_])
= changed(l.top, edits);

@synopsis{String rewriting operations}
@description{
The core operation is to replace a substring with another.
The replace operator uses a `loc` value to point to a range inside a string,
and a `str` as its replacement.
}
data TextEdit
= replace(loc range, str replacement)
;
= replace(loc range, str replacement);

@synopsis{Deletion is replacement with an empty string.}
TextEdit delete(loc range)
= replace(range, "");

TextEdit delete(loc range) = replace(range, "");
@synopsis{Inserting before a given range.}
TextEdit insertBefore(loc range, str insertion, str separator=" ")
= (range.begin?)
? replace(range.top(range.offset, 0, range.begin, range.begin), "<insertion><separator>")
: replace(range.top(range.offset, 0), "<insertion><separator>");

@synopsis{Inserting after a given range.}
TextEdit insertAfter(loc range, str insertion, str separator=" ")
= (range.end?)
? replace(range.top(range.offset + range.length, 0, range.end, range.end), "<separator><insertion>")
: replace(range.top(range.offset + range.length, 0), "<separator><insertion>");

7 changes: 5 additions & 2 deletions src/org/rascalmpl/library/lang/box/util/Box2Text.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@description{
The input to Box2Text is a hierarchy of "Boxes" represented by the Box algebraic data-type.
These boxes put hard and soft relative positioning constraints on the embedded text fragments, and
there is the global soft constraints of the width of the screen (or the paper). Box2Text can also
add markup for syntax highlighting in either ANSI plaintext encoding, HTML font tags or LaTex macros.
there is the global soft constraints of the width of the screen (or the paper).
This implementation is a port from ASF+SDF to Rascal. The ASF+SDF implementation was published as
"From Box to Tex:An algebraic approach to the construction of documentation tools" by Mark van den Brand
Expand Down Expand Up @@ -62,6 +62,9 @@ format(H([L("if"), H([L("("), L("true"), L(")")], hs=0), HOV([L("W<i>") | i <- [
format(H([L("if"), H([L("("), L("true"), L(")")], hs=0), HV([L("W<i>") | i <- [0..30]])]))
```
}
@pitfalls{
* Box2text does not have highlighting features anymore; you can use ((util::Highlight)) for this instead.
}
module lang::box::util::Box2Text

import util::Math;
Expand Down
50 changes: 41 additions & 9 deletions src/org/rascalmpl/library/util/IDEServices.rsc
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module util::IDEServices

extend analysis::diff::edits::TextEdits;
import analysis::diff::edits::ExecuteTextEdits;
extend Content;
extend Message;

@synopsis{Open a browser for a given location.}
@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
java void browse(loc uri, str title = "<uri>", int viewColumn=1);


@synopsis{Open an editor for file at a given location.}
@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
java void edit(loc uri);


@synopsis{Let the IDE apply a list of document edits.}
@description{
Asks the IDE to apply document edits as defined in the standard library module
Expand All @@ -26,24 +25,23 @@ Typically a call to this IDE service method is included in the implementation
of refactoring and quick-fix features of the language service protocol.
}
@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
public java void applyDocumentsEdits(list[DocumentEdit] edits);

java void applyDocumentsEdits(list[DocumentEdit] edits);

@synopsis{Asks the IDE to show a "browser window" with the given interactive Content.}
@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
public java void showInteractiveContent(Content content, str title=content.title, int viewColumn=content.viewColumn);
java void showInteractiveContent(Content content, str title=content.title, int viewColumn=content.viewColumn);

@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
public java void showMessage(Message message);
java void showMessage(Message message);

@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
public java void logMessage(Message message);
java void logMessage(Message message);

@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
public java void registerDiagnostics(list[Message] messages);
java void registerDiagnostics(list[Message] messages);

@javaClass{org.rascalmpl.library.util.IDEServicesLibrary}
public java void unregisterDiagnostics(list[loc] resources);
java void unregisterDiagnostics(list[loc] resources);

@synopsis{Fixes are an extension to error messages that allow for interactive code fixes in the IDE.}
@description{
Expand All @@ -69,3 +67,37 @@ via a ((CodeAction)), and then have it executed by the respective language serve
}
data Command(str title="")
= noop();

@synopsis{Utility function for testing code actions.}
@benefits{
* test code actions outside of the IDE context, for example while running unit tests.
* this function is synchronous and blocks until the IO is finished. After running it you
can test for changed file contents without waiting, in most cases (see pitfalls).
}
@description{
* `action` is the action to execute
* `evaluator` is used to evaluate action.command if it is present.
* the return value is the return value of the evaluated command, or `true` if no command is present.
}
@pitfalls{
* ((CodeAction))s may use the other features of ((util::IDEServices)), and thus start editors or browsers as side-effects.
* ((CodeAction))s code actions with ((DocumentEdit))s will write to disk and change the original files.
* ((util::IDEServices::Command))s can only be executed by a parametrized command `evaluator``; if you do not provide it then
this test function will throw ((CallFailed)) exceptions for every unsupported (((util::IDEServices::Command)).
* (((util::IDEServices::Command))s can start asynchronous effects by calling non-blocking functions that schedule other effects.
An example is the starting and running of web ((Library:module:Content)) via ((showInteractiveContent)). Testing properties of the
rendered content will require the use of asynchronous testing frameworks, like Selenium.
* Never call ((testCodeAction)) to execute actions in an interactive context. That must be done by the IDE client
to synchronize the contents of editors and parse trees, etc. This function is only for unit testing code actions.
}
value testCodeAction(CodeAction action, value (Command _) evaluator = value (noop()) { return true; }) {
if (action.edits?) {
executeDocumentEdits(action.edits);
}

if (action.command?) {
return evaluator(action.command);
}

return true;
}
12 changes: 0 additions & 12 deletions src/org/rascalmpl/repl/TerminalProgressBarMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,6 @@ static String moveUp(int n) {
return "\u001B[" + n + "F";
}

static String overlined() {
return "\u001B[53m";
}

static String underlined() {
return "\u001B[4m";
}

public static String printCursorPosition() {
return "\u001B[6n";
}
Expand All @@ -468,10 +460,6 @@ public static String normal() {
return "\u001B[0m";
}

public static String lightBackground() {
return "\u001B[48;5;250m";
}

static String moveDown(int n) {
return "\u001B[" + n + "E";
}
Expand Down
7 changes: 5 additions & 2 deletions src/org/rascalmpl/semantics/dynamic/Expression.java
Original file line number Diff line number Diff line change
Expand Up @@ -1833,10 +1833,12 @@ public IMatchingResult buildMatcher(IEvaluatorContext eval, boolean bindTypePara
}
return new TypedMultiVariablePattern(eval, this, type, arg.getName(), bindTypeParameters);
}

if(arg.hasQualifiedName()){
return new MultiVariablePattern(eval, this, arg.getQualifiedName());
}
throw new ImplementationError(null);

throw new UnsupportedOperation("splice operator outside of list or set", this);
}

@Override
Expand Down Expand Up @@ -1872,7 +1874,8 @@ public Type typeOf(Environment env, IEvaluator<Result<IValue>> eval, boolean ins
if(arg.hasQualifiedName()){
return arg.getQualifiedName().typeOf(env, eval, instantiateTypeParameters);
}
throw new ImplementationError(null);

return arg.typeOf(env, eval, instantiateTypeParameters);
}

}
Expand Down
2 changes: 0 additions & 2 deletions src/org/rascalmpl/semantics/dynamic/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.rascalmpl.interpreter.result.Result;
import org.rascalmpl.interpreter.result.ResultFactory;
import org.rascalmpl.interpreter.utils.Names;
import org.rascalmpl.uri.URIUtil;

import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.IValue;
Expand Down
1 change: 0 additions & 1 deletion test/org/rascalmpl/test/parser/StackNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.junit.Assert;
import org.junit.Test;
import org.rascalmpl.parser.gtd.stack.EpsilonStackNode;
import org.rascalmpl.parser.gtd.stack.LiteralStackNode;
import org.rascalmpl.parser.gtd.stack.filter.ICompletionFilter;
import org.rascalmpl.parser.gtd.stack.filter.IEnterFilter;
import org.rascalmpl.parser.gtd.stack.filter.follow.AtEndOfLineRequirement;
Expand Down

0 comments on commit 904f0be

Please sign in to comment.