Skip to content

Commit

Permalink
Improved code reuse and fixed some incorrect tag names in XML code ge…
Browse files Browse the repository at this point in the history
…neration.

Added normalization step to lua/XML code generation that adds required plugins and components.
Updated type data files from the DSLTypeExtractor to the newest version.
  • Loading branch information
Gohla committed Jul 19, 2011
1 parent 6fb17f7 commit ed67dc2
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 207 deletions.
43 changes: 29 additions & 14 deletions DSL/DiversiaScript/syntax/data/enum.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ exports
"SmallHail" -> PrecipitationTypeValue {cons("SmallHail")}
"Custom" -> PrecipitationTypeValue {cons("Custom")}

"ClientServerPluginType" -> ClientServerPluginTypeEnumType {cons("ClientServerPluginType")}
ClientServerPluginTypeEnumType -> EnumType
ClientServerPluginTypeEnumType "." ClientServerPluginTypeValue -> Exp {prefer, cons("EnumValueRef")}
"PermissionManager" -> ClientServerPluginTypeValue {cons("PermissionManager")}
"ResourceManager" -> ClientServerPluginTypeValue {cons("ResourceManager")}
"Lua" -> ClientServerPluginTypeValue {cons("Lua")}
"ServerNeighbors" -> ClientServerPluginTypeValue {cons("ServerNeighbors")}
"Sky" -> ClientServerPluginTypeValue {cons("Sky")}
"ObjectTemplateManager" -> ClientServerPluginTypeValue {cons("ObjectTemplateManager")}
"ObjectManager" -> ClientServerPluginTypeValue {cons("ObjectManager")}
"Terrain" -> ClientServerPluginTypeValue {cons("Terrain")}
"GameMode" -> ClientServerPluginTypeValue {cons("GameMode")}
"SceneManager" -> ClientServerPluginTypeValue {cons("SceneManager")}

"ComponentType" -> ComponentTypeEnumType {cons("ComponentType")}
ComponentTypeEnumType -> EnumType
ComponentTypeEnumType "." ComponentTypeValue -> Exp {prefer, cons("EnumValueRef")}
Expand Down Expand Up @@ -325,12 +311,41 @@ exports
"Kinematic" -> PhysicsTypeValue {cons("Kinematic")}
"Dynamic" -> PhysicsTypeValue {cons("Dynamic")}

"PluginType" -> PluginTypeEnumType {cons("PluginType")}
PluginTypeEnumType -> EnumType
PluginTypeEnumType "." PluginTypeValue -> Exp {prefer, cons("EnumValueRef")}
"PermissionManager" -> PluginTypeValue {cons("PermissionManager")}
"ResourceManager" -> PluginTypeValue {cons("ResourceManager")}
"Lua" -> PluginTypeValue {cons("Lua")}
"ServerNeighbors" -> PluginTypeValue {cons("ServerNeighbors")}
"Sky" -> PluginTypeValue {cons("Sky")}
"ObjectTemplateManager" -> PluginTypeValue {cons("ObjectTemplateManager")}
"ObjectManager" -> PluginTypeValue {cons("ObjectManager")}
"Terrain" -> PluginTypeValue {cons("Terrain")}
"GameMode" -> PluginTypeValue {cons("GameMode")}
"SceneManager" -> PluginTypeValue {cons("SceneManager")}
"LevelManager" -> PluginTypeValue {cons("LevelManager")}

"ResourceLocationType" -> ResourceLocationTypeEnumType {cons("ResourceLocationType")}
ResourceLocationTypeEnumType -> EnumType
ResourceLocationTypeEnumType "." ResourceLocationTypeValue -> Exp {prefer, cons("EnumValueRef")}
"FileSystem" -> ResourceLocationTypeValue {cons("FileSystem")}
"URL" -> ResourceLocationTypeValue {cons("URL")}

