Class AugmentedGrammarFileHandler

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byGrammarFileHandler
          extended byAugmentedGrammarFileHandler
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler
Direct Known Subclasses:
HeadFeaturedGrammarFileHandler

public class AugmentedGrammarFileHandler
extends GrammarFileHandler

An AugmentedGrammarFileHandler reads grammars whose constituents are AugmentedConstituents.

The BNF grammar we are trying to parse is something like the following:

    Grammar <- START("Grammar") Description? GrammarRule* END("Grammar")
    Description <- START(DESCRIPTION) characters END(Description)
    GrammarRule <- START("Rule") Constit+ END("Rule")
    Constit <- START(CATEGORY) Feature* END(CATEGORY)
    Feature <- START(FEATNAME) FeatureValue END(FEATNAME)
    FeatureValue <- characters
 
where CATEGORY is a syntactic category, and FEATNAME is a feature name. These might be specified in the preamble of the file, or we could just accept anything (which is in fact what we do now).


Field Summary
(package private)  Symbol feature
           
(package private)  FeatureSet features
           
(package private) static int STATE_FEATURE
           
(package private)  java.util.HashMap varTable
           
 
Fields inherited from class GrammarFileHandler
cat, constits, grammar, locator, ruleId, state, STATE_CONSTIT, STATE_DESCRIPTION, STATE_FILE, STATE_GRAMMAR, STATE_RULE, textBuffer
 
Constructor Summary
AugmentedGrammarFileHandler(AugmentedGrammar g)
          Create a new AugmentedGrammarFileHandler to read into the given AugmentedGrammar.
 
Method Summary
 void characters(char[] buf, int offset, int len)
          Called by the SAX parsing engine when characters are read outside of any element tag.
 void endElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName)
          SAX ContentHandler method called when an end-element tag is encountered.
static void main(java.lang.String[] argv)
          Test the GrammarFileHandler.
 void startElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName, org.xml.sax.Attributes attrs)
          SAX ContentHandler method called when a start-element tag is encountered.
 
Methods inherited from class GrammarFileHandler
consumeText, error, ERROR, fatalError, readFile, setDocumentLocator, warning
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_FEATURE

static final int STATE_FEATURE
See Also:
Constant Field Values

feature

Symbol feature

features

FeatureSet features

varTable

java.util.HashMap varTable
Constructor Detail

AugmentedGrammarFileHandler

public AugmentedGrammarFileHandler(AugmentedGrammar g)
Create a new AugmentedGrammarFileHandler to read into the given AugmentedGrammar.

Method Detail

startElement

public void startElement(java.lang.String namespaceURI,
                         java.lang.String sName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Description copied from class: GrammarFileHandler
SAX ContentHandler method called when a start-element tag is encountered.

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class GrammarFileHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String namespaceURI,
                       java.lang.String sName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
Description copied from class: GrammarFileHandler
SAX ContentHandler method called when an end-element tag is encountered.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class GrammarFileHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] buf,
                       int offset,
                       int len)
                throws org.xml.sax.SAXException
Description copied from class: GrammarFileHandler
Called by the SAX parsing engine when characters are read outside of any element tag. This can be called multiple times, such as when the text spans multiple lines (depends on whitespace treatment, whether the parser is validating, etc.). So the safe thing to do is just hold onto the text for later use when an end-element tag is reached (assuming we don't care about the actual form of the original text, but just its content, which is the case for us). We could be more careful, saving the text in states where we're expecting text and otherwise indicating a state-specific error, but frankly I don't care that much.

Specified by:
characters in interface org.xml.sax.ContentHandler
Overrides:
characters in class GrammarFileHandler
Throws:
org.xml.sax.SAXException

main

public static void main(java.lang.String[] argv)
                 throws java.io.IOException
Description copied from class: GrammarFileHandler
Test the GrammarFileHandler.

Throws:
java.io.IOException