Class HeadFeaturedGrammarFileHandler

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

public class HeadFeaturedGrammarFileHandler
extends AugmentedGrammarFileHandler

An HeadFeaturedGrammarFileHandler reads grammars whose constituents are HeadFeaturedConstituents.

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

    Grammar <- START("Grammar") Description? HeadFeatures? GrammarRule* END("Grammar")
    Description <- START("Description") characters END("Description")
    HeadFeatures <- START("HeadFeatures") HeadFeature* END("HeadFeatures")
    HeadFeature <- START(CATEGORY) FEATNAME* END(CATEGORY)
    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.

The head constituent of a rule is marked with the HEAD attribute.


Field Summary
(package private)  boolean isHead
           
(package private) static int STATE_HEADFEATURES
           
 
Fields inherited from class AugmentedGrammarFileHandler
feature, features, STATE_FEATURE, 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
HeadFeaturedGrammarFileHandler(HeadFeaturedGrammar g)
          Create a new HeadFeaturedGrammarFileHandler to read into the given HeadFeaturedGrammar.
 
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_HEADFEATURES

static final int STATE_HEADFEATURES
See Also:
Constant Field Values

isHead

boolean isHead
Constructor Detail

HeadFeaturedGrammarFileHandler

public HeadFeaturedGrammarFileHandler(HeadFeaturedGrammar g)
Create a new HeadFeaturedGrammarFileHandler to read into the given HeadFeaturedGrammar.

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 AugmentedGrammarFileHandler
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 AugmentedGrammarFileHandler
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 AugmentedGrammarFileHandler
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