-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
293 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/com/github/kayjamlang/core/KayJamIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
328
src/main/java/com/github/kayjamlang/core/KayJamParser.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/github/kayjamlang/core/containers/Script.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters