Class PragmaHandler

  • Direct Known Subclasses:
    MetaPragma, NoPragma

    public abstract class PragmaHandler
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      PragmaHandler()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void closeScope​(SymtabEntry entry)
      This method is called when the parser encounters a right curly brace.
      protected java.lang.String currentToken()
      Get the current token.
      protected SymtabEntry getEntryForName​(java.lang.String string)
      This method, given an entry name, returns the entry with that name.
      protected java.lang.String getStringToEOL()
      This method returns a string of all of the characters from the input file from the current position up to, but not including, the end-of-line character(s).
      protected java.lang.String getUntil​(char c)
      This method returns a string of all of the characters from the input file from the current position up to, but not including, the given character.
      (package private) void init​(Preprocessor p)  
      protected java.lang.String nextToken()
      This method returns the next token String from the input file.
      protected void openScope​(SymtabEntry entry)
      This method is called when the parser encounters a left curly brace.
      protected void parseException​(java.lang.String message)
      This method displays a Parser Exception complete with line number and position information with the given message string.
      abstract boolean process​(java.lang.String pragma, java.lang.String currentToken)  
      protected SymtabEntry scopedName()
      This method assumes that the current token marks the beginning of a scoped name.
      protected void skipToEOL()
      Skip to the end of the line.
      protected java.lang.String skipUntil​(char c)
      This method skips the data in the input file until the specified character is encountered, then it returns the next token.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PragmaHandler

        public PragmaHandler()
    • Method Detail

      • process

        public abstract boolean process​(java.lang.String pragma,
                                        java.lang.String currentToken)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • currentToken

        protected java.lang.String currentToken()
        Get the current token.
        Returns:
        the current token
      • getEntryForName

        protected SymtabEntry getEntryForName​(java.lang.String string)
        This method, given an entry name, returns the entry with that name. It can take fully or partially qualified names and returns the appropriate entry defined within the current scope. If no entry exists, null is returned.
        Parameters:
        string - entry name to look for
        Returns:
        entry with that name or null if no entry
      • getStringToEOL

        protected java.lang.String getStringToEOL()
                                           throws java.io.IOException
        This method returns a string of all of the characters from the input file from the current position up to, but not including, the end-of-line character(s).
        Returns:
        String from current position
        Throws:
        java.io.IOException
      • getUntil

        protected java.lang.String getUntil​(char c)
                                     throws java.io.IOException
        This method returns a string of all of the characters from the input file from the current position up to, but not including, the given character. It encapsulates parenthesis and quoted strings, meaning it does not stop if the given character is found within parentheses or quotes. For instance, given the input of `start(inside)end', getUntil ('n') will return "start(inside)e".
        Parameters:
        c - token to read up to. The token itself will not be read.
        Throws:
        java.io.IOException
      • nextToken

        protected java.lang.String nextToken()
                                      throws java.io.IOException
        This method returns the next token String from the input file.
        Returns:
        the next token String
        Throws:
        java.io.IOException
      • scopedName

        protected SymtabEntry scopedName()
                                  throws java.io.IOException
        This method assumes that the current token marks the beginning of a scoped name. It then parses the subsequent identifier and double colon tokens, builds the scoped name, and finds the symbol table entry with that name.
        Returns:
        a SymtabEntry of the name
        Throws:
        java.io.IOException
      • skipToEOL

        protected void skipToEOL()
                          throws java.io.IOException
        Skip to the end of the line.
        Throws:
        java.io.IOException
      • skipUntil

        protected java.lang.String skipUntil​(char c)
                                      throws java.io.IOException
        This method skips the data in the input file until the specified character is encountered, then it returns the next token.
        Parameters:
        c - token to indicate end of skipping
        Throws:
        java.io.IOException
      • parseException

        protected void parseException​(java.lang.String message)
        This method displays a Parser Exception complete with line number and position information with the given message string.
        Parameters:
        message - message to display as part of the Exception
        See Also:
        Throwable.getMessage()
      • openScope

        protected void openScope​(SymtabEntry entry)
        This method is called when the parser encounters a left curly brace. An extender of PragmaHandler may find scope information useful. For example, the prefix pragma takes effect as soon as it is encountered and stays in effect until the current scope is closed. If a similar pragma extension is desired, then the openScope and closeScope methods are available for overriding.
        Parameters:
        entry - the symbol table entry whose scope has just been opened. Be aware that, since the scope has just been entered, this entry is incomplete at this point.
      • closeScope

        protected void closeScope​(SymtabEntry entry)
        This method is called when the parser encounters a right curly brace. An extender of PragmaHandler may find scope information useful. For example, the prefix pragma takes effect as soon as it is encountered and stays in effect until the current scope is closed. If a similar pragma extension is desired, then the openScope and closeScope methods are available for overriding.
        Parameters:
        entry - the symbol table entry whose scope has just been closed.