[antlr-interest] XPA and ANTLR

Oliver Zeigermann oliver at zeigermann.de
Thu Aug 12 00:55:49 PDT 2004


Hi David,

which tokens do you think are skipped?

Anyway, you could also try to use the XPA token parser. There you can be 
very sure nothing is missed as you will have to consume each and every 
token.

Oliver

ooobles wrote:

> Hi all,
> 
> It's been a while since I've got to play with ANTLR in a new way. 
> I've been happily making up new grammars for a while now. :)  I now
> have the new challenge of parsing XML. After writing a 1200line parser
> that reads over a dom4j tree, I decided there must be a better way. 
> Thankfully, I found XPA and have started writing a tree walker for
> reading XML Schemas (XSD).
> 
> One thing I find with tree walkers is that I can't be sure if I missed
> nodes in the tree.  A tree walker can silently skip child nodes
> because the grammar has already been met.  Is there any way to force
> the parser to report an error when additional nodes have been found in
> the tree?
> 
> I've been using one of the XPA examples to write the tree parser (see
> below). It *seems* to read XSD, but I'm quite sure it is skipping
> some elements.
> 
> As an aside, has anyone already written an XSD parser that generates a
>  nice internal model? :)  I'm guessing I'll need to do a few passes
> over the XSD files to resolve all the data types, groups, elements, etc.
> 
> Thanks,
> David.
> 
> PS I read over a few other messages mentioning that there arn't many
> fans of XML here.  I'm definately not a fan either, but when you
> work in a group that only does XML, you don't get much choice. :) 
> 
> -------------- XSD Tree Parser ----------------
> 
> class ComponentTreeParser extends TreeParser;
> options 
> {
>    buildAST = true;
>    ASTLabelType = "XMLAST";
> }
> 
> // enable wildcard processing for xtal and 
> // set wildcard element type to "<wildcard>"
> tokens 
> {
>     "<wildcard>";
> }
> 
> schema : #(c:"<xsd:schema>" ( schemaImport | schemaInclude	| element |
> complexType | complexContent | groupDef )* )
>     ;
> 
> schemaImport : imp:"<xsd:import>" 
> 	;
> 
> schemaInclude : inc:"<xsd:include>"
> 	;	
> 
> groupDef: #("<xsd:group>" sequence )
> 	;
> 
> annotation: #("<xsd:annotation>" documentation )
> 	;	
> 
> documentation: "<xsd:documentation>"
> 	;
> 
> complexType: #( "<xsd:complexType>"  ( annotation | sequence |
> attribute | simpleContent | complexContent )* )
> 	;
> 
> complexContent: #( "<xsd:complxContent>" extension )
> 	;
> 
> simpleContent: #( "<xsd:simpleContent>" extension )
> 	;
> 	
> extension: #( "<xsd:extension>" ( attribute | sequence ) )
> 	;
> 	
> sequence: #( "<xsd:sequence>" ( sequence | element | choice | groupRef
> )* )
> 	;
> 	
> choice: #( "<xsd:choice>" ( element | sequence )* )
> 	;	
> 
> groupRef: "<xsd:group>" 	
> 	;
> 	
> attribute: #( "<xsd:attribute>" (simpleType)? )
> 	;	
> 	
> simpleType: #( "<xsd:simpleType>" restriction )	
> 	;
> 	
> restriction: #( "<xsd:restriction>" enumeration )
> 	;
> 	
> enumeration: "<xsd:enumeration>"	
> 	;
> 
> 
> 
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
>  
> 
> 



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list