[Htmlparser-cvs] htmlparser/src/org/htmlparser/lexer Lexer.java,1.14,1.15
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-10-20 03:32:08
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer In directory sc8-pr-cvs1:/tmp/cvs-serv26197/lexer Modified Files: Lexer.java Log Message: Removed lexer level AbstractNode. Removed data package from parser level tags. Separated tag creation from recursion in NodeFactory interface. Index: Lexer.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/Lexer.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** Lexer.java 18 Oct 2003 20:50:36 -0000 1.14 --- Lexer.java 20 Oct 2003 01:28:02 -0000 1.15 *************** *** 41,45 **** import org.htmlparser.Node; ! import org.htmlparser.lexer.nodes.AbstractNode; import org.htmlparser.lexer.nodes.PageAttribute; import org.htmlparser.lexer.nodes.NodeFactory; --- 41,45 ---- import org.htmlparser.Node; ! import org.htmlparser.AbstractNode; import org.htmlparser.lexer.nodes.PageAttribute; import org.htmlparser.lexer.nodes.NodeFactory; *************** *** 736,739 **** --- 736,740 ---- mCursor = cursor; ret = getNodeFactory ().createTagNode (this, begin, end, attributes); + ret = getNodeFactory ().scanTagNode (this, ret); } else *************** *** 897,900 **** --- 898,905 ---- /** * Create a new tag node. + * Note that the attributes vector contains at least one element, + * which is the tag name (standalone attribute) at position zero. + * This can be used to decide which type of node to create, or + * gate other processing that may be appropriate. * @param lexer The lexer parsing this tag. * @param start The beginning position of the tag. *************** *** 905,908 **** --- 910,943 ---- { return (new TagNode (lexer.getPage (), start, end, attributes)); + } + + /** + * Scan a new tag node. + * Provides composite tags the opportunity to collect their children by + * scanning forward using the same lexer that created the composite tag. + * On isolating a tag, processing in the lexer is: + * <pre><code> + * Node node = getNodeFactory ().createTagNode (this, begin, end, attributes); + * node = getNodeFactory ().scanTagNode (this, node); + * </code></pre> + * This two step process, allows a node factory to only handle node + * creation if it wishes, and delegate the recursion and scanning of child + * nodes to the original factory. + * Without giving too much implementation details, the low level lexer node + * factory simply returns the same tag, while the higher level parser node + * factory checks for a scanner registered for the node type and if there + * is one, calls the scanner to create the specific type of node, which + * advances the lexer past the children of the node. + * @param lexer The lexer that parsed this tag. + * @param tag The tag (just) created by createTagNode. Although this is + * of type Node, it can safely be cast to the type returned by + * {@link #createTagNode createTagNode}. + * @return Either the same node or a new node containing children. + * In any case the lexer should be positioned to proceed with the isolation + * of the next unknown node. + */ + public Node scanTagNode (Lexer lexer, Node tag) + { + return (tag); } |