1 /*
2  * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 /*
26  * COMPONENT_NAME: idl.parser
27  *
28  * ORIGINS: 27
29  *
30  * Licensed Materials - Property of IBM
31  * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
32  * RMI-IIOP v1.0
33  *
34  */
35 
36 package com.sun.tools.corba.se.idl;
37 
38 // NOTES:
39 // - Add openScope and closeScope.
40 
41 import java.io.IOException;
42 
43 public abstract class PragmaHandler
44 {
process(String pragma, String currentToken)45   public abstract boolean process (String pragma, String currentToken) throws IOException;
46 
init(Preprocessor p)47   void init (Preprocessor p)
48   {
49     preprocessor = p;
50   } // init
51 
52   // Utility methods.
53 
54   /** Get the current token. */
currentToken()55   protected String currentToken ()
56   {
57     return preprocessor.currentToken ();
58   } // currentToken
59 
60   /** This method, given an entry name, returns the entry with that name.
61       It can take fully or partially qualified names and returns the
62       appropriate entry defined within the current scope.  If no entry
63       exists, null is returned. */
getEntryForName(String string)64   protected SymtabEntry getEntryForName (String string)
65   {
66     return preprocessor.getEntryForName (string);
67   } // getEntryForName
68 
69   /** This method returns a string of all of the characters from the input
70       file from the current position up to, but not including, the end-of-line
71       character(s). */
getStringToEOL()72   protected String getStringToEOL () throws IOException
73   {
74     return preprocessor.getStringToEOL ();
75   } // getStringToEOL
76 
77   /** This method returns a string of all of the characters from the input
78       file from the current position up to, but not including, the given
79       character.  It encapsulates parenthesis and quoted strings, meaning
80       it does not stop if the given character is found within parentheses
81       or quotes.  For instance, given the input of `start(inside)end',
82       getUntil ('n') will return "start(inside)e" */
getUntil(char c)83   protected String getUntil (char c) throws IOException
84   {
85     return preprocessor.getUntil (c);
86   } // getUntil
87 
88   /** This method returns the next token String from the input file. */
nextToken()89   protected String nextToken () throws IOException
90   {
91     return preprocessor.nextToken ();
92   } // nextToken
93 
94   /** This method assumes that the current token marks the beginning
95       of a scoped name.  It then parses the subsequent identifier and
96       double colon tokens, builds the scoped name, and finds the symbol
97       table entry with that name. */
scopedName()98   protected SymtabEntry scopedName () throws IOException
99   {
100     return preprocessor.scopedName ();
101   } // scopedName
102 
103   /** Skip to the end of the line. */
skipToEOL()104   protected void skipToEOL () throws IOException
105   {
106     preprocessor.skipToEOL ();
107   } // skipToEOL
108 
109   /** This method skips the data in the input file until the specified
110       character is encountered, then it returns the next token. */
skipUntil(char c)111   protected String skipUntil (char c) throws IOException
112   {
113     return preprocessor.skipUntil (c);
114   } // skipUntil
115 
116   /** This method displays a Parser Exception complete with line number
117       and position information with the given message string. */
parseException(String message)118   protected void parseException (String message)
119   {
120     preprocessor.parseException (message);
121   } // parseException
122 
123   /** This method is called when the parser encounters a left curly brace.
124       An extender of PragmaHandler may find scope information useful.
125       For example, the prefix pragma takes effect as soon as it is
126       encountered and stays in effect until the current scope is closed.
127       If a similar pragma extension is desired, then the openScope and
128       closeScope methods are available for overriding.
129       @param entry the symbol table entry whose scope has just been opened.
130        Be aware that, since the scope has just been entered, this entry is
131        incomplete at this point.  */
openScope(SymtabEntry entry)132   protected void openScope (SymtabEntry entry)
133   {
134   } // openScope
135 
136   /** This method is called when the parser encounters a right curly brace.
137       An extender of PragmaHandler may find scope information useful.
138       For example, the prefix pragma takes effect as soon as it is
139       encountered and stays in effect until the current scope is closed.
140       If a similar pragma extension is desired, then the openScope and
141       closeScope methods are available for overriding.
142       @param entry the symbol table entry whose scope has just been closed. */
closeScope(SymtabEntry entry)143   protected void closeScope (SymtabEntry entry)
144   {
145   } // closeScope
146 
147   private Preprocessor preprocessor = null;
148 } // class PragmaHandler
149