refactor: make filenames more consistent
This commit is contained in:
parent
b675411925
commit
69f93b4f87
@ -46,6 +46,8 @@ public class Filename {
|
|||||||
|
|
||||||
|
|
||||||
public Filename(String protocol, String path) {
|
public Filename(String protocol, String path) {
|
||||||
|
path = path.trim();
|
||||||
|
protocol = protocol.trim();
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
this.path = path;
|
this.path = path;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package me.topchetoeu.jscript;
|
package me.topchetoeu.jscript;
|
||||||
|
|
||||||
public class Location implements Comparable<Location> {
|
public class Location implements Comparable<Location> {
|
||||||
public static final Location INTERNAL = new Location(0, 0, new Filename("jscript", "internal"));
|
public static final Location INTERNAL = new Location(0, 0, new Filename("jscript", "native"));
|
||||||
private int line;
|
private int line;
|
||||||
private int start;
|
private int start;
|
||||||
private Filename filename;
|
private Filename filename;
|
||||||
|
@ -2,7 +2,6 @@ package me.topchetoeu.jscript.engine.debug;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.Filename;
|
|
||||||
import me.topchetoeu.jscript.json.JSON;
|
import me.topchetoeu.jscript.json.JSON;
|
||||||
import me.topchetoeu.jscript.json.JSONElement;
|
import me.topchetoeu.jscript.json.JSONElement;
|
||||||
import me.topchetoeu.jscript.json.JSONMap;
|
import me.topchetoeu.jscript.json.JSONMap;
|
||||||
@ -33,7 +32,7 @@ public class V8Message {
|
|||||||
this.params = raw.contains("params") ? raw.map("params") : new JSONMap();
|
this.params = raw.contains("params") ? raw.map("params") : new JSONMap();
|
||||||
}
|
}
|
||||||
public V8Message(String raw) {
|
public V8Message(String raw) {
|
||||||
this(JSON.parse(new Filename("jscript", "json-msg"), raw).map());
|
this(JSON.parse(null, raw).map());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONMap toMap() {
|
public JSONMap toMap() {
|
||||||
|
@ -177,6 +177,7 @@ public class JSON {
|
|||||||
return ParseRes.res(values, n);
|
return ParseRes.res(values, n);
|
||||||
}
|
}
|
||||||
public static JSONElement parse(Filename filename, String raw) {
|
public static JSONElement parse(Filename filename, String raw) {
|
||||||
|
if (filename == null) filename = new Filename("jscript", "json");
|
||||||
var res = parseValue(filename, Parsing.tokenize(filename, raw), 0);
|
var res = parseValue(filename, Parsing.tokenize(filename, raw), 0);
|
||||||
if (res.isFailed()) throw new SyntaxException(null, "Invalid JSON given.");
|
if (res.isFailed()) throw new SyntaxException(null, "Invalid JSON given.");
|
||||||
else if (res.isError()) throw new SyntaxException(null, res.error);
|
else if (res.isError()) throw new SyntaxException(null, res.error);
|
||||||
@ -191,6 +192,7 @@ public class JSON {
|
|||||||
.replace("\\", "\\\\")
|
.replace("\\", "\\\\")
|
||||||
.replace("\n", "\\n")
|
.replace("\n", "\\n")
|
||||||
.replace("\r", "\\r")
|
.replace("\r", "\\r")
|
||||||
|
.replace("\t", "\\t")
|
||||||
.replace("\"", "\\\"")
|
.replace("\"", "\\\"")
|
||||||
+ "\"";
|
+ "\"";
|
||||||
if (el.isList()) {
|
if (el.isList()) {
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
package me.topchetoeu.jscript.lib;
|
package me.topchetoeu.jscript.lib;
|
||||||
|
|
||||||
import me.topchetoeu.jscript.Filename;
|
|
||||||
import me.topchetoeu.jscript.engine.Context;
|
import me.topchetoeu.jscript.engine.Context;
|
||||||
import me.topchetoeu.jscript.exceptions.EngineException;
|
import me.topchetoeu.jscript.exceptions.EngineException;
|
||||||
import me.topchetoeu.jscript.exceptions.SyntaxException;
|
import me.topchetoeu.jscript.exceptions.SyntaxException;
|
||||||
import me.topchetoeu.jscript.interop.Native;
|
import me.topchetoeu.jscript.interop.Native;
|
||||||
import me.topchetoeu.jscript.json.JSON;
|
import me.topchetoeu.jscript.json.JSON;
|
||||||
|
|
||||||
public class JSONLib {
|
@Native("JSON") public class JSONLib {
|
||||||
@Native
|
@Native
|
||||||
public static Object parse(Context ctx, String val) {
|
public static Object parse(Context ctx, String val) {
|
||||||
try {
|
try {
|
||||||
return JSON.toJs(JSON.parse(new Filename("jscript", "json"), val));
|
return JSON.toJs(JSON.parse(null, val));
|
||||||
}
|
}
|
||||||
catch (SyntaxException e) { throw EngineException.ofSyntax(e.msg); }
|
catch (SyntaxException e) { throw EngineException.ofSyntax(e.msg); }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user