1 /*
   2  * @(#)file      Parser.jjt
   3  * @(#)author    Sun Microsystems, Inc.
   4  *
   5  * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.  Oracle designates this
  11  * particular file as subject to the "Classpath" exception as provided
  12  * by Oracle in the LICENSE file that accompanied this code.
  13  *
  14  * This code is distributed in the hope that it will be useful, but WITHOUT
  15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  17  * version 2 for more details (a copy is included in the LICENSE file that
  18  * accompanied this code).
  19  *
  20  * You should have received a copy of the GNU General Public License version
  21  * 2 along with this work; if not, write to the Free Software Foundation,
  22  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  23  *
  24  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  25  * or visit www.oracle.com if you need additional information or have any
  26  * questions.
  27  *
  28  */
  29 
  30 options {
  31   MULTI=true;
  32   STATIC=false;
  33   NODE_PREFIX= "JDM";
  34   NODE_PACKAGE="com.sun.jmx.snmp.IPAcl";
  35 }
  36 
  37 
  38 PARSER_BEGIN(Parser)
  39 
  40 package com.sun.jmx.snmp.IPAcl;
  41 
  42 import java.io.*;
  43 
  44 public class Parser {
  45 }
  46 
  47 PARSER_END(Parser)
  48 
  49 
  50 SKIP :
  51 {
  52   " "
  53 | "\t"
  54 | "\n"
  55 | "\r"
  56 | <"--" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
  57 | <"#" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
  58 
  59 }
  60 
  61 
  62 
  63 /* RESERVED WORDS AND LITERALS */
  64 
  65 TOKEN : 
  66 {
  67   <ACCESS: "access">
  68 | <ACL: "acl">
  69 | <ASSIGN: "=">
  70 | <COMMUNITIES: "communities">
  71 | <ENTERPRISE: "enterprise">
  72 | <HOSTS: "hosts">
  73 | <LBRACE: "{">
  74 | <MANAGERS: "managers">
  75 | <RANGE: "-">
  76 | <RBRACE: "}">
  77 | <RO: "read-only">
  78 | <RW: "read-write">
  79 | <TRAP: "trap">
  80 | <INFORM: "inform">
  81 | <TRAPCOMMUNITY: "trap-community">
  82 | <INFORMCOMMUNITY: "inform-community">
  83 | <TRAPNUM: "trap-num">
  84 }
  85 
  86 
  87 
  88 TOKEN : /* LITERALS */
  89 {
  90   < INTEGER_LITERAL:
  91         <DECIMAL_LITERAL> (["l","L"])?
  92       | <HEX_LITERAL> (["l","L"])?
  93       | <OCTAL_LITERAL> (["l","L"])?
  94   >
  95 |
  96   < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
  97 |
  98   < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
  99 |      
 100   < #OCTAL_LITERAL: "0" (["0"-"7"])* >
 101 }
 102 
 103 TOKEN : /* V6 LITERALS */
 104 { 
 105   < V6_ADDRESS: ((( ( (<H> ":")+ (":")?) | "::" ) (<H> ":")* (<H> | (<D> "." <D> "." <D> "." <D>))) | ("::")) | ( (<H> ":")+ ":") >
 106 |
 107   <#H: (["0"-"9","a"-"f","A"-"F"])+ >
 108 | 
 109   <#D: (["0"-"9"])+ >
 110 }
 111  
 112 TOKEN : /* IDENTIFIERS */
 113 {
 114   < IDENTIFIER: ( (<DIGIT>|<LETTER>)+ (<SEPARATOR>|<LETTER>|<DIGIT>)* (<DIGIT>|<LETTER>)+ ) | (<DIGIT>|<LETTER>)+ >
 115 |
 116   < #LETTER: ["a"-"z","A"-"Z"] >
 117 |
 118   < #SEPARATOR: ["-", "_"] >
 119 |
 120   < #DIGIT: ["0"-"9"] >
 121 |
 122  <CSTRING: "\"" (~["\""])* "\"">
 123 }
 124 
 125  
 126 
 127 TOKEN: /* SEPARATOR */
 128 {
 129   < COMMA: "," >
 130 | < DOT: "." >
 131 | < MARK: "!" >
 132 | < MASK: "/">
 133 }
 134 
 135 // A file can contain several acl definitions
 136 //
 137 JDMSecurityDefs SecurityDefs()  : {}
 138 {
 139   [AclBlock()]
 140   [TrapBlock()]
 141   [InformBlock()]
 142   <EOF>
 143   { return jjtThis;}
 144 }
 145 
 146 void AclBlock(): {}
 147 {
 148 "acl" "=" "{" (AclItem())+ "}"
 149 }
 150 
 151 void AclItem(): {}
 152 {
 153 "{" jjtThis.com= Communities() jjtThis.access= Access() Managers() "}"
 154 }
 155 
 156 JDMCommunities Communities(): {}
 157 {
 158 "communities" "=" Community() ( "," Community())*
 159 
 160 {return jjtThis;}
 161 
 162 }
 163 
 164 void Community(): 
 165 {
 166   Token t;
 167 }
 168 {
 169 t=<IDENTIFIER> {jjtThis.communityString= t.image;}
 170 }
 171 
 172 JDMAccess Access(): {}
 173 {
 174 "access" "=" ( <RO> {jjtThis.access= RO;}
 175               |
 176                <RW> {jjtThis.access= RW;}
 177              )
 178 {return jjtThis;}
 179 }
 180 
 181 
 182 void Managers() : { }
 183 {
 184 "managers" "=" Host() ( "," Host())*
 185 }
 186 
 187 void Host() : 
 188 {
 189   Token t;
 190 }
 191 {
 192 HostName()
 193 |
 194 LOOKAHEAD(<INTEGER_LITERAL> ( "." <INTEGER_LITERAL> )* "/" <INTEGER_LITERAL>)
 195 NetMask()
 196 |
 197 LOOKAHEAD(<V6_ADDRESS> "/" <INTEGER_LITERAL>)
 198 NetMaskV6()
 199 |
 200 LOOKAHEAD(<INTEGER_LITERAL> ".")
 201 IpAddress()
 202 |
 203 IpV6Address()
 204 |
 205 IpMask()
 206 }
 207 
 208 void HostName():
 209 {
 210   Token t;
 211 }
 212 {
 213   t=<IDENTIFIER> { jjtThis.name.append(t.image); }
 214 (
 215 "." t=<IDENTIFIER> 
 216   {jjtThis.name.append( '.').append(t.image); }
 217 )*
 218 
 219 }
 220 
 221 void IpAddress():
 222 {
 223 Token t;
 224 }
 225 {
 226 
 227 t= <INTEGER_LITERAL> 
 228   {jjtThis.address.append(t.image); }
 229 (
 230 "." t= <INTEGER_LITERAL> 
 231   {jjtThis.address.append( '.').append(t.image); }
 232 )*
 233 
 234 }
 235 
 236 void IpV6Address():
 237 {
 238 Token t;
 239 }
 240 {
 241 
 242 t= <V6_ADDRESS> 
 243   {jjtThis.address.append(t.image); }
 244 }
 245 
 246 void IpMask():
 247 {
 248 Token t;
 249 }
 250 {
 251 
 252 t= <INTEGER_LITERAL> 
 253   {jjtThis.address.append(t.image); }
 254 (
 255 "!" t= <INTEGER_LITERAL> 
 256   {jjtThis.address.append( '.').append(t.image); }
 257 )*
 258 }
 259 
 260 void NetMask():
 261 {
 262 Token t;
 263 }
 264 {
 265 
 266 t= <INTEGER_LITERAL> 
 267   {jjtThis.address.append(t.image); }
 268 (
 269 "." t= <INTEGER_LITERAL> 
 270   {jjtThis.address.append( '.').append(t.image); }
 271 )* "/" t= <INTEGER_LITERAL> {jjtThis.mask = t.image; }
 272 }
 273 
 274 void NetMaskV6():
 275 {
 276 Token t;
 277 }
 278 {
 279 
 280 t= <V6_ADDRESS> 
 281   {jjtThis.address.append(t.image); }
 282 
 283 "/" t= <INTEGER_LITERAL> {jjtThis.mask = t.image; }
 284 }
 285 
 286 void TrapBlock(): { }
 287 {
 288 "trap" "=" "{" (TrapItem())* "}"
 289 }
 290 
 291 void TrapItem(): { }
 292 {
 293 "{" jjtThis.comm= TrapCommunity() TrapInterestedHost() (Enterprise())* "}"
 294 }
 295 
 296 JDMTrapCommunity TrapCommunity(): 
 297 {
 298   Token t;
 299 }
 300 {
 301 "trap-community" "=" t=<IDENTIFIER> { jjtThis.community= t.image; return jjtThis; }
 302 }
 303 
 304 void TrapInterestedHost(): { }
 305 {
 306 "hosts" "=" HostTrap() ("," HostTrap())*
 307 }
 308 
 309 void HostTrap() : 
 310 {
 311   Token t;
 312 }
 313 {
 314 HostName()
 315 |
 316 IpAddress()
 317 |
 318 IpV6Address()
 319 }
 320 
 321 void Enterprise(): 
 322 {
 323   Token t;
 324 }
 325 {
 326 "{"
 327 "enterprise" "="  t=<CSTRING> {jjtThis.enterprise= t.image;}
 328 
 329 "trap-num" "=" TrapNum() ("," TrapNum())*
 330 
 331 "}"
 332 }
 333 
 334 void TrapNum():
 335 {
 336   Token t;
 337 }
 338 {
 339   t=<INTEGER_LITERAL> {jjtThis.low= Integer.parseInt(t.image);}
 340 [
 341   "-" t=<INTEGER_LITERAL> {jjtThis.high= Integer.parseInt(t.image);}
 342 ]
 343 }
 344 
 345 
 346 void InformBlock(): { }
 347 {
 348 "inform" "=" "{" (InformItem())* "}"
 349 }
 350 
 351 void InformItem(): { }
 352 {
 353 "{" jjtThis.comm= InformCommunity() InformInterestedHost() "}"
 354 }
 355 
 356 JDMInformCommunity InformCommunity(): 
 357 {
 358   Token t;
 359 }
 360 {
 361 "inform-community" "=" t=<IDENTIFIER> { jjtThis.community= t.image; return jjtThis; }
 362 }
 363 
 364 void InformInterestedHost(): { }
 365 {
 366 "hosts" "=" HostInform() ("," HostInform())*
 367 }
 368 
 369 void HostInform() : 
 370 {
 371   Token t;
 372 }
 373 {
 374 HostName()
 375 |
 376 IpAddress()
 377 |
 378 IpV6Address()
 379 }
 380