-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[interval] Implements basic interval
- Loading branch information
Showing
12 changed files
with
268 additions
and
28 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,8 @@ public enum TokenType { | |
BRACKET_LEFT, | ||
BRACKET_RIGHT, | ||
DOUBLE_POINT, | ||
DOT, | ||
DOT, | ||
DOT_DOT, | ||
ARROW, | ||
END_OF_FILE, | ||
} |
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
81 changes: 81 additions & 0 deletions
81
src/main/java/leekscript/compiler/expression/LeekInterval.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,81 @@ | ||
package leekscript.compiler.expression; | ||
|
||
import leekscript.common.Type; | ||
import leekscript.compiler.Hover; | ||
import leekscript.compiler.Token; | ||
import leekscript.compiler.JavaWriter; | ||
import leekscript.compiler.Location; | ||
import leekscript.compiler.WordCompiler; | ||
import leekscript.compiler.bloc.MainLeekBlock; | ||
import leekscript.compiler.exceptions.LeekCompilerException; | ||
|
||
public class LeekInterval extends Expression { | ||
|
||
private Expression mFrom; | ||
private Expression mTo; | ||
private Token openingBracket; | ||
private Token closingBracket; | ||
|
||
public LeekInterval(Token openingBracket, Expression from, Expression to, Token closingBracket) { | ||
this.openingBracket = openingBracket; | ||
this.closingBracket = closingBracket; | ||
this.mFrom = from; | ||
this.mTo = to; | ||
|
||
openingBracket.setExpression(this); | ||
closingBracket.setExpression(this); | ||
} | ||
|
||
@Override | ||
public int getNature() { | ||
return ARRAY; | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.INTERVAL; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[" + mFrom + ".." + mTo + "]"; | ||
} | ||
|
||
@Override | ||
public boolean validExpression(WordCompiler compiler, MainLeekBlock mainBlock) throws LeekExpressionException { | ||
return mFrom.validExpression(compiler, mainBlock) && mTo.validExpression(compiler, mainBlock); | ||
} | ||
|
||
@Override | ||
public void preAnalyze(WordCompiler compiler) throws LeekCompilerException { | ||
mFrom.preAnalyze(compiler); | ||
mTo.preAnalyze(compiler); | ||
} | ||
|
||
@Override | ||
public void analyze(WordCompiler compiler) throws LeekCompilerException { | ||
operations = 2 + mFrom.getOperations() + mTo.getOperations(); | ||
mFrom.analyze(compiler); | ||
mTo.analyze(compiler); | ||
} | ||
|
||
@Override | ||
public void writeJavaCode(MainLeekBlock mainBlock, JavaWriter writer) { | ||
writer.addCode("new IntervalLeekValue(" + writer.getAIThis() + ", "); | ||
mFrom.writeJavaCode(mainBlock, writer); | ||
writer.addCode(", "); | ||
mTo.writeJavaCode(mainBlock, writer); | ||
writer.addCode(")"); | ||
} | ||
|
||
@Override | ||
public Location getLocation() { | ||
return new Location(openingBracket.getLocation(), closingBracket.getLocation()); | ||
} | ||
|
||
@Override | ||
public Hover hover(Token token) { | ||
var hover = new Hover(getType(), getLocation(), toString()); | ||
return hover; | ||
} | ||
} |
Oops, something went wrong.