miksilo.modularLanguages.deltas.expression.IntLiteralDelta.scala Maven / Gradle / Ivy
The newest version!
package miksilo.modularLanguages.deltas.expression
import miksilo.modularLanguages.core.deltas._
import miksilo.modularLanguages.core.deltas.grammars.LanguageGrammars
import miksilo.modularLanguages.core.deltas.path.NodePath
import miksilo.modularLanguages.core.node.{Node, NodeField, NodeShape}
import miksilo.languageServer.core.language.{Compilation, Language}
import miksilo.languageServer.core.smarts.ConstraintBuilder
import miksilo.languageServer.core.smarts.scopes.objects.Scope
import miksilo.languageServer.core.smarts.types.objects.Type
import miksilo.modularLanguages.deltas.bytecode.types.IntTypeDelta
object IntLiteralDelta extends DeltaWithGrammar with ExpressionInstance {
val shape = Shape
override def dependencies: Set[Contract] = Set(ExpressionDelta)
override def transformGrammars(grammars: LanguageGrammars, state: Language): Unit = {
import grammars._
val inner = integer
val parseNumber = inner.as(Value).asLabelledNode(Shape)
find(ExpressionDelta.LastPrecedenceGrammar).addAlternative(parseNumber)
}
def neww(value: Int) = new Node(Shape, Value -> value)
def getValue(literal: Node): Int = literal(Value).asInstanceOf[Int]
object Shape extends NodeShape
object Value extends NodeField
override def description: String = "Adds the usage of int literals."
override def constraints(compilation: Compilation, builder: ConstraintBuilder, expression: NodePath, _type: Type, parentScope: Scope): Unit = {
builder.typesAreEqual(_type, IntTypeDelta.constraintType)
}
}