-
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.
refactor: split up ast into multiple files
- Loading branch information
1 parent
10f9150
commit 788497c
Showing
8 changed files
with
535 additions
and
526 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package java2typescript.ast | ||
|
||
case class ClassDeclaration( | ||
name: Identifier, | ||
typeParameters: List[Type] = List(), | ||
heritageClauses: List[HeritageClause] = List(), | ||
members: List[Member] = List(), | ||
modifiers: List[Modifier] = List() | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.ClassDeclaration | ||
} | ||
|
||
case class VariableDeclaration( | ||
name: Identifier, | ||
`type`: Option[Type], | ||
initializer: Option[Expression] = None | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.VariableDeclaration | ||
} | ||
|
||
case class InterfaceDeclaration( | ||
name: Identifier, | ||
typeParameters: List[Type] = List(), | ||
heritageClauses: List[HeritageClause] = List(), | ||
members: List[Member] = List(), | ||
modifiers: List[Modifier] = List() | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.InterfaceDeclaration | ||
} | ||
|
||
case class EnumDeclaration( | ||
name: Identifier, | ||
members: List[Member] = List(), | ||
modifiers: List[Modifier] = List() | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.EnumDeclaration | ||
} | ||
|
||
case class ImportDeclaration( | ||
importClause: ImportClause, | ||
moduleSpecifier: StringLiteral | ||
) extends Node { | ||
val kind: SyntaxKind = SyntaxKind.ImportDeclaration | ||
} | ||
|
||
case class FunctionDeclaration( | ||
name: Identifier, | ||
`type`: Option[Type], | ||
parameters: List[Parameter] = List(), | ||
typeParameters: List[Type] = List(), | ||
body: Option[Block] = None, | ||
modifiers: List[Modifier] = List(), | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.FunctionDeclaration | ||
} |
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,104 @@ | ||
package java2typescript.ast | ||
|
||
trait Expression extends Node | ||
|
||
case class ArrayLiteralExpression( | ||
elements: List[Expression] | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.ArrayLiteralExpression | ||
} | ||
|
||
case class PropertyAccessExpression( | ||
expression: Expression, | ||
name: Identifier | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.PropertyAccessExpression | ||
} | ||
|
||
case class ElementAccessExpression( | ||
expression: Expression, | ||
argumentExpression: Expression | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.ElementAccessExpression | ||
} | ||
|
||
case class CallExpression( | ||
expression: Expression, | ||
arguments: List[Expression] = List(), | ||
typeArguments: List[Type] = List() | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.CallExpression | ||
} | ||
|
||
case class NewExpression ( | ||
expression: Identifier, | ||
arguments: List[Expression] = List(), | ||
typeArguments: List[Type] = List() | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.NewExpression | ||
} | ||
|
||
case class ParenthesizedExpression( | ||
expression: Expression | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.ParenthesizedExpression | ||
} | ||
|
||
case class TypeOfExpression( | ||
expression: Expression | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.TypeOfExpression | ||
} | ||
|
||
case class PrefixUnaryExpression( | ||
operator: SyntaxKind, | ||
operand: Expression | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.PrefixUnaryExpression | ||
} | ||
|
||
case class PostfixUnaryExpression( | ||
operator: SyntaxKind, | ||
operand: Expression | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.PostfixUnaryExpression | ||
} | ||
|
||
case class BinaryExpression( | ||
left: Expression, | ||
right: Expression, | ||
operatorToken: Token | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.BinaryExpression | ||
} | ||
|
||
case class ConditionalExpression( | ||
condition: Expression, | ||
whenTrue: Expression, | ||
whenFalse: Expression, | ||
) extends Expression { | ||
val questionToken: QuestionToken = QuestionToken() | ||
val colonToken: ColonToken = ColonToken() | ||
val kind: SyntaxKind = SyntaxKind.ConditionalExpression | ||
} | ||
|
||
case class ExpressionWithTypeArguments( | ||
expression: Expression, | ||
typeArguments: List[Type] = List() | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.ExpressionWithTypeArguments | ||
} | ||
|
||
case class AsExpression( | ||
expression: Expression, | ||
`type`: Type | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.AsExpression | ||
} | ||
|
||
case class VariableDeclarationList( | ||
declarations: List[VariableDeclaration], | ||
override val flags: Int = 1 // 1 = Let | ||
) extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.VariableDeclarationList | ||
} |
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,80 @@ | ||
package java2typescript.ast | ||
|
||
// Keyword | ||
|
||
case class ExportKeyword() extends Modifier { | ||
val kind: SyntaxKind = SyntaxKind.ExportKeyword | ||
} | ||
|
||
case class ExtendsKeyword() extends Token { | ||
val kind: SyntaxKind = SyntaxKind.ExtendsKeyword | ||
} | ||
|
||
case class FalseKeyword() extends Literal { | ||
val kind: SyntaxKind = SyntaxKind.FalseKeyword | ||
} | ||
|
||
case class InstanceOfKeyword() extends Token { | ||
val kind: SyntaxKind = SyntaxKind.InstanceOfKeyword | ||
} | ||
|
||
case class NullKeyword() extends Literal { | ||
val kind: SyntaxKind = SyntaxKind.NullKeyword | ||
} | ||
|
||
case class SuperKeyword() extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.SuperKeyword | ||
} | ||
|
||
case class ThisKeyword() extends Expression { | ||
val kind: SyntaxKind = SyntaxKind.ThisKeyword | ||
} | ||
|
||
case class TrueKeyword() extends Literal { | ||
val kind: SyntaxKind = SyntaxKind.TrueKeyword | ||
} | ||
|
||
case class VoidKeyword() extends Type { | ||
val kind: SyntaxKind = SyntaxKind.VoidKeyword | ||
} | ||
|
||
case class ImplementsKeyword() extends Token { | ||
val kind: SyntaxKind = SyntaxKind.ImplementsKeyword | ||
} | ||
|
||
case class PrivateKeyword() extends Modifier { | ||
val kind: SyntaxKind = SyntaxKind.PrivateKeyword | ||
} | ||
|
||
case class ProtectedKeyword() extends Modifier { | ||
val kind: SyntaxKind = SyntaxKind.ProtectedKeyword | ||
} | ||
|
||
case class PublicKeyword() extends Modifier { | ||
val kind: SyntaxKind = SyntaxKind.PublicKeyword | ||
} | ||
|
||
case class StaticKeyword() extends Modifier { | ||
val kind: SyntaxKind = SyntaxKind.StaticKeyword | ||
} | ||
|
||
case class AbstractKeyword() extends Modifier { | ||
val kind: SyntaxKind = SyntaxKind.AbstractKeyword | ||
} | ||
|
||
case class AnyKeyword() extends Type { | ||
val kind: SyntaxKind = SyntaxKind.AnyKeyword | ||
} | ||
|
||
case class BooleanKeyword() extends Type { | ||
val kind: SyntaxKind = SyntaxKind.BooleanKeyword | ||
} | ||
|
||
case class NumberKeyword() extends Type { | ||
val kind: SyntaxKind = SyntaxKind.NumberKeyword | ||
} | ||
|
||
case class StringKeyword() extends Type { | ||
val kind: SyntaxKind = SyntaxKind.StringKeyword | ||
} | ||
|
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,14 @@ | ||
package java2typescript.ast | ||
|
||
trait Literal extends Expression | ||
|
||
case class NumericLiteral(text: String) extends Literal { | ||
val kind: SyntaxKind = SyntaxKind.NumericLiteral | ||
} | ||
|
||
case class StringLiteral( | ||
text: String | ||
) extends Literal { | ||
val kind: SyntaxKind = SyntaxKind.StringLiteral | ||
val hasExtendedUnicodeEscape = false | ||
} |
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,38 @@ | ||
package java2typescript.ast | ||
|
||
trait Member extends Node | ||
|
||
case class PropertyDeclaration( | ||
name: Identifier, | ||
`type`: Option[Type], | ||
initializer: Option[Expression], | ||
modifiers: List[Modifier] = List() | ||
) extends Member { | ||
val kind: SyntaxKind = SyntaxKind.PropertyDeclaration | ||
} | ||
|
||
case class MethodDeclaration( | ||
name: Identifier, | ||
`type`: Option[Type], | ||
parameters: List[Parameter] = List(), | ||
typeParameters: List[Type] = List(), | ||
body: Option[Block] = None, | ||
modifiers: List[Modifier] = List(), | ||
) extends Member { | ||
val kind: SyntaxKind = SyntaxKind.MethodDeclaration | ||
} | ||
|
||
case class Constructor( | ||
parameters: List[Parameter] = List(), | ||
body: Option[Block] = None, | ||
modifiers: List[Modifier] = List(), | ||
) extends Member { | ||
val kind: SyntaxKind = SyntaxKind.Constructor | ||
override val flags: Int = 66048 | ||
} | ||
|
||
case class EnumMember( | ||
name: Identifier | ||
) extends Member { | ||
val kind: SyntaxKind = SyntaxKind.EnumMember | ||
} |
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,101 @@ | ||
package java2typescript.ast | ||
|
||
trait Statement extends Node | ||
|
||
case class Block( | ||
statements: List[Statement] | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.Block | ||
val multiLine: Boolean = true | ||
} | ||
|
||
case class VariableStatement( | ||
declarationList: VariableDeclarationList | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.VariableStatement | ||
} | ||
|
||
case class ExpressionStatement( | ||
expression: Expression | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.ExpressionStatement | ||
} | ||
|
||
case class IfStatement( | ||
expression: Expression, | ||
thenStatement: Statement, | ||
elseStatement: Option[Statement] = None | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.IfStatement | ||
} | ||
|
||
case class DoStatement( | ||
statement: Statement, | ||
expression: Expression | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.DoStatement | ||
} | ||
|
||
case class WhileStatement( | ||
expression: Expression, | ||
statement: Statement | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.WhileStatement | ||
} | ||
|
||
case class ForStatement( | ||
initializer: Option[Expression], | ||
condition: Option[Expression], | ||
incrementor: Option[Expression], | ||
statement: Statement | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.ForStatement | ||
} | ||
|
||
case class ForOfStatement( | ||
initializer: VariableDeclarationList, | ||
expression: Expression, | ||
statement: Statement | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.ForOfStatement | ||
} | ||
|
||
case class ContinueStatement() extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.ContinueStatement | ||
} | ||
|
||
case class BreakStatement() extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.BreakStatement | ||
} | ||
|
||
case class ReturnStatement( | ||
expression: Option[Expression] | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.ReturnStatement | ||
} | ||
|
||
case class SwitchStatement( | ||
expression: Expression, | ||
caseBlock: CaseBlock | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.SwitchStatement | ||
} | ||
|
||
case class ThrowStatement( | ||
expression: Expression | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.ThrowStatement | ||
} | ||
|
||
case class TryStatement( | ||
tryBlock: Block, | ||
catchClause: Option[CatchClause], | ||
finallyBlock: Option[Block] | ||
) extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.TryStatement | ||
} | ||
|
||
case class EmptyStatement() extends Statement { | ||
val kind: SyntaxKind = SyntaxKind.EmptyStatement | ||
} | ||
|
Oops, something went wrong.