Groovy for Domain-specific Languages - Second Edition
Integrating It All [ 318 ] ' ',' ',' ', ' ',' ',' ' ] def TicTacToeEngineSession() { super() page = new WelcomePage(this) } } Th ...
Chapter 12 [ 319 ] The persisted version of the session saved pages as a string so you can see that the class that represents a ...
Integrating It All [ 320 ] Looking back at the DSL code, you will note that the state: block where the state variables are decla ...
Chapter 12 [ 321 ] } else { page = "roundX" } } def play_round = { Object event -> def player = getPlayer(event.player) playe ...
Integrating It All [ 322 ] We can verify this with a Spock test: given: def engine = new GameEngineClient() expect: !engine.sess ...
Chapter 12 [ 323 ] // X O X // O X O // Expect next X play to win when: engine = new GameEngineClient() engine.play_round([playe ...
Integrating It All [ 324 ] void setCompilationUnit(CompilationUnit unit) { compilationUnit = unit } } You will immediately notic ...
Chapter 12 [ 325 ] There is not much to the game model class, as you can see in the preceding code. While parsing, we build a li ...
Integrating It All [ 326 ] stmnt.statementLabel && stmnt.statementLabel == 'state' } boolean isNonStateBlock(Statement s ...
Chapter 12 [ 327 ] stmnt.statementLabel && stmnt.statementLabel == 'event' } boolean isNonEventBlock(Statement stmnt) { ...
Integrating It All [ 328 ] Our starting point with this AST transformation will be a single Groovy script class containing the D ...
Chapter 12 [ 329 ] ), new ExpressionStatement( new BinaryExpression( new VariableExpression("page"), new Token(Types.EQUALS, "=" ...
Integrating It All [ 330 ] We start off the preceding code by creating a new AST node for the session class. We build the constr ...
Chapter 12 [ 331 ] constructorStatement ) classNode.addConstructor(constructorNode) } Most of the preceding code should be famil ...
Integrating It All [ 332 ] ) ), new ExpressionStatement( new MethodCallExpression( new VariableExpression('session'), new Consta ...
Chapter 12 [ 333 ] moduleNode.addClass(pageNode[1]) } } Much of the code for building these classes will be familiar already. On ...
Integrating It All [ 334 ] new Token(Types.EQUALS, "=", -1, -1), new VariableExpression("session") ) ) closureDelegateStatements ...
Chapter 12 [ 335 ] } def blockStatement = new BlockStatement( eventStatements as Statement [], new VariableScope() ) PageAssignm ...
Integrating It All [ 336 ] These assignments can occur anywhere within the event: block code. This means they could be nested de ...
Chapter 12 [ 337 ] The PageAssignmentTransformer class extends CodeVisitorSupport and overrides the visitBinaryExpression method ...
«
11
12
13
14
15
16
17
18
19
20
»
Free download pdf