Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from definiti/57-improve-helpers
57 improve helpers
- Loading branch information
Showing
138 changed files
with
1,945 additions
and
2,938 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
src/main/scala/definiti/common/ast/ClassDefinition.scala
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,108 @@ | ||
package definiti.common.ast | ||
|
||
sealed trait ClassDefinition extends NamespaceElement { | ||
def name: String | ||
|
||
def fullName: String | ||
|
||
def genericTypes: Seq[String] | ||
} | ||
|
||
sealed trait ProjectClassDefinition extends ClassDefinition { | ||
def comment: Option[String] | ||
|
||
def location: Location | ||
} | ||
|
||
case class DefinedType( | ||
name: String, | ||
fullName: String, | ||
genericTypes: Seq[String], | ||
parameters: Seq[ParameterDefinition], | ||
attributes: Seq[AttributeDefinition], | ||
verifications: Seq[TypeVerification], | ||
inherited: Seq[VerificationReference], | ||
comment: Option[String], | ||
location: Location | ||
) extends ProjectClassDefinition | ||
|
||
case class AliasType( | ||
name: String, | ||
fullName: String, | ||
genericTypes: Seq[String], | ||
parameters: Seq[ParameterDefinition], | ||
alias: TypeDeclaration, | ||
inherited: Seq[VerificationReference], | ||
verifications: Seq[TypeVerification], | ||
comment: Option[String], | ||
location: Location | ||
) extends ProjectClassDefinition | ||
|
||
sealed trait TypeVerification { | ||
def message: VerificationMessage | ||
|
||
def function: DefinedFunction | ||
|
||
def location: Location | ||
} | ||
|
||
case class AtomicTypeVerification( | ||
message: VerificationMessage, | ||
function: DefinedFunction, | ||
location: Location | ||
) extends TypeVerification | ||
|
||
case class DependentTypeVerification( | ||
name: String, | ||
message: VerificationMessage, | ||
function: DefinedFunction, | ||
location: Location | ||
) extends TypeVerification | ||
|
||
case class Enum( | ||
name: String, | ||
fullName: String, | ||
cases: Seq[EnumCase], | ||
comment: Option[String], | ||
location: Location | ||
) extends ProjectClassDefinition { | ||
override def genericTypes: Seq[String] = Seq.empty | ||
} | ||
|
||
|
||
case class NativeClassDefinition( | ||
name: String, | ||
fullName: String, | ||
genericTypes: Seq[String], | ||
attributes: Seq[AttributeDefinition], | ||
methods: Seq[MethodDefinition], | ||
comment: Option[String] | ||
) extends ClassDefinition | ||
|
||
case class EnumCase( | ||
name: String, | ||
comment: Option[String], | ||
location: Location | ||
) | ||
|
||
case class AttributeDefinition( | ||
name: String, | ||
typeDeclaration: TypeDeclaration, | ||
comment: Option[String], | ||
verifications: Seq[VerificationReference], | ||
location: Location | ||
) | ||
|
||
case class MethodDefinition( | ||
name: String, | ||
genericTypes: Seq[String], | ||
parameters: Seq[ParameterDefinition], | ||
returnType: TypeReference, | ||
comment: Option[String] | ||
) | ||
|
||
case class VerificationReference( | ||
verificationName: String, | ||
parameters: Seq[AtomicExpression], | ||
location: Location | ||
) |
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,7 @@ | ||
package definiti.common.ast | ||
|
||
case class ExtendedContext[A]( | ||
name: String, | ||
content: A, | ||
location: Location | ||
) extends NamespaceElement |
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
2 changes: 1 addition & 1 deletion
2
...in/scala/definiti/core/ast/Location.scala → .../scala/definiti/common/ast/Location.scala
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,4 +1,4 @@ | ||
package definiti.core.ast | ||
package definiti.common.ast | ||
|
||
case class Location( | ||
file: String, | ||
|
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,11 @@ | ||
package definiti.common.ast | ||
|
||
case class NamedFunction( | ||
name: String, | ||
fullName: String, | ||
genericTypes: Seq[String], | ||
parameters: Seq[ParameterDefinition], | ||
returnType: TypeReference, | ||
body: Expression, | ||
location: Location | ||
) extends NamespaceElement |
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,7 @@ | ||
package definiti.common.ast | ||
|
||
case class ParameterDefinition( | ||
name: String, | ||
typeReference: AbstractTypeReference, | ||
location: Location | ||
) |
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,13 @@ | ||
package definiti.common.ast | ||
|
||
case class Root( | ||
namespaces: Seq[Namespace] | ||
) | ||
|
||
case class Namespace( | ||
name: String, | ||
fullName: String, | ||
elements: Seq[NamespaceElement] | ||
) | ||
|
||
trait NamespaceElement |
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,50 @@ | ||
package definiti.common.ast | ||
|
||
sealed trait AbstractTypeReference { | ||
def readableString: String | ||
} | ||
|
||
case object Unset extends AbstractTypeReference { | ||
override def readableString: String = "***Unset***" | ||
} | ||
|
||
case class TypeReference( | ||
typeName: String, | ||
genericTypes: Seq[TypeReference] = Seq.empty | ||
) extends AbstractTypeReference { | ||
def readableString: String = { | ||
if (genericTypes.nonEmpty) { | ||
s"$typeName[${genericTypes.map(_.readableString).mkString(",")}]" | ||
} else { | ||
typeName | ||
} | ||
} | ||
} | ||
|
||
case class LambdaReference( | ||
inputTypes: Seq[TypeReference], | ||
outputType: TypeReference | ||
) extends AbstractTypeReference { | ||
def readableString: String = s"(${inputTypes.map(_.readableString).mkString(", ")}) => ${outputType.readableString}" | ||
} | ||
|
||
case class NamedFunctionReference( | ||
functionName: String | ||
) extends AbstractTypeReference { | ||
def readableString: String = functionName | ||
} | ||
|
||
case class TypeDeclaration( | ||
typeName: String, | ||
genericTypes: Seq[TypeDeclaration], | ||
parameters: Seq[AtomicExpression], | ||
location: Location | ||
) { | ||
def readableString: String = { | ||
if (genericTypes.nonEmpty) { | ||
s"$typeName[${genericTypes.map(_.readableString).mkString(", ")}]" | ||
} else { | ||
typeName | ||
} | ||
} | ||
} |
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,32 @@ | ||
package definiti.common.ast | ||
|
||
case class Verification( | ||
name: String, | ||
fullName: String, | ||
parameters: Seq[ParameterDefinition], | ||
message: VerificationMessage, | ||
function: DefinedFunction, | ||
comment: Option[String], | ||
location: Location | ||
) extends NamespaceElement | ||
|
||
sealed trait VerificationMessage { | ||
def prettyPrint: String | ||
} | ||
|
||
case class LiteralMessage(message: String, location: Location) extends VerificationMessage { | ||
override def prettyPrint: String = message | ||
} | ||
|
||
case class TypedMessage(message: String, types: Seq[TypeReference], location: Location) extends VerificationMessage { | ||
override def prettyPrint: String = { | ||
if (types.nonEmpty) { | ||
s"""message("${message}", ${types.map(_.readableString).mkString(", ")})""" | ||
} else { | ||
s"""message("${message}")""" | ||
} | ||
|
||
} | ||
} | ||
|
||
case class DefinedFunction(parameters: Seq[ParameterDefinition], body: Expression, genericTypes: Seq[String], location: Location) |
6 changes: 3 additions & 3 deletions
6
...la/definiti/core/validation/Control.scala → ...ala/definiti/common/control/Control.scala
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
6 changes: 3 additions & 3 deletions
6
...initi/core/validation/ControlResult.scala → ...finiti/common/control/ControlResult.scala
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,17 @@ | ||
package definiti.common.plugin | ||
|
||
import definiti.common.ast.{Library, Location} | ||
import definiti.common.program.ProgramResult.NoResult | ||
import definiti.common.validation.Validated | ||
|
||
trait ContextPlugin[A] extends Plugin { | ||
def contextName: String | ||
|
||
def parse(content: String, packageName: String, imports: Map[String, String], location: Location): A | ||
|
||
def validate(context: A, library: Library): Validated[NoResult] | ||
|
||
def contextToJson(context: A): String | ||
|
||
def contextFromJson(json: String): A | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/scala/definiti/common/plugin/GeneratorPlugin.scala
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,10 @@ | ||
package definiti.common.plugin | ||
|
||
import java.nio.file.Path | ||
|
||
import definiti.common.ast.{Library, Root} | ||
|
||
trait GeneratorPlugin extends Plugin { | ||
def generate(root: Root, library: Library): Map[Path, String] | ||
} | ||
|
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,8 @@ | ||
package definiti.common.plugin | ||
|
||
import definiti.common.ast.Root | ||
import definiti.common.validation.Validated | ||
|
||
trait ParserPlugin extends Plugin { | ||
def transform(root: Root): Validated[Root] | ||
} |
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,5 @@ | ||
package definiti.common.plugin | ||
|
||
trait Plugin { | ||
def name: String | ||
} |
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,9 @@ | ||
package definiti.common.plugin | ||
|
||
import definiti.common.ast.{Library, Root} | ||
import definiti.common.program.ProgramResult.NoResult | ||
import definiti.common.validation.Validated | ||
|
||
trait ValidatorPlugin extends Plugin { | ||
def validate(root: Root, library: Library): Validated[NoResult] | ||
} |
Oops, something went wrong.