@@ -2,13 +2,6 @@ package chapi.domain.expr
22
33// todo: mapping to pratt parser ?
44// mini sample <https://github.com/segeljakt/pratt>
5- //
6- // enum class TokenTree {
7- // Primary,
8- // Prefix,
9- // Infix,
10- // Postfix;
11- // }
125sealed class Expression {
136 class BinOp (val lhs : ExpressionNode , val op : BinOpKind , val rhs : ExpressionNode ) : ExpressionNode {
147 override fun toString () = " $lhs $op $rhs "
@@ -22,10 +15,26 @@ sealed class Expression {
2215 override fun toString () = value.toString()
2316 }
2417
18+ class FloatValue (val value : Float ) : ExpressionNode {
19+ override fun toString () = value.toString()
20+ }
21+
22+ class StringValue (val value : String ) : ExpressionNode {
23+ override fun toString () = value
24+ }
25+
2526 class Variable (val name : String ) : ExpressionNode {
2627 override fun toString () = name
2728 }
2829
30+ class TryCatch (val tryBlock : ExpressionNode , val catchBlock : ExpressionNode ) : ExpressionNode {
31+ override fun toString () = " try { $tryBlock } catch { $catchBlock }"
32+ }
33+
34+ class IfElse (val condition : ExpressionNode , val thenBlock : ExpressionNode , val elseBlock : ExpressionNode ) : ExpressionNode {
35+ override fun toString () = " if ($condition ) { $thenBlock } else { $elseBlock }"
36+ }
37+
2938 class Identifier (val name : String ) : ExpressionNode {
3039 override fun toString () = name
3140 }
@@ -45,6 +54,10 @@ sealed class Expression {
4554 override fun toString () = args.joinToString(" , " )
4655 }
4756
57+ class ArrayLiteral (val args : kotlin.Array <ExpressionNode >) : ExpressionNode {
58+ override fun toString () = " [${args.joinToString(" , " )} ]"
59+ }
60+
4861 class CustomValueType (val value : ValueType ) : ExpressionNode
4962
5063}
0 commit comments