-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AbstractExpression and TreeRenderer.
- Loading branch information
Showing
16 changed files
with
500 additions
and
10 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
44 changes: 44 additions & 0 deletions
44
src/main/java/co/icecave/dialekt/ast/AbstractExpression.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,44 @@ | ||
package co.icecave.dialekt.ast; | ||
|
||
import co.icecave.dialekt.parser.Token; | ||
|
||
/** | ||
* A base class providing common functionality for expressions. | ||
*/ | ||
public abstract class AbstractExpression implements ExpressionInterface | ||
{ | ||
/** | ||
* Fetch the first token from the source that is part of this expression. | ||
* | ||
* @return The first token from this expression. | ||
*/ | ||
public Token firstToken() | ||
{ | ||
return this.firstToken; | ||
} | ||
|
||
/** | ||
* Fetch the last token from the source that is part of this expression. | ||
* | ||
* @return The last token from this expression. | ||
*/ | ||
public Token lastToken() | ||
{ | ||
return this.lastToken; | ||
} | ||
|
||
/** | ||
* Set the delimiting tokens for this expression. | ||
* | ||
* @param firstToken The first token from this expression. | ||
* @param lastToken The last token from this expression. | ||
*/ | ||
public void setTokens(Token firstToken, Token lastToken) | ||
{ | ||
this.firstToken = firstToken; | ||
this.lastToken = lastToken; | ||
} | ||
|
||
private Token firstToken; | ||
private Token lastToken; | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/java/co/icecave/dialekt/ast/ExpressionInterface.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 |
---|---|---|
@@ -1,10 +1,25 @@ | ||
package co.icecave.dialekt.ast; | ||
|
||
import co.icecave.dialekt.parser.Token; | ||
|
||
/** | ||
* An AST node that is an expression. | ||
* | ||
* Not all nodes in the tree represent an entire (sub-)expression. | ||
*/ | ||
public interface ExpressionInterface extends NodeInterface | ||
{ | ||
/** | ||
* Fetch the first token from the source that is part of this expression. | ||
* | ||
* @return The first token from this expression. | ||
*/ | ||
public Token firstToken(); | ||
|
||
/** | ||
* Fetch the last token from the source that is part of this expression. | ||
* | ||
* @return The last token from this expression. | ||
*/ | ||
public Token lastToken(); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package co.icecave.dialekt.parser; | ||
|
||
public class Token | ||
{ | ||
// const WILDCARD_CHARACTER = '*'; | ||
|
||
// const LOGICAL_AND = 1; | ||
// const LOGICAL_OR = 2; | ||
// const LOGICAL_NOT = 3; | ||
// const STRING = 4; | ||
// const OPEN_BRACKET = 6; | ||
// const CLOSE_BRACKET = 7; | ||
|
||
// public function __construct( | ||
// $type, | ||
// $value, | ||
// $startOffset, | ||
// $endOffset, | ||
// $lineNumber, | ||
// $columnNumber | ||
// ) { | ||
// $this->type = $type; | ||
// $this->value = $value; | ||
// $this->startOffset = $startOffset; | ||
// $this->endOffset = $endOffset; | ||
// $this->lineNumber = $lineNumber; | ||
// $this->columnNumber = $columnNumber; | ||
// } | ||
|
||
// public static function typeDescription($type) | ||
// { | ||
// switch ($type) { | ||
// case self::LOGICAL_AND: | ||
// return 'AND operator'; | ||
// case self::LOGICAL_OR: | ||
// return 'OR operator'; | ||
// case self::LOGICAL_NOT: | ||
// return 'NOT operator'; | ||
// case self::STRING: | ||
// return 'tag'; | ||
// case self::OPEN_BRACKET: | ||
// return 'open bracket'; | ||
// case self::CLOSE_BRACKET: | ||
// return 'close bracket'; | ||
// }; | ||
|
||
// throw new LogicException('Unknown type.'); | ||
// } | ||
|
||
// public $type; | ||
// public $value; | ||
// public $startOffset; | ||
// public $endOffset; | ||
// public $lineNumber; | ||
// public $columnNumber; | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/main/java/co/icecave/dialekt/renderer/RendererInterface.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,15 @@ | ||
package co.icecave.dialekt.renderer; | ||
|
||
import co.icecave.dialekt.ast.ExpressionInterface; | ||
|
||
public interface RendererInterface | ||
{ | ||
/** | ||
* Render an expression to a string. | ||
* | ||
* @param expression The expression to render. | ||
* | ||
* @return The rendered expression. | ||
*/ | ||
public String render(ExpressionInterface expression); | ||
} |
Oops, something went wrong.