"ResourceType" -> ResourceTypeEnumType {cons("ResourceType")}
ResourceTypeEnumType -> EnumType
ResourceTypeEnumType "." ResourceTypeValue -> Exp {prefer, cons("EnumValueRef")}
"Generic" -> ResourceTypeValue {cons("Generic")}
"OgreMesh" -> ResourceTypeValue {cons("OgreMesh")}
"BulletMesh" -> ResourceTypeValue {cons("BulletMesh")}
"Skeleton" -> ResourceTypeValue {cons("Skeleton")}
"Texture" -> ResourceTypeValue {cons("Texture")}
"MaterialScript" -> ResourceTypeValue {cons("MaterialScript")}
"ParticleScript" -> ResourceTypeValue {cons("ParticleScript")}
"LuaScript" -> ResourceTypeValue {cons("LuaScript")}
"Audio" -> ResourceTypeValue {cons("Audio")}
"Level" -> ResourceTypeValue {cons("Level")}

"SkyType" -> SkyTypeEnumType {cons("SkyType")}
SkyTypeEnumType -> EnumType
SkyTypeEnumType "." SkyTypeValue -> Exp {prefer, cons("EnumValueRef")}
Expand Down
1 change: 1 addition & 0 deletions DSL/DiversiaScript/syntax/data/plugin.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ exports
"Sky" -> PluginType {cons("Sky")}
"Terrain" -> PluginType {cons("Terrain")}
"SceneManager" -> PluginType {cons("SceneManager")}
"LevelManager" -> PluginType {cons("LevelManager")}
12 changes: 6 additions & 6 deletions DSL/DiversiaScript/syntax/data/type-func.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ exports

context-free syntax

"Run_garbage_collection" -> BuiltinFunction {cons("Run_garbage_collection")}

"ForceSerialize" -> BuiltinFunction {cons("ForceSerialize")}

"CreatePlugin" -> BuiltinFunction {cons("CreatePlugin")}
"GetPlugin" -> BuiltinFunction {cons("GetPlugin")}
"HasPlugin" -> BuiltinFunction {cons("HasPlugin")}
"DestroyPlugin" -> BuiltinFunction {cons("DestroyPlugin")}
"Run_garbage_collection" -> BuiltinFunction {cons("Run_garbage_collection")}

"IsCreatedBy" -> BuiltinFunction {cons("IsCreatedBy")}
"IsCreatedBySource" -> BuiltinFunction {cons("IsCreatedBySource")}
Expand Down Expand Up @@ -115,6 +110,11 @@ exports
"ApplyCentralImpulse" -> BuiltinFunction {cons("ApplyCentralImpulse")}
"ApplyTorque" -> BuiltinFunction {cons("ApplyTorque")}

"CreatePlugin" -> BuiltinFunction {cons("CreatePlugin")}
"GetPlugin" -> BuiltinFunction {cons("GetPlugin")}
"HasPlugin" -> BuiltinFunction {cons("HasPlugin")}
"DestroyPlugin" -> BuiltinFunction {cons("DestroyPlugin")}

"AddServer" -> BuiltinFunction {cons("AddServer")}
"GetServer" -> BuiltinFunction {cons("GetServer")}
"HasServer" -> BuiltinFunction {cons("HasServer")}
Expand Down
37 changes: 21 additions & 16 deletions DSL/DiversiaScript/syntax/data/type-prop.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ exports

"ServerNeighbors" -> BuiltinProperty {cons("ServerNeighbors")}

"Type" -> BuiltinProperty {cons("Type")}
"TypeName" -> BuiltinProperty {cons("TypeName")}
"Mode" -> BuiltinProperty {cons("Mode")}
"PluginManager" -> BuiltinProperty {cons("PluginManager")}

"Mode" -> BuiltinProperty {cons("Mode")}
"Plugins" -> BuiltinProperty {cons("Plugins")}

"WorldSize" -> BuiltinProperty {cons("WorldSize")}
"TextureNames" -> BuiltinProperty {cons("TextureNames")}

Expand Down Expand Up @@ -165,6 +157,9 @@ exports
"WindowWidth" -> BuiltinProperty {cons("WindowWidth")}
"WindowHeight" -> BuiltinProperty {cons("WindowHeight")}

"DefaultLevel" -> BuiltinProperty {cons("DefaultLevel")}
"LoadedPlugins" -> BuiltinProperty {cons("LoadedPlugins")}

