Skip to content

Commit

Permalink
Merge pull request #8 from Tapeline/master
Browse files Browse the repository at this point in the history
v2.0-RC-3
  • Loading branch information
Quail-Language authored Feb 20, 2024
2 parents e8c5f06 + 3d8f3a5 commit 34a1c7e
Show file tree
Hide file tree
Showing 62 changed files with 2,591 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import me.tapeline.quailj.typing.classes.QObject;

// TODO fix error display

// TODO fix in operator and add contains method to list
public class Main {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DocumentationGenerator {
);

private final String documentationHeader = "<!doctype html>\n" +
"<html lang=\"en\">\n" +
"<html lang=\"en\" style=\"overflow-x:hidden\">\n" +
"<head>\n" +
" <meta charset=\"UTF-8\">\n" +
" <meta name=\"viewport\"\n" +
Expand All @@ -41,6 +41,28 @@ public class DocumentationGenerator {
" <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/[email protected]" +
"/font/bootstrap-icons.css\">\n" +
" <title>Docs</title>\n" +
" <style>\n" +
" @media screen and (min-width: 810px) {\n" +
" aside {\n" +
" height: 100vh;\n" +
" overflow-y: scroll;\n" +
" }\n" +
" }\n" +
"\n" +
" :target {\n" +
" -webkit-animation: target-fade 5s 1;\n" +
" -moz-animation: target-fade 5s 1;\n" +
" }\n" +
"\n" +
" @-webkit-keyframes target-fade {\n" +
" 0% { background-color: rgba(255, 198, 109, 0.8); }\n" +
" 100% { background-color: rgba(0,0,0,0); }\n" +
" }\n" +
" @-moz-keyframes target-fade {\n" +
" 0% { background-color: rgba(255, 198, 109, 0.8); }\n" +
" 100% { background-color: rgba(0,0,0,0); }\n" +
" }" +
" </style>\n" +
"</head>\n" +
"<body class=\"row p-5\">";
private final String documentationFooter = "</body>\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class LaunchCommandParser {
private final HashMap<String, Object> userFlags;
private String selectedRunStrategy;
private String targetScript;
private String scriptArgString;

private String outputFile;

Expand All @@ -35,6 +36,8 @@ public static boolean toBoolean(String strValue) {
public void parseReceivedArgs() {
boolean strategySet = false;
boolean waitingOutputFile = false;
boolean waitingScriptArgString = false;
StringBuilder scriptArgString = new StringBuilder();
for (String arg : receivedConsoleArgs) {
if (arg.startsWith("-")) parseFlag(arg);
else if (!strategySet) {
Expand All @@ -47,14 +50,17 @@ else if (!strategySet) {
} else if (waitingOutputFile) {
outputFile = arg;
break;
} else if (waitingScriptArgString) {
scriptArgString.append(arg).append(" ");
} else {
targetScript = arg;
if (selectedRunStrategy.equalsIgnoreCase("run") ||
selectedRunStrategy.equalsIgnoreCase("profile") ||
selectedRunStrategy.equalsIgnoreCase("debug"))
break;
waitingScriptArgString = true;
}
}
this.scriptArgString = scriptArgString.toString();
}

private void parseFlag(String flag) {
Expand Down Expand Up @@ -114,4 +120,9 @@ public String getTargetScript() {
public String getOutputFile() {
return outputFile;
}

public String getScriptArgString() {
return scriptArgString;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class QuailLauncher {
public static final int QUAIL_MAJOR_VERSION = 2;
public static final int QUAIL_MINOR_VERSION = 0;
public static final int QUAIL_PATCH_VERSION = 0;
public static final String QUAIL_VERSION_STATUS = "alpha";
public static final int QUAIL_SUBVERSION = 7;
public static final String QUAIL_VERSION_SUFFIX = "RC-2";
public static final String QUAIL_VERSION_STATUS = "beta";
public static final int QUAIL_SUBVERSION = 8;
public static final String QUAIL_VERSION_SUFFIX = "RC-3";

private HashMap<String, Object> localFlags;

Expand Down Expand Up @@ -125,6 +125,7 @@ public QObject launch(String[] args) throws IOException, PreprocessorException,
new File(launchCommandParser.getTargetScript()),
scriptHome, new DefaultIO(), doProfile, doDebug);
QObject returnValue = QObject.Val(0);
runtime.setScriptArgs(launchCommandParser.getScriptArgString());
try {
runtime.run(parsedCode, runtime.getMemory());
} catch (RuntimeStriker striker) {
Expand Down Expand Up @@ -172,6 +173,8 @@ public QObject launchWithAnonymousCode(String code, File scriptHome, String[] ar

Runtime runtime = new Runtime(parsedCode, preprocessedCode, new File(""),
scriptHome, io, doProfile, doDebug);
runtime.setScriptArgs(launchCommandParser.getScriptArgString());

QObject returnValue = QObject.Val(0);
try {
runtime.run(parsedCode, runtime.getMemory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ private char peekNext() {
return sourceCode.charAt(current + 1);
}

/**
* Gets next non-whitespace character index
* @return -1 if next char is out of code bounds. If not - target char index
*/
private int findNextSignificantIndex() {
int offset = 0;
while (current + offset < sourceCode.length()) {
if (isSignificant(sourceCode.charAt(current + offset)))
return offset;
else
offset++;
}
return -1;
}

/**
* @param c target character
* @return whether the character is a digit
Expand All @@ -192,6 +207,14 @@ private boolean isAlphaNumeric(char c) {
return isAlpha(c) || isDigit(c);
}

/**
* @param c target character
* @return whether the character is significant
*/
private boolean isSignificant(char c) {
return c != '\n' && c != '\t' && c != '\r' && c != ' ';
}

/**
* Checks for short assign operators and adds binary op token
* @param type binary operator token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public enum TokenType {
DOT,
VAR,
IN,
NOT_IN,
INSTANCEOF,
LIKE,
DOCS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,40 +444,6 @@ private BlockNode parsePythonBlock() throws ParserException {
}
}

@Deprecated // TODO Remove??
private Node newNode(Class<? extends Node> node, Object... args) {
Constructor<?> foundConstructor = null;
for (Constructor<?> constructor : node.getConstructors()) {
if (constructor.getParameterCount() != args.length)
continue;
boolean matches = true;
for (int i = 0; i < args.length; i++) {
if (args[i] == null) continue;
Class<?> parameterClass = constructor.getParameterTypes()[i];
if (constructor.getParameterTypes()[i].isPrimitive())
parameterClass = ClassUtils.primitiveToWrapper(
constructor.getParameterTypes()[i]);
if (!parameterClass.isAssignableFrom(args[i].getClass())) {
matches = false;
break;
}
}
if (matches) {
foundConstructor = constructor;
break;
}
}
if (foundConstructor == null)
throw new RuntimeException("Cannot find suitable constructor");
try {
return applyDecorations(pendingDecorations,
(Node) foundConstructor.newInstance(args));
} catch (InstantiationException | IllegalAccessException |
InvocationTargetException e) {
throw new RuntimeException(e);
}
}

/**
* Transforms given node with provided decorations in reverse order
* E.g.: @Decorator(...) function f() ... will be transformed into
Expand Down Expand Up @@ -859,9 +825,11 @@ else if (name.getLexeme().equals("call"))
Node statement = parseStatement();
function = new LiteralFunction(funcToken, "_constructor", args, statement);
}
if (decorations != null)
return applyDecorations(decorations, function);
else
if (decorations != null) {
Node node = applyDecorations(decorations, function);
pendingDecorations.clear();
return node;
} else
return function;
}

Expand All @@ -883,9 +851,12 @@ private Node parseClass() throws ParserException {
else if (expr instanceof VariableNode)
contents.add(new VarAssignNode(expr.getToken(), ((VariableNode) expr),
getDefaultNodeFor(((VariableNode) expr).modifiers)));
else if (expr instanceof LiteralFunction)
methods.put(((LiteralFunction) expr).name, ((LiteralFunction) expr));
else
else if (expr instanceof LiteralFunction) {
if (methods.containsKey(((LiteralFunction) expr).name))
initialize.add(expr); // In case there is an overloaded method
else
methods.put(((LiteralFunction) expr).name, ((LiteralFunction) expr));
} else
initialize.add(expr);
}
return new LiteralClass(classToken, className.getLexeme(), like, contents, methods, initialize);
Expand Down Expand Up @@ -944,8 +915,17 @@ private Node parseAnd(ParsingPolicy policy) throws ParserException {

private Node parseEquality(ParsingPolicy policy) throws ParserException {
Node left = parseComparison(policy);
while (matchMultiple(EQUALS, NOT_EQUALS, INSTANCEOF, IN) != null)
left = new BinaryOperatorNode(getPrevious(), left, parseComparison(policy));
while (true) {
Token op = matchMultiple(EQUALS, NOT_EQUALS, INSTANCEOF, IN);
if (op == null && forseePattern(NOT, IN)) {
Token notToken = require(NOT);
Token inToken = require(IN);
op = new Token(NOT_IN, "not in", notToken.getLine(), notToken.getCharacter(),
inToken.getCharacter() + inToken.getLength() - notToken.getCharacter());
}
if (op == null) break;
left = new BinaryOperatorNode(op, left, parseComparison(policy));
}
return left;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
import me.tapeline.quailj.runtime.std.basic.common.*;
import me.tapeline.quailj.runtime.std.basic.numbers.*;
import me.tapeline.quailj.runtime.std.basic.threading.QThread;
import me.tapeline.quailj.runtime.std.cli.CliLibrary;
import me.tapeline.quailj.runtime.std.event.EventLibrary;
import me.tapeline.quailj.runtime.std.fs.FSLibrary;
import me.tapeline.quailj.runtime.std.ji.JILibrary;
import me.tapeline.quailj.runtime.std.math.MathLibrary;
import me.tapeline.quailj.runtime.std.qml.QMLLibrary;
import me.tapeline.quailj.runtime.std.reflect.ReflectLibrary;
import me.tapeline.quailj.runtime.std.storage.StorageLibrary;
import me.tapeline.quailj.typing.classes.*;
import me.tapeline.quailj.typing.classes.errors.*;
Expand All @@ -55,6 +57,7 @@ public class Runtime {
protected final boolean doProfile;
protected final boolean doDebug;
protected final String code;
protected String scriptArgs;
protected final IO io;
protected Node current = new Node(Token.UNDEFINED) {
@Override
Expand Down Expand Up @@ -93,6 +96,14 @@ public Runtime(Node root, String code, File scriptFile, File scriptHome,
io.resetCwd();
}

public String getScriptArgs() {
return scriptArgs;
}

public void setScriptArgs(String scriptArgs) {
this.scriptArgs = scriptArgs;
}

public File getScriptFile() {
return scriptFile;
}
Expand Down Expand Up @@ -255,6 +266,8 @@ private void registerDefaults() {
libraryLoader.addBuiltinLibrary(new FSLibrary());
libraryLoader.addBuiltinLibrary(new StorageLibrary());
libraryLoader.addBuiltinLibrary(new MathLibrary());
libraryLoader.addBuiltinLibrary(new ReflectLibrary());
libraryLoader.addBuiltinLibrary(new CliLibrary());
}

public void error(String message) throws RuntimeStriker {
Expand Down Expand Up @@ -442,6 +455,8 @@ private QObject performBinaryOperation(QObject operandA, TokenType op, QObject o
case LESS_EQUAL: return operandA.lessEqual(this, operandB);
case EQUALS: return operandA.equalsObject(this, operandB);
case NOT_EQUALS: return operandA.notEqualsObject(this, operandB);
case IN: return operandB.containsObject(this, operandA);
case NOT_IN: return operandB.notContainsObject(this, operandA);
case INSTANCEOF: return Val(operandA.instanceOf(operandB));
default: error(new QInternalException("Unknown binary operation " + op));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package me.tapeline.quailj.runtime.std.cli;

import me.tapeline.quailj.parsing.nodes.literals.LiteralFunction;
import me.tapeline.quailj.runtime.Runtime;
import me.tapeline.quailj.typing.modifiers.ModifierConstants;
import me.tapeline.quailj.typing.classes.QObject;
import me.tapeline.quailj.typing.utils.FuncArgument;
import me.tapeline.quailj.typing.classes.utils.QBuiltinFunc;
import me.tapeline.quailj.runtime.RuntimeStriker;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class CliGetConsoleArgString extends QBuiltinFunc {

public CliGetConsoleArgString(Runtime runtime) {
super(
"getConsoleArgString",
Arrays.asList(
),
runtime,
runtime.getMemory(),
false
);
}

@Override
public QObject action(Runtime runtime, HashMap<String, QObject> args, List<QObject> argList) throws RuntimeStriker {
return Val(runtime.getScriptArgs());
}

}
Loading

0 comments on commit 34a1c7e

Please sign in to comment.