fix(muscript): move components used in StandardLib to muscript-core
This commit is contained in:
parent
712a0406c5
commit
111cd13de2
|
@ -0,0 +1,54 @@
|
|||
package io.gitlab.jfronny.muscript.core;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An exception type with a location
|
||||
* For use in MuScript, can be converted to a pretty LocationalError with asPrintable
|
||||
*/
|
||||
public class LocationalException extends RuntimeException {
|
||||
private final CodeLocation location;
|
||||
private final List<StackFrame> callStack = new LinkedList<>();
|
||||
|
||||
private String messageCache;
|
||||
|
||||
public LocationalException(CodeLocation location) {
|
||||
super();
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public LocationalException(CodeLocation location, String message) {
|
||||
super(message);
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public LocationalException(CodeLocation location, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public LocationalException(CodeLocation location, Throwable cause) {
|
||||
super(cause);
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
// Not getMessage() to fix locations
|
||||
return messageCache != null ? messageCache : (messageCache = asPrintable().toString());
|
||||
}
|
||||
|
||||
public PrettyPrintError asPrintable() {
|
||||
return (location.source() == null ? PrettyPrintError.builder() : PrettyPrintError.builder(location))
|
||||
.setMessage(super.getMessage())
|
||||
.setCallStack(callStack)
|
||||
.build();
|
||||
}
|
||||
|
||||
public LocationalException appendStack(StackFrame frame) {
|
||||
messageCache = null;
|
||||
callStack.add(frame);
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.gitlab.jfronny.muscript.parser;
|
||||
package io.gitlab.jfronny.muscript.core;
|
||||
|
||||
public enum MuScriptVersion {
|
||||
V1, V2, V3;
|
|
@ -1,6 +1,5 @@
|
|||
package io.gitlab.jfronny.muscript.parser.util;
|
||||
package io.gitlab.jfronny.muscript.core;
|
||||
|
||||
import io.gitlab.jfronny.muscript.core.CodeLocation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
|
@ -1,4 +1,4 @@
|
|||
package io.gitlab.jfronny.muscript.parser;
|
||||
package io.gitlab.jfronny.muscript.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.gitlab.jfronny.muscript.parser.util;
|
||||
package io.gitlab.jfronny.muscript.core;
|
||||
|
||||
public sealed interface StackFrame {
|
||||
record Raw(String file, String name, int chStart) implements StackFrame {
|
|
@ -10,12 +10,11 @@ import io.gitlab.jfronny.muscript.ast.context.TypeMismatchException;
|
|||
import io.gitlab.jfronny.muscript.ast.dynamic.*;
|
||||
import io.gitlab.jfronny.muscript.ast.number.*;
|
||||
import io.gitlab.jfronny.muscript.ast.string.Concatenate;
|
||||
import io.gitlab.jfronny.muscript.core.CodeLocation;
|
||||
import io.gitlab.jfronny.muscript.core.*;
|
||||
import io.gitlab.jfronny.muscript.parser.lexer.LegacyLexer;
|
||||
import io.gitlab.jfronny.muscript.parser.lexer.Lexer;
|
||||
import io.gitlab.jfronny.muscript.parser.lexer.LexerImpl;
|
||||
import io.gitlab.jfronny.muscript.parser.lexer.Token;
|
||||
import io.gitlab.jfronny.muscript.parser.util.PrettyPrintError;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -127,6 +126,7 @@ public class Parser extends VersionedComponent {
|
|||
return conditional();
|
||||
} catch (RuntimeException e) {
|
||||
if (e instanceof ParseException) throw e;
|
||||
else if (e instanceof LocationalException le) throw new ParseException(le.asPrintable(), le.getCause());
|
||||
else throw error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package io.gitlab.jfronny.muscript.parser;
|
||||
|
||||
import io.gitlab.jfronny.muscript.core.MuScriptVersion;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class VersionedComponent {
|
||||
|
|
|
@ -2,12 +2,19 @@ package io.gitlab.jfronny.muscript.parser.impl;
|
|||
|
||||
import io.gitlab.jfronny.muscript.ast.Expr;
|
||||
import io.gitlab.jfronny.muscript.ast.context.IExprParser;
|
||||
import io.gitlab.jfronny.muscript.parser.MuScriptVersion;
|
||||
import io.gitlab.jfronny.muscript.ast.context.Script;
|
||||
import io.gitlab.jfronny.muscript.core.MuScriptVersion;
|
||||
import io.gitlab.jfronny.muscript.core.SourceFS;
|
||||
import io.gitlab.jfronny.muscript.parser.Parser;
|
||||
|
||||
public class ExprParserImpl implements IExprParser {
|
||||
@Override
|
||||
public Expr parse(String expr) {
|
||||
return Parser.parse(MuScriptVersion.DEFAULT, expr);
|
||||
public Expr parse(MuScriptVersion version, String expr) {
|
||||
return Parser.parse(version, expr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Script parseMultiScript(MuScriptVersion version, String path, SourceFS filesystem) {
|
||||
return Parser.parseMultiScript(version, path, filesystem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.muscript.parser.lexer;
|
||||
|
||||
import io.gitlab.jfronny.muscript.core.CodeLocation;
|
||||
import io.gitlab.jfronny.muscript.parser.MuScriptVersion;
|
||||
import io.gitlab.jfronny.muscript.core.MuScriptVersion;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.muscript.parser.lexer;
|
||||
|
||||
import io.gitlab.jfronny.muscript.core.CodeLocation;
|
||||
import io.gitlab.jfronny.muscript.parser.MuScriptVersion;
|
||||
import io.gitlab.jfronny.muscript.core.MuScriptVersion;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface Lexer {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.gitlab.jfronny.muscript.parser.lexer;
|
||||
|
||||
import io.gitlab.jfronny.muscript.core.CodeLocation;
|
||||
import io.gitlab.jfronny.muscript.parser.MuScriptVersion;
|
||||
import io.gitlab.jfronny.muscript.core.MuScriptVersion;
|
||||
import io.gitlab.jfronny.muscript.parser.VersionedComponent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
|
|
@ -5,5 +5,4 @@ module io.gitlab.jfronny.commons.muscript.parser {
|
|||
requires io.gitlab.jfronny.commons.muscript.core;
|
||||
exports io.gitlab.jfronny.muscript.parser;
|
||||
exports io.gitlab.jfronny.muscript.parser.lexer;
|
||||
exports io.gitlab.jfronny.muscript.parser.util;
|
||||
}
|
Loading…
Reference in New Issue