"LightType" -> BuiltinProperty {cons("LightType")}
"CastShadows" -> BuiltinProperty {cons("CastShadows")}
"DiffuseColour" -> BuiltinProperty {cons("DiffuseColour")}
Expand Down Expand Up @@ -202,6 +197,8 @@ exports
"Enabled" -> BuiltinProperty {cons("Enabled")}
"Speed" -> BuiltinProperty {cons("Speed")}

"BackgroundInitialise" -> BuiltinProperty {cons("BackgroundInitialise")}
"BackgroundLoad" -> BuiltinProperty {cons("BackgroundLoad")}
"Type" -> BuiltinProperty {cons("Type")}
"ResourceLocation" -> BuiltinProperty {cons("ResourceLocation")}
"Group" -> BuiltinProperty {cons("Group")}
Expand Down Expand Up @@ -259,6 +256,14 @@ exports
"Caption" -> BuiltinProperty {cons("Caption")}
"Colour" -> BuiltinProperty {cons("Colour")}

"Type" -> BuiltinProperty {cons("Type")}
"TypeName" -> BuiltinProperty {cons("TypeName")}
"Mode" -> BuiltinProperty {cons("Mode")}
"PluginManager" -> BuiltinProperty {cons("PluginManager")}

"Mode" -> BuiltinProperty {cons("Mode")}
"Plugins" -> BuiltinProperty {cons("Plugins")}

"File" -> BuiltinProperty {cons("File")}
"Type" -> BuiltinProperty {cons("Type")}
"Priority" -> BuiltinProperty {cons("Priority")}
Expand Down Expand Up @@ -308,10 +313,6 @@ exports
"InheritScale" -> BuiltinProperty {cons("InheritScale")}
"InheritScale" -> BuiltinObjectProperty {cons("InheritScale")}

"X" -> BuiltinProperty {cons("X")}
"Y" -> BuiltinProperty {cons("Y")}
"Z" -> BuiltinProperty {cons("Z")}
"W" -> BuiltinProperty {cons("W")}
"XAxis" -> BuiltinProperty {cons("XAxis")}
"YAxis" -> BuiltinProperty {cons("YAxis")}
"ZAxis" -> BuiltinProperty {cons("ZAxis")}
Expand All @@ -327,26 +328,30 @@ exports
"ShortestPitch" -> BuiltinProperty {cons("ShortestPitch")}
"Yaw" -> BuiltinProperty {cons("Yaw")}
"ShortestYaw" -> BuiltinProperty {cons("ShortestYaw")}
"X" -> BuiltinProperty {cons("X")}
"Y" -> BuiltinProperty {cons("Y")}
"Z" -> BuiltinProperty {cons("Z")}
"W" -> BuiltinProperty {cons("W")}

"Degrees" -> BuiltinProperty {cons("Degrees")}
"AngleUnits" -> BuiltinProperty {cons("AngleUnits")}
"Radians" -> BuiltinProperty {cons("Radians")}

"X" -> BuiltinProperty {cons("X")}
"Y" -> BuiltinProperty {cons("Y")}
"Length" -> BuiltinProperty {cons("Length")}
"SquaredLength" -> BuiltinProperty {cons("SquaredLength")}
"IsZeroLength" -> BuiltinProperty {cons("IsZeroLength")}
"NormalisedCopy" -> BuiltinProperty {cons("NormalisedCopy")}

"X" -> BuiltinProperty {cons("X")}
"Y" -> BuiltinProperty {cons("Y")}
"Z" -> BuiltinProperty {cons("Z")}

"Zero" -> BuiltinProperty {cons("Zero")}
"Length" -> BuiltinProperty {cons("Length")}
"SquaredLength" -> BuiltinProperty {cons("SquaredLength")}
"IsZeroLength" -> BuiltinProperty {cons("IsZeroLength")}
"NormalisedCopy" -> BuiltinProperty {cons("NormalisedCopy")}
"X" -> BuiltinProperty {cons("X")}
"Y" -> BuiltinProperty {cons("Y")}
"Z" -> BuiltinProperty {cons("Z")}

