Skip to content

Commit

Permalink
chore: improve error message when missing stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Feb 20, 2024
1 parent 5fe5caf commit 2a96112
Show file tree
Hide file tree
Showing 54 changed files with 112 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/net/sourceforge/plantuml/preproc/Stdlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ public static void extractStdLib() throws IOException {
private static Collection<String> getAll() throws IOException {
final Set<String> result = new TreeSet<>();
final InputStream home = getInternalInputStream("home", ".repx");
if (home == null)
throw new IOException("Cannot access to /stdlib/*.repx files");

final BufferedReader br = new BufferedReader(new InputStreamReader(home));
String name;
while ((name = br.readLine()) != null)
Expand Down
6 changes: 4 additions & 2 deletions src/net/sourceforge/plantuml/tim/TFunctionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public TFunctionImpl(String functionName, List<TFunctionArgument> args, boolean
this.functionType = functionType;
}

@Override
public boolean canCover(int nbArg, Set<String> namedArguments) {
for (String n : namedArguments)
if (signature.getNamedArguments().contains(n) == false)
Expand Down Expand Up @@ -140,8 +141,9 @@ public void executeProcedureInternal(TContext context, TMemory memory, List<TVal
context.executeLines(copy, body, TFunctionType.PROCEDURE, false);
}

public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> args,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location,
List<TValue> args, Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
if (functionType == TFunctionType.LEGACY_DEFINE)
return executeReturnLegacyDefine(location, context, memory, args);

Expand Down
4 changes: 3 additions & 1 deletion src/net/sourceforge/plantuml/tim/stdlib/AlwaysFalse.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%false", 0);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 0;
}


@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
return TValue.fromBoolean(false);
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/AlwaysTrue.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%true", 0);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 0;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
return TValue.fromBoolean(true);
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/CallUserFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%call_user_func", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg > 0;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String fname = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Chr.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%chr", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Darken.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%darken", 2);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 2;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String colorString = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/DateFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%date", 2);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 0 || nbArg == 1 || nbArg == 2;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
if (values.size() == 0)
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Dec2hex.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%dec2hex", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Dirpath.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%dirpath", 0);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 0;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
if (value == null) {
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Eval.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%eval", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String exp = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%feature", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String arg = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/FileExists.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%file_exists", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
// ::comment when __CORE__
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Filename.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%filename", 0);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 0;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
if (value == null) {
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/FunctionExists.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%function_exists", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String name = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/GetAllTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%get_all_theme", 0);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 0;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final JsonArray result = new JsonArray();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/GetJsonKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%get_json_keys", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final TValue data = values.get(0);
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/GetJsonType.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%get_json_type", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final TValue data = values.get(0);
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/GetVariableValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%get_variable_value", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String name = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/GetVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%version", 0);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 0;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
return TValue.fromString(Version.versionString());
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Getenv.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%getenv", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
// ::comment when __CORE__
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Hex2dec.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%hex2dec", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
try {
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/HslColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%hsl_color", 3);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 3 || nbArg == 4;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final int h = values.get(0).toInt();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/IntVal.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%intval", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String s = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/InvokeProcedure.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%invoke_procedure", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg > 0;
}
Expand All @@ -75,6 +76,7 @@ public void executeProcedureInternal(TContext context, TMemory memory, List<TVal
func.executeProcedureInternal(context, memory, sublist, named);
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) {
throw new UnsupportedOperationException();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/IsDark.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%is_dark", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String colorString = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/IsLight.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%is_light", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String colorString = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/JsonKeyExists.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%json_key_exists", 1);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 2;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final TValue arg0 = values.get(0);
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/Lighten.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%lighten", 2);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 2;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String colorString = values.get(0).toString();
Expand Down
2 changes: 2 additions & 0 deletions src/net/sourceforge/plantuml/tim/stdlib/LoadJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ public TFunctionSignature getSignature() {
return new TFunctionSignature("%load_json", 3);
}

@Override
public boolean canCover(int nbArg, Set<String> namedArgument) {
return nbArg == 1 || nbArg == 2 || nbArg == 3;
}

@Override
public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> values,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
final String path = values.get(0).toString();
Expand Down
Loading

0 comments on commit 2a96112

Please sign in to comment.