25. EnFun: Entities with Functions
module blog
entity String {
function plus(that:String): String
}
entity Bool { }
entity Set<T> {
function add(x: T)
function remove(x: T)
function member(x: T): Bool
}
entity Blog {
posts : Set<Post>
function newPost(): Post {
var p : Post := Post.new();
posts.add(p);
}
}
entity Post {
title : String
}
40. Declarative Syntax Definition
Entity("User", [
Property("first", Type("String")),
Property("last", Type("String"))
])
signature
constructors
Entity : ID * List(Property) -> Definition
Type : ID -> Type
Property : ID * Type -> Property
41. Declarative Syntax Definition
entity User { Entity("User", [
first : String Property("first", Type("String")),
last : String Property("last", Type("String"))
} ])
signature
constructors
Entity : ID * List(Property) -> Definition
Type : ID -> Type
Property : ID * Type -> Property
42. Declarative Syntax Definition
context-free syntax
"entity" ID "{" Property* "}" -> Definition {"Entity"}
ID -> Type {"Type"}
ID ":" Type -> Property {"Property"}
entity User { Entity("User", [
first : String Property("first", Type("String")),
last : String Property("last", Type("String"))
} ])
signature
constructors
Entity : ID * List(Property) -> Definition
Type : ID -> Type
Property : ID * Type -> Property
43. Declarative Syntax Definition
context-free syntax
"entity" ID "{" Property* "}" -> Definition {"Entity"}
ID -> Type {"Type"}
ID ":" Type -> Property {"Property"}
entity User { Entity("User", [
first : String Property("first", Type("String")),
last : String Property("last", Type("String"))
} ])
signature
constructors
Entity : ID * List(Property) -> Definition
Type : ID -> Type
Property : ID * Type -> Property
69. Types of Names
rules // names
type-of :
Var(x) -> <lookup-type> x
type-of :
|[ e.x ]| -> t
where <lookup-type> x => t
type-of :
|[ e.x(e*) ]| -> t
where <lookup-type> x => (t*, t)
type-of :
|[ f(e*) ]| -> t
where <lookup-type> f => (t*, t)
71. Definitions and References
definition
test type refers to entity [[
module test
entity [[String]] { }
entity User {
first : [[String]]
last : String
}
]] resolve #2 to #1
reference
72. From Tree to Graph
Module(
"test"
, [ Entity("String", [])
, Entity(
"User"
, [ Property("first", )
, Property("last", )
]
)
]
)
74. Spoofax Name Binding Language
namespaces Module Type See the full story in
SLE talk on Friday
rules
Entity(c, _) :
defines Type c
Type(x, _) :
refers to Type x
Module(m, _) :
defines Module m
scopes Type
Imports(m) :
imports Type from Module m
abstract from name resolution algorithmics