"X" -> BuiltinProperty {cons("X")}
"Y" -> BuiltinProperty {cons("Y")}
Expand Down
7 changes: 4 additions & 3 deletions DSL/DiversiaScript/syntax/data/type.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ exports
"ClientObjectManager" -> BuiltinType {cons("ClientObjectManager")}
"ClientObjectTemplate" -> BuiltinType {cons("ClientObjectTemplate")}
"ClientObjectTemplateManager" -> BuiltinType {cons("ClientObjectTemplateManager")}
"ClientPlugin" -> BuiltinType {cons("ClientPlugin")}
"Lua" -> BuiltinType {cons("Lua")}
"PermissionManager" -> BuiltinType {cons("PermissionManager")}
"ServerNeighborsPlugin" -> BuiltinType {cons("ServerNeighborsPlugin")}
"ServerPlugin" -> BuiltinType {cons("ServerPlugin")}
"ClientServerPlugin" -> BuiltinType {cons("ClientServerPlugin")}
"ClientServerPluginManager" -> BuiltinType {cons("ClientServerPluginManager")}
"LayerInstance" -> BuiltinType {cons("LayerInstance")}
"Component" -> BuiltinType {cons("Component")}
"ComponentHandle" -> BuiltinType {cons("ComponentHandle")}
Expand All @@ -37,6 +35,7 @@ exports
"GameMode" -> BuiltinType {cons("GameMode")}
"InputManager" -> BuiltinType {cons("InputManager")}
"KeyboardState" -> BuiltinType {cons("KeyboardState")}
"LevelManager" -> BuiltinType {cons("LevelManager")}
"Light" -> BuiltinType {cons("Light")}
"LuaObjectScript" -> BuiltinType {cons("LuaObjectScript")}
"Mesh" -> BuiltinType {cons("Mesh")}
Expand All @@ -49,6 +48,8 @@ exports
"Sky" -> BuiltinType {cons("Sky")}
"Terrain" -> BuiltinType {cons("Terrain")}
"Text" -> BuiltinType {cons("Text")}
"Plugin" -> BuiltinType {cons("Plugin")}
"PluginManager" -> BuiltinType {cons("PluginManager")}
"PropertySynchronization" -> BuiltinType {cons("PropertySynchronization")}
"ResourceInfo" -> BuiltinType {cons("ResourceInfo")}
"ServerInfo" -> BuiltinType {cons("ServerInfo")}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module codegen/lua/luagen
module codegen/lua/generate

imports

libstratego-lib
libstratego-gpp
include/DiversiaScript
include/Lua
lib/namespaces

namespace
signatures
Expand Down
34 changes: 34 additions & 0 deletions DSL/DiversiaScript/trans/codegen/lua/normalise.str
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module codegen/lua/normalise

imports

include/DiversiaScript

signatures

rules // Normalisation rules that add plugins and components to objects to make them work with lua/game xml.

normalise-luaxml(|mediaDir): Start(imports, pluginDefs, objectDefs, eventDefs) ->
Start(imports, pluginDefs', <map(normalise-luaxml)> objectDefs, eventDefs)
where pluginDefs' := <concat> [ // Add PermissionManager, ResourceManager and Lua plugin.
pluginDefs,
[
PluginDef("ResourceManager", ResourceManager(), [
PluginProp(ResourceManager(), Type(), EnumValueRef(ResourceLocationType(), FileSystem())),
PluginProp(ResourceManager(), ResourceLocation(), StrConst(mediaDir))
]),
PluginDef("LevelManager", LevelManager(), [])
]
]

