Skip to content

Commit 773f14c

Browse files
committed
0.1.4-dev
1 parent 2214723 commit 773f14c

16 files changed

+293
-173
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77

88
group 'com.github.kayjamlang'
99
archivesBaseName = "core"
10-
version '0.1.3.6'
10+
version '0.1.4-dev'
1111

1212
dependencies {
1313
testCompile group: 'junit', name: 'junit', version: '4.13.2'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.github.kayjamlang.core;
2+
3+
import java.util.regex.Pattern;
4+
5+
public enum KayJamIdentifier {
6+
VAR("var"),
7+
FUNCTION("function|fun"),
8+
NAMED("named"),
9+
PUBLIC("public"),
10+
PRIVATE("private"),
11+
WHILE("while"),
12+
FOR("for"),
13+
CLASS("class"),
14+
OBJECT("object"),
15+
RETURN("return"),
16+
CONSTRUCTOR("constructor"),
17+
COMPANION("companion"),
18+
USE("use"),
19+
CAST("as"),
20+
IS("is"),
21+
IF("if"),
22+
IN("in"),
23+
ELSE("else"),
24+
25+
;
26+
27+
private final Pattern pattern;
28+
29+
KayJamIdentifier(String regex) {
30+
pattern = Pattern.compile("^" + regex + "$");
31+
}
32+
33+
public boolean endOfMatch(String s) {
34+
return pattern.matcher(s).find();
35+
}
36+
37+
public static KayJamIdentifier find(String str) {
38+
for(KayJamIdentifier t : KayJamIdentifier.values()) {
39+
if(t.endOfMatch(str))
40+
return t;
41+
}
42+
43+
return null;
44+
}
45+
}

src/main/java/com/github/kayjamlang/core/KayJamParser.java

+184-144
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package com.github.kayjamlang.core;
22

33
public class KayJamVersion {
4-
public static final Integer VERSION_CODE = 4;
4+
public static final int VERSION_CODE = 5;
55
}

src/main/java/com/github/kayjamlang/core/Token.java

+1-19
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,12 @@ public enum Type {
1919
TK_REF ("->"),
2020
TK_ANNOTATION ("\\@"),
2121
TK_NEW_LINE ("\\R"),
22-
TK_PUBLIC ("public "),
23-
TK_PRIVATE ("private "),
24-
TK_COMPANION ("companion "),
25-
TK_RETURN ("return "),
26-
TK_CONSTRUCTOR ("constructor"),
27-
TK_FUNCTION ("(function|fun)"),
28-
TK_CLASS ("class"),
29-
TK_OBJECT ("object"),
30-
TK_USE ("use "),
31-
TK_WHILE ("while"),
32-
TK_NAMED ("named "),
33-
TK_FOR ("for"),
3422
TK_COMPANION_ACCESS ("::"),
3523
TK_COLON (":"),
3624
TK_OPEN ("\\("),
3725
TK_CLOSE ("\\)"),
3826
TK_SEMI (";"),
3927
TK_COMMA (","),
40-
TK_VAR ("var"),
41-
TK_AS("as"),
42-
TK_IS("is"),
43-
TK_KEY_IN ("in "),
44-
TK_KEY_IF ("if"),
45-
TK_KEY_ELSE ("else"),
4628
TK_NULLABLE ("\\?"),
4729
TK_OPEN_SQUARE_BRACKET("\\["),
4830
TK_CLOSE_SQUARE_BRACKET("\\]"),
@@ -90,7 +72,7 @@ public enum Type {
9072
pattern = Pattern.compile("^" + regex);
9173
}
9274

93-
int endOfMatch(String s) {
75+
public int endOfMatch(String s) {
9476
Matcher m = pattern.matcher(s);
9577

9678
if (m.find()) {

src/main/java/com/github/kayjamlang/core/containers/Container.java

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public Container(List<Expression> children, AccessIdentifier identifier, int lin
2020
}
2121
}
2222

23+
public Container(List<Expression> children, int line) {
24+
this(children, AccessIdentifier.NONE, line);
25+
}
26+
2327
@Override
2428
public String toString() {
2529
return "Container{" +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.kayjamlang.core.containers;
2+
3+
import com.github.kayjamlang.core.exceptions.ParserException;
4+
import com.github.kayjamlang.core.expressions.Expression;
5+
import com.github.kayjamlang.core.expressions.UseExpression;
6+
import com.github.kayjamlang.core.opcodes.AccessIdentifier;
7+
8+
import java.util.ArrayList;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
public class Script extends Container {
14+
public final Map<String, ClassContainer> classes = new HashMap<>();
15+
public final List<UseExpression> usages = new ArrayList<>();
16+
17+
public Script(Container container) throws ParserException {
18+
super(new ArrayList<>(), AccessIdentifier.NONE, 0);
19+
functions.addAll(container.functions);
20+
21+
boolean usagesHeadFinished = false;
22+
for(Expression expression: container.children){
23+
if(expression instanceof UseExpression){
24+
if(usagesHeadFinished)
25+
throw new ParserException(expression.line, "All use expressions must be above the rest!");
26+
27+
usages.add((UseExpression) expression);
28+
}else usagesHeadFinished = true;
29+
30+
if(expression instanceof ClassContainer){
31+
ClassContainer clazz = (ClassContainer) expression;
32+
classes.put(clazz.name, clazz);
33+
}
34+
}
35+
}
36+
}

src/main/java/com/github/kayjamlang/core/expressions/UseExpression.java

+13
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@
33
import com.github.kayjamlang.core.opcodes.AccessIdentifier;
44

55
public class UseExpression extends Expression {
6+
7+
public final String from;
8+
9+
public UseExpression(String from, int line){
10+
super(AccessIdentifier.NONE, line);
11+
this.from = from;
12+
expression = null;
13+
}
14+
15+
@Deprecated
616
public final Expression expression;
717

18+
@Deprecated
819
public UseExpression(Expression expression, int line) {
920
super(AccessIdentifier.NONE, line);
1021
this.expression = expression;
22+
this.from = null;
1123
}
1224

25+
@Deprecated
1326
public interface UseInterface{
1427
Expression getExpression(String path) throws Exception;
1528
}

src/test/java/com/github/kayjamlang/tests/containers/classes/AnonymousObjectContainerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void prepare(){
2020

2121
@Test
2222
public void test() throws Exception {
23-
Expression expression = parser.readExpression();
23+
Expression expression = parser.readTopExpression();
2424

2525
assertNotNull(expression);
2626
assertSame(ObjectContainer.class, expression.getClass());

src/test/java/com/github/kayjamlang/tests/containers/classes/ClassContainerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void prepare(){
2020

2121
@Test
2222
public void test() throws Exception {
23-
Expression expression = parser.readExpression();
23+
Expression expression = parser.readTopExpression();
2424

2525
assertNotNull(expression);
2626
assertSame(ClassContainer.class, expression.getClass());

src/test/java/com/github/kayjamlang/tests/containers/classes/ClassExtendsContainerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void prepare(){
2020

2121
@Test
2222
public void test() throws Exception {
23-
Expression expression = parser.readExpression();
23+
Expression expression = parser.readTopExpression();
2424

2525
assertNotNull(expression);
2626
assertSame(ClassContainer.class, expression.getClass());

src/test/java/com/github/kayjamlang/tests/containers/classes/ClassExtendsImplementsContainerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void prepare(){
2020

2121
@Test
2222
public void test() throws Exception {
23-
Expression expression = parser.readExpression();
23+
Expression expression = parser.readTopExpression();
2424

2525
assertNotNull(expression);
2626
assertSame(ClassContainer.class, expression.getClass());

src/test/java/com/github/kayjamlang/tests/containers/classes/ClassImplementsContainerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void prepare(){
2020

2121
@Test
2222
public void test() throws Exception {
23-
Expression expression = parser.readExpression();
23+
Expression expression = parser.readTopExpression();
2424

2525
assertNotNull(expression);
2626
assertSame(ClassContainer.class, expression.getClass());

src/test/java/com/github/kayjamlang/tests/containers/classes/CloneClassContainerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void prepare(){
2020

2121
@Test
2222
public void test() throws Exception {
23-
Expression expression = parser.readExpression();
23+
Expression expression = parser.readTopExpression();
2424

2525
assertNotNull(expression);
2626
assertSame(ClassContainer.class, expression.getClass());

src/test/java/com/github/kayjamlang/tests/containers/classes/ObjectContainerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void prepare(){
2020

2121
@Test
2222
public void test() throws Exception {
23-
Expression expression = parser.readExpression();
23+
Expression expression = parser.readTopExpression();
2424

2525
assertNotNull(expression);
2626
assertSame(ObjectContainer.class, expression.getClass());

src/test/java/com/github/kayjamlang/tests/expressions/UseExpressionTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void prepare(){
2121

2222
@Test
2323
public void test() throws Exception {
24-
Expression expression = parser.readExpression();
24+
Expression expression = parser.readTopExpression();
2525

2626
assertNotNull(expression);
2727
assertSame(UseExpression.class, expression.getClass());

0 commit comments

Comments
 (0)