2 * Copyright (c) 2007, Newspiritcompany.com (Berlin Brown)
3 * http://www.opensource.org/licenses/bsd-license.php
5 * Simple Remote Definition Meta Language
6 * (with parsing, more practical usage)
7 * Grammar Definition for Antlr (3.0+)
11 * Description Current Version:
13 * Parse the Example Remote Def file and
14 * print the important values.
16 * In total, we are only building basic data structures
17 * out of the meta language file (lists, maps, etc)
19 * All rights reserved.
21 * Redistribution and use in source and binary forms, with or without modification,
22 * are permitted provided that the following conditions are met:
26 * * Redistributions of source code must retain the above copyright notice,
27 * this list of conditions and the following disclaimer.
28 * * Redistributions in binary form must reproduce the above copyright notice,
29 * this list of conditions and the following disclaimer in the documentation
30 * and/or other materials provided with the distribution.
31 * * Neither the name of the Newspiritcompany.com (Berlin Brown) nor
32 * the names of its contributors may be used to endorse or promote
33 * products derived from this software without specific prior written permission.
35 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
39 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
41 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
42 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
43 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
44 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
45 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 //***********************************************
49 // Begin Grammar Definitions
50 //***********************************************
59 Map types; // JAVA definition
63 package org.spirit.parse.remotedef;
67 import java.util.HashSet;
68 import java.util.HashMap;
71 // Applies only to the lexer:
73 package org.spirit.parse.remotedef;
77 private Map rootNamespaceAttributes = new HashMap();
78 private Stack rootOperations = new Stack();
79 private boolean buildRootOperationFlag = false;
81 Map getRootNamespaceAttributes() {
82 return rootNamespaceAttributes;
85 Stack getRootOperations() {
86 return rootOperations;
91 root_meta_declarations
94 $Symbols::types = new HashMap();
104 * Only one root namespace, allowed.
107 OPEN_PAREN ( operation_declaration_list|statement_expression_list|end_root_attr_expression )+ CLOSE_PAREN
109 // JAVA COMMENT: name space defined.
110 System.out.println("INFO: ROOT NAMESPACE FOUND: ");
115 * Root expression list
117 statement_expression_list :
118 ( attribute_expression )+
121 end_root_attr_expression :
124 System.out.println("END OF ROOT ATTRIBUTES FOUND");
125 buildRootOperationFlag = true;
129 begin_oper_attr_expression :
132 System.out.println("BEGIN OPERATIONS FOUND");
133 // JAVA_COMMENT: create a new operation stack.
134 rootOperations.push(new HashMap());
139 * Attributes are defined with @attr: val;
140 * Sub hash data structures are defined by
143 * Data payloads (String Content) is enclosed
144 * between <<< and >>> tags.
146 operation_declaration_list :
147 ( begin_oper_attr_expression OPEN_BRACE ( statement_expression_list | DATA_PAYLOAD_VALUE )+
150 // JAVA COMMENT: print the data payload
151 if ($DATA_PAYLOAD_VALUE != null) {
152 System.out.println("INFO: data payload: [" + $DATA_PAYLOAD_VALUE.text + "]");
153 ((Map) (rootOperations.peek())).put("data.payload", $DATA_PAYLOAD_VALUE.text);
161 * Process a attribute statement expression, which has the following syntax:
162 * <code>@some_attribute: some_value;</code>
164 attribute_expression :
165 AT_SIGN_IDENTIFIER attribute_atom_key COLON IDENTIFIER_ATOM END_EXPRESSION
167 // JAVA COMMENT: print the attribute key
168 System.out.println("INFO: define attribute expr: [" + $IDENTIFIER_ATOM.text + "]");
169 System.out.println("INFO: key: " + $attribute_atom_key.text);
171 $Symbols::types.put($attribute_atom_key.text, $IDENTIFIER_ATOM.text);
173 // If operations enabled, accumulate that map data
174 if (buildRootOperationFlag) {
175 ((Map) (rootOperations.peek())).put($attribute_atom_key.text, $IDENTIFIER_ATOM.text);
177 getRootNamespaceAttributes().put($attribute_atom_key.text, $IDENTIFIER_ATOM.text);
183 AT_SIGN_IDENTIFIER attribute_val COLON
185 // JAVA COMMENT: print the attribute value
186 System.out.println("INFO: define attribute key: [" + $attribute_val.text + "]");
198 //***********************************************
199 // Misc Utility Definitions and Tokens
200 //***********************************************
203 ( LETTER | '0'..'9' )*
222 //***********************************************
225 // For example, open and close parens are defined
226 //***********************************************
230 END_EXPRESSION : ';' ;
232 AT_SIGN_IDENTIFIER : '@' ;
242 //***********************************************
243 // Ignore (whitespace, comments)
244 //***********************************************
247 (' '|'\r'|'\t'|'\u000C'|'\n')
252 '/*' ( options {greedy=false;} : . )* '*/' {channel=99;}
256 '//' ~('\n'|'\r')* '\r'? '\n'
258 // JAVA COMMENT: set channel = 99
263 // End of Grammar File //