normalise-luaxml: ObjectDef(name, propAssigns, propDefs, componentDefs, varDefs, defaultStateDef, stateDefs, eventDefs) ->
ObjectDef(name, propAssigns, propDefs, componentDefs', varDefs, defaultStateDef, stateDefs, eventDefs)
where componentDefs' := <concat> [ // Add LuaObjectScript component.
componentDefs,
[
ComponentDef("LuaObjectScript", LuaObjectScript(), [
ComponentProp(LuaObjectScript(), ClientScriptFile(), StrConst($[gen/[name].lua])),
ComponentProp(LuaObjectScript(), ClientSecurityLevel(), StrConst("Low"))
])
]
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module codegen/xml/xmlgen
module codegen/xml/generate

imports

Expand All @@ -19,7 +19,7 @@ imports

rules // Structure

to-game-xml: Start(imports, pluginDefs, objectDefs, eventDefs) ->
to-game-xml: Start(_, pluginDefs, objectDefs, _) ->
XMLNode("ClientPluginManager", [XMLNode("Plugins", <concat> [
<map(to-game-xml)> pluginDefs,
[XMLNode("item", [
Expand Down Expand Up @@ -52,7 +52,7 @@ rules // Object definitions (object templates)
rules // Components (component templates)

to-game-xml: ComponentDef(name, type, properties) -> XMLNode("item", [
XMLNode("key", [XMLElement("type", <builtin-enum-value(|ComponentType())> type), XMLElement("name", name)]),
XMLNode("key", [XMLElement("Type", <builtin-enum-value(|ComponentType())> type), XMLElement("Name", name)]),
XMLNode("value", [XMLNode("Properties", <map(to-game-xml)> properties)])
])

Expand Down Expand Up @@ -94,27 +94,25 @@ rules // Expressions (no type info)
to-game-xml: New(type, params) ->
<zip(\ (name, value) -> XMLElement(name, value) \)> (propertyNames, values)
where values := <map(to-game-xml)> params
where (propertyNames, _) := <split-at(|<length> values)> <map(get-name)> <builtin-type-props> type
where (propertyNames, _) := <split-at(|<length> values)> <map(get-name)> <filter(?Property(_, _, True()))> <builtin-type-props> type

rules // Expressions (with type info)

to-game-xml-typeinfo: True() -> XMLElement("bool", 1)
to-game-xml-typeinfo: False() -> XMLElement("bool", 0)
to-game-xml-typeinfo: IntConst(num) -> XMLElement("int", num)
to-game-xml-typeinfo: FloatConst(num) -> XMLElement("float", num)
to-game-xml-typeinfo: StrConst(string) -> XMLElement("string", string')
to-game-xml-typeinfo: exp@True() -> XMLElement("bool", <to-game-xml> exp)
to-game-xml-typeinfo: exp@False() -> XMLElement("bool", <to-game-xml> exp)
to-game-xml-typeinfo: exp@IntConst(num) -> XMLElement("int", <to-game-xml> exp)
to-game-xml-typeinfo: exp@FloatConst(num) -> XMLElement("float", <to-game-xml> exp)
to-game-xml-typeinfo: exp@StrConst(string) -> XMLElement("string", <to-game-xml> exp)
where string' := <un-double-quote> string
to-game-xml-typeinfo: StrConst(string) -> XMLElement("string", string)
to-game-xml-typeinfo: exp@StrConst(string) -> XMLElement("string", <to-game-xml> exp)
where not (<un-double-quote> string)
to-game-xml-typeinfo: Vector2Const(exp1, exp2) ->
<to-game-xml-typeinfo> New(Vector2(), [exp1, exp2])
to-game-xml-typeinfo: Vector3Const(exp1, exp2, exp3) ->
<to-game-xml-typeinfo> New(Vector3(), [exp1, exp2, exp3])
to-game-xml-typeinfo: Vector4Const(exp1, exp2, exp3, exp4) ->
<to-game-xml-typeinfo> New(Vector4(), [exp1, exp2, exp3, exp4])
to-game-xml-typeinfo: EnumValueRef(enum, value) ->
XMLNode("enum", [XMLElement(<crush> enum, <builtin-enum-value(|enum)> value)])
to-game-xml-typeinfo: New(type, params) ->
XMLNode("object", [XMLNode(<crush> type, <zip(\ (name, value) -> XMLElement(name, value) \)> (propertyNames, values))])
where values := <map(to-game-xml)> params
where (propertyNames, _) := <split-at(|<length> values)> <map(get-name)> <builtin-type-props> type
to-game-xml-typeinfo: exp@EnumValueRef(enum, value) ->
XMLNode("enum", [XMLElement(<crush> enum, <to-game-xml> exp)])
to-game-xml-typeinfo: exp@New(type, params) ->
XMLNode("object", [XMLNode(<crush> type, <to-game-xml> exp)])
Loading

0 comments on commit ed67dc2

Please sign in to comment.