001: /*
002: * Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: /*
026: * COMPONENT_NAME: idl.parser
027: *
028: * ORIGINS: 27
029: *
030: * Licensed Materials - Property of IBM
031: * 5639-D57 (C) COPYRIGHT International Business Machines Corp. 1997, 1999
032: * RMI-IIOP v1.0
033: *
034: * @(#)PragmaHandler.java 1.20 07/05/05
035: */
036:
037: package com.sun.tools.corba.se.idl;
038:
039: // NOTES:
040: // - Add openScope and closeScope.
041:
042: import java.io.IOException;
043:
044: public abstract class PragmaHandler {
045: public abstract boolean process(String pragma, String currentToken)
046: throws IOException;
047:
048: void init(Preprocessor p) {
049: preprocessor = p;
050: } // init
051:
052: // Utility methods.
053:
054: /** Get the current token. */
055: protected String currentToken() {
056: return preprocessor.currentToken();
057: } // currentToken
058:
059: /** This method, given an entry name, returns the entry with that name.
060: It can take fully or partially qualified names and returns the
061: appropriate entry defined within the current scope. If no entry
062: exists, null is returned. */
063: protected SymtabEntry getEntryForName(String string) {
064: return preprocessor.getEntryForName(string);
065: } // getEntryForName
066:
067: /** This method returns a string of all of the characters from the input
068: file from the current position up to, but not including, the end-of-line
069: character(s). */
070: protected String getStringToEOL() throws IOException {
071: return preprocessor.getStringToEOL();
072: } // getStringToEOL
073:
074: /** This method returns a string of all of the characters from the input
075: file from the current position up to, but not including, the given
076: character. It encapsulates parenthesis and quoted strings, meaning
077: it does not stop if the given character is found within parentheses
078: or quotes. For instance, given the input of `start(inside)end',
079: getUntil ('n') will return "start(inside)e" */
080: protected String getUntil(char c) throws IOException {
081: return preprocessor.getUntil(c);
082: } // getUntil
083:
084: /** This method returns the next token String from the input file. */
085: protected String nextToken() throws IOException {
086: return preprocessor.nextToken();
087: } // nextToken
088:
089: /** This method assumes that the current token marks the beginning
090: of a scoped name. It then parses the subsequent identifier and
091: double colon tokens, builds the scoped name, and finds the symbol
092: table entry with that name. */
093: protected SymtabEntry scopedName() throws IOException {
094: return preprocessor.scopedName();
095: } // scopedName
096:
097: /** Skip to the end of the line. */
098: protected void skipToEOL() throws IOException {
099: preprocessor.skipToEOL();
100: } // skipToEOL
101:
102: /** This method skips the data in the input file until the specified
103: character is encountered, then it returns the next token. */
104: protected String skipUntil(char c) throws IOException {
105: return preprocessor.skipUntil(c);
106: } // skipUntil
107:
108: /** This method displays a Parser Exception complete with line number
109: and position information with the given message string. */
110: protected void parseException(String message) {
111: preprocessor.parseException(message);
112: } // parseException
113:
114: /** This method is called when the parser encounters a left curly brace.
115: An extender of PragmaHandler may find scope information useful.
116: For example, the prefix pragma takes effect as soon as it is
117: encountered and stays in effect until the current scope is closed.
118: If a similar pragma extension is desired, then the openScope and
119: closeScope methods are available for overriding.
120: @param entry the symbol table entry whose scope has just been opened.
121: Be aware that, since the scope has just been entered, this entry is
122: incomplete at this point. */
123: protected void openScope(SymtabEntry entry) {
124: } // openScope
125:
126: /** This method is called when the parser encounters a right curly brace.
127: An extender of PragmaHandler may find scope information useful.
128: For example, the prefix pragma takes effect as soon as it is
129: encountered and stays in effect until the current scope is closed.
130: If a similar pragma extension is desired, then the openScope and
131: closeScope methods are available for overriding.
132: @param entry the symbol table entry whose scope has just been closed. */
133: protected void closeScope(SymtabEntry entry) {
134: } // closeScope
135:
136: private Preprocessor preprocessor = null;
137: } // class PragmaHandler
|