Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1
Chapter 12

[ 327 ]

stmnt.statementLabel &&
stmnt.statementLabel == 'event'
}
boolean isNonEventBlock(Statement stmnt) {
stmnt instanceof ExpressionStatement &&
stmnt.expression instanceof ConstantExpression &&
stmnt.statementLabel &&
(stmnt.statementLabel == 'page' ||
stmnt.statementLabel == 'when' ||
stmnt.statementLabel == 'state')
}

Building the game engine pattern


Once the parser has completed its work, we should have a full representation of the
game engine in the GameEngineModel class. We next set about generating the classes
of the game engine from this model. The EnginePatternBuilder class takes over at
this point:


class EnginePatternBuilder {
def model
ModuleNode moduleNode
ClassNode classNode
String className
ClassNode contextClass
String sessionClassName
def sourceUnit
def compilationUnit

EnginePatternBuilder(ASTNode[] nodes, model, source, comp) {
this.model = model
moduleNode = nodes[0]
classNode = nodes[0].classes[0]
className = nodes[0].classes[0].nameWithoutPackage
this.sourceUnit = source
this.compilationUnit = comp
}

void buildEnginePattern() {
buildSessionClass()
updateClientClass()
buildPageClasses()
removeMethods()
}

........
}
Free download pdf