Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/trapezium/vrml/grammar/SpecNodeRule.java


1   package com.trapezium.vrml.grammar;
2   
3   import com.trapezium.vrml.Scene;
4   import com.trapezium.vrml.LeftBrace;
5   import com.trapezium.vrml.RightBrace;
6   import com.trapezium.vrml.NodeTypeId;
7   import com.trapezium.parse.TokenEnumerator;
8   
9   /**
10   * Process the file we are using to generate built in node classes.  This is similar, but
11   * not identical to ".wrl" file processing.  The "Spec" object is built as follows:
12   *
13   *            Spec s = new Spec();
14   *            SpecRule.Build( v, s );
15   *
16   * The spec grammar is:
17   *
18   *  spec:
19   *    specNode
20   *
21   *  specNode:
22   *    Category categoryName { interfaceDeclarations* }
23   *    nodeType { interfaceDeclarations* }
24   *
25   * When the "Spec" object has been created, we create a visitor to visit each node, and 
26   * generate code based on the interfaceDeclarations and the embedded controls (tips, etc.)
27   */
28  
29  class SpecNodeRule {
30    /** keep track of category based on where we are in the processing */
31    String mostRecentCategory = null;
32    InterfaceDeclarationRule interfaceDeclarationRule;
33  
34    public SpecNodeRule( NodeRule nodeRule ) {
35        interfaceDeclarationRule = new InterfaceDeclarationRule( nodeRule );
36    }
37  
38    /**
39     *  Apply the SpecRule to update the Spec object. 
40     */
41    public void Build( int tokenOffset, TokenEnumerator v, Spec spec ) {
42      GrammarRule.Enter( "SpecNodeRule.Build" );
43  
44      SpecNode s = new SpecNode();
45      spec.addChild( s );
46      NodeTypeId nodeTypeId = new NodeTypeId( tokenOffset, v );
47      s.addChild( nodeTypeId );
48      if ( nodeTypeId.getName().compareTo( "Category" ) == 0 ) {
49        tokenOffset = v.getNextToken();
50        mostRecentCategory = v.toString( tokenOffset );
51      }
52      s.setCategory( mostRecentCategory );
53      s.addChild( new LeftBrace( v ));
54      while ( true ) {
55        tokenOffset = v.getNextToken();
56        if ( v.sameAs( tokenOffset, "}" )) {
57          break;
58        }
59        interfaceDeclarationRule.Build( tokenOffset, v, null, s );
60      }
61      s.addChild( new RightBrace( tokenOffset, v ));
62      GrammarRule.Exit( "SpecNodeRule.Build" );
63    }
64  }
65