Skip to content

Commit

Permalink
0.1.4-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
levkopo committed May 6, 2021
1 parent 2214723 commit 773f14c
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 173 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

group 'com.github.kayjamlang'
archivesBaseName = "core"
version '0.1.3.6'
version '0.1.4-dev'

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.13.2'
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/github/kayjamlang/core/KayJamIdentifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.kayjamlang.core;

import java.util.regex.Pattern;

public enum KayJamIdentifier {
VAR("var"),
FUNCTION("function|fun"),
NAMED("named"),
PUBLIC("public"),
PRIVATE("private"),
WHILE("while"),
FOR("for"),
CLASS("class"),
OBJECT("object"),
RETURN("return"),
CONSTRUCTOR("constructor"),
COMPANION("companion"),
USE("use"),
CAST("as"),
IS("is"),
IF("if"),
IN("in"),
ELSE("else"),

;

private final Pattern pattern;

KayJamIdentifier(String regex) {
pattern = Pattern.compile("^" + regex + "$");
}

public boolean endOfMatch(String s) {
return pattern.matcher(s).find();
}

public static KayJamIdentifier find(String str) {
for(KayJamIdentifier t : KayJamIdentifier.values()) {
if(t.endOfMatch(str))
return t;
}

return null;
}
}
328 changes: 184 additions & 144 deletions src/main/java/com/github/kayjamlang/core/KayJamParser.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.github.kayjamlang.core;

public class KayJamVersion {
public static final Integer VERSION_CODE = 4;
public static final int VERSION_CODE = 5;
}
20 changes: 1 addition & 19 deletions src/main/java/com/github/kayjamlang/core/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,12 @@ public enum Type {
TK_REF ("->"),
TK_ANNOTATION ("\\@"),
TK_NEW_LINE ("\\R"),
TK_PUBLIC ("public "),
TK_PRIVATE ("private "),
TK_COMPANION ("companion "),
TK_RETURN ("return "),
TK_CONSTRUCTOR ("constructor"),
TK_FUNCTION ("(function|fun)"),
TK_CLASS ("class"),
TK_OBJECT ("object"),
TK_USE ("use "),
TK_WHILE ("while"),
TK_NAMED ("named "),
TK_FOR ("for"),
TK_COMPANION_ACCESS ("::"),
TK_COLON (":"),
TK_OPEN ("\\("),
TK_CLOSE ("\\)"),
TK_SEMI (";"),
TK_COMMA (","),
TK_VAR ("var"),
TK_AS("as"),
TK_IS("is"),
TK_KEY_IN ("in "),
TK_KEY_IF ("if"),
TK_KEY_ELSE ("else"),
TK_NULLABLE ("\\?"),
TK_OPEN_SQUARE_BRACKET("\\["),
TK_CLOSE_SQUARE_BRACKET("\\]"),
Expand Down Expand Up @@ -90,7 +72,7 @@ public enum Type {
pattern = Pattern.compile("^" + regex);
}

int endOfMatch(String s) {
public int endOfMatch(String s) {
Matcher m = pattern.matcher(s);

if (m.find()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public Container(List<Expression> children, AccessIdentifier identifier, int lin
}
}

public Container(List<Expression> children, int line) {
this(children, AccessIdentifier.NONE, line);
}

@Override
public String toString() {
return "Container{" +
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/github/kayjamlang/core/containers/Script.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.kayjamlang.core.containers;

import com.github.kayjamlang.core.exceptions.ParserException;
import com.github.kayjamlang.core.expressions.Expression;
import com.github.kayjamlang.core.expressions.UseExpression;
import com.github.kayjamlang.core.opcodes.AccessIdentifier;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Script extends Container {
public final Map<String, ClassContainer> classes = new HashMap<>();
public final List<UseExpression> usages = new ArrayList<>();

public Script(Container container) throws ParserException {
super(new ArrayList<>(), AccessIdentifier.NONE, 0);
functions.addAll(container.functions);

boolean usagesHeadFinished = false;
for(Expression expression: container.children){
if(expression instanceof UseExpression){
if(usagesHeadFinished)
throw new ParserException(expression.line, "All use expressions must be above the rest!");

usages.add((UseExpression) expression);
}else usagesHeadFinished = true;

if(expression instanceof ClassContainer){
ClassContainer clazz = (ClassContainer) expression;
classes.put(clazz.name, clazz);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@
import com.github.kayjamlang.core.opcodes.AccessIdentifier;

public class UseExpression extends Expression {

public final String from;

public UseExpression(String from, int line){
super(AccessIdentifier.NONE, line);
this.from = from;
expression = null;
}

@Deprecated
public final Expression expression;

@Deprecated
public UseExpression(Expression expression, int line) {
super(AccessIdentifier.NONE, line);
this.expression = expression;
this.from = null;
}

@Deprecated
public interface UseInterface{
Expression getExpression(String path) throws Exception;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void prepare(){

@Test
public void test() throws Exception {
Expression expression = parser.readExpression();
Expression expression = parser.readTopExpression();

assertNotNull(expression);
assertSame(ObjectContainer.class, expression.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void prepare(){

@Test
public void test() throws Exception {
Expression expression = parser.readExpression();
Expression expression = parser.readTopExpression();

assertNotNull(expression);
assertSame(ClassContainer.class, expression.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void prepare(){

@Test
public void test() throws Exception {
Expression expression = parser.readExpression();
Expression expression = parser.readTopExpression();

assertNotNull(expression);
assertSame(ClassContainer.class, expression.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void prepare(){

@Test
public void test() throws Exception {
Expression expression = parser.readExpression();
Expression expression = parser.readTopExpression();

assertNotNull(expression);
assertSame(ClassContainer.class, expression.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void prepare(){

@Test
public void test() throws Exception {
Expression expression = parser.readExpression();
Expression expression = parser.readTopExpression();

assertNotNull(expression);
assertSame(ClassContainer.class, expression.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void prepare(){

@Test
public void test() throws Exception {
Expression expression = parser.readExpression();
Expression expression = parser.readTopExpression();

assertNotNull(expression);
assertSame(ClassContainer.class, expression.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void prepare(){

@Test
public void test() throws Exception {
Expression expression = parser.readExpression();
Expression expression = parser.readTopExpression();

assertNotNull(expression);
assertSame(ObjectContainer.class, expression.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void prepare(){

@Test
public void test() throws Exception {
Expression expression = parser.readExpression();
Expression expression = parser.readTopExpression();

assertNotNull(expression);
assertSame(UseExpression.class, expression.getClass());
Expand Down

0 comments on commit 773f14c

Please sign in to comment.