hotsax.html.sax
Class HtmlParser

java.lang.Object
  extended by hotsax.html.sax.HtmlParser

public class HtmlParser
extends Object

Encapsulates yacc() parser functionality in a Java class for quick code development


Field Summary
static short ANGLE_CLOSE
           
static short ANGLE_END_CLOSE
           
static short ANGLE_END_OPEN
           
static short ANGLE_OPEN
           
static short ATTR
           
static short CDATA_END
           
static short CDATA_START
           
static short COMMENT_END
           
static short COMMENT_START
           
 String DEFAULT_LEXER_NAME
           
static short DOCTYPE_START
           
static short EOF
           
static short EQUAL
           
(package private) static boolean interactive
           
static short NAME
           
static short PI_CLOSE
           
static short PI_OPEN
           
static short SOF
           
(package private)  int statemax
           
(package private)  int stateptr
           
(package private)  int stateptrmax
           
(package private)  int[] statestk
           
static short STRING
           
static short TEXT
           
(package private)  int valptr
           
(package private)  HtmlParserVal[] valstk
           
static short VALUE
           
(package private)  int yychar
           
(package private) static short[] yycheck
           
(package private)  boolean yydebug
           
(package private) static short[] yydefred
           
(package private) static short[] yydgoto
           
static short YYERRCODE
           
(package private)  int yyerrflag
           
(package private) static short YYFINAL
           
(package private) static short[] yygindex
           
(package private) static short[] yylen
           
(package private) static short[] yylhs
           
(package private)  HtmlParserVal yylval
           
(package private)  int yym
           
(package private) static short YYMAXTOKEN
           
(package private)  int yyn
           
(package private) static String[] yyname
           
(package private)  int yynerrs
           
(package private) static short[] yyrindex
           
(package private) static String[] yyrule
           
(package private)  String yys
           
(package private) static short[] yysindex
           
(package private) static int YYSTACKSIZE
           
(package private)  int yystate
           
(package private) static short[] yytable
           
(package private) static int YYTABLESIZE
           
(package private)  String yytext
           
(package private)  HtmlParserVal yyval
           
 
Constructor Summary
HtmlParser()
          Create new HtmlParser with no reader.
HtmlParser(Reader r)
          Create new HtmlParser with specified reader
 
Method Summary
 void addSemanticLexer(String name, SemanticLexer lexer)
          Add a new Semantic Lexer to the hash of available lexers.
(package private)  void debug(String msg)
           
(package private)  void dump_stacks(int count)
           
 ParserDelegate getDelegate()
           
 ParserDelegate getParserDelegate()
          Get the current ParserDelegate
 Reader getReader()
          Return the reader the parser is using.
 SemanticLexer getSemanticLexer(String name)
          Check the possibility of an alternate lexer for this semantic state.
(package private)  boolean init_stacks()
           
 void lexerInit()
          Initialize the lexer hash.
static void main(String[] args)
           
 void revertSemanticLexer()
          Revert the SemanticLexer to the default value.
 void run()
          A default run method, used for operating this parser object in the background.
 void setParserDelegate(ParserDelegate delegate)
          Set the ParserDelegate.
 void setReader(Reader r)
          Set the reader the parser is using.
 void setSemanticLexer(String name)
          Change the lexer to the one specified in the name.
(package private)  void state_drop(int cnt)
           
(package private)  int state_peek(int relative)
           
(package private)  int state_pop()
           
(package private)  void state_push(int state)
           
(package private)  void val_drop(int cnt)
           
(package private)  void val_init()
           
(package private)  HtmlParserVal val_peek(int relative)
           
(package private)  HtmlParserVal val_pop()
           
(package private)  void val_push(HtmlParserVal val)
           
 void yyerror(String error)
           
(package private)  void yylexdebug(int state, int ch)
           
(package private)  int yyparse()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

yydebug

boolean yydebug

yynerrs

int yynerrs

yyerrflag

int yyerrflag

yychar

int yychar

YYSTACKSIZE

static final int YYSTACKSIZE
See Also:
Constant Field Values

statestk

int[] statestk

stateptr

int stateptr

stateptrmax

int stateptrmax

statemax

int statemax

yytext

String yytext

yyval

HtmlParserVal yyval

yylval

HtmlParserVal yylval

valstk

HtmlParserVal[] valstk

valptr

int valptr

SOF

public static final short SOF
See Also:
Constant Field Values

ANGLE_OPEN

public static final short ANGLE_OPEN
See Also:
Constant Field Values

ANGLE_CLOSE

public static final short ANGLE_CLOSE
See Also:
Constant Field Values

ANGLE_END_OPEN

public static final short ANGLE_END_OPEN
See Also:
Constant Field Values

ANGLE_END_CLOSE

public static final short ANGLE_END_CLOSE
See Also:
Constant Field Values

ATTR

public static final short ATTR
See Also:
Constant Field Values

EQUAL

public static final short EQUAL
See Also:
Constant Field Values

VALUE

public static final short VALUE
See Also:
Constant Field Values

STRING

public static final short STRING
See Also:
Constant Field Values

TEXT

public static final short TEXT
See Also:
Constant Field Values

COMMENT_START

public static final short COMMENT_START
See Also:
Constant Field Values

COMMENT_END

public static final short COMMENT_END
See Also:
Constant Field Values

NAME

public static final short NAME
See Also:
Constant Field Values

PI_OPEN

public static final short PI_OPEN
See Also:
Constant Field Values

PI_CLOSE

public static final short PI_CLOSE
See Also:
Constant Field Values

DOCTYPE_START

public static final short DOCTYPE_START
See Also:
Constant Field Values

CDATA_START

public static final short CDATA_START
See Also:
Constant Field Values

CDATA_END

public static final short CDATA_END
See Also:
Constant Field Values

EOF

public static final short EOF
See Also:
Constant Field Values

YYERRCODE

public static final short YYERRCODE
See Also:
Constant Field Values

yylhs

static final short[] yylhs

yylen

static final short[] yylen

yydefred

static final short[] yydefred

yydgoto

static final short[] yydgoto

yysindex

static final short[] yysindex

yyrindex

static final short[] yyrindex

yygindex

static final short[] yygindex

YYTABLESIZE

static final int YYTABLESIZE
See Also:
Constant Field Values

yytable

static final short[] yytable

yycheck

static final short[] yycheck

YYFINAL

static final short YYFINAL
See Also:
Constant Field Values

YYMAXTOKEN

static final short YYMAXTOKEN
See Also:
Constant Field Values

yyname

static final String[] yyname

yyrule

static final String[] yyrule

DEFAULT_LEXER_NAME

public final String DEFAULT_LEXER_NAME
See Also:
Constant Field Values

interactive

static boolean interactive

yyn

int yyn

yym

int yym

yystate

int yystate

yys

String yys
Constructor Detail

HtmlParser

public HtmlParser(Reader r)
Create new HtmlParser with specified reader


HtmlParser

public HtmlParser()
Create new HtmlParser with no reader. One must be set via setReader. Calling setReader will also call lexerInit()

Method Detail

debug

void debug(String msg)

state_push

void state_push(int state)

state_pop

int state_pop()

state_drop

void state_drop(int cnt)

state_peek

int state_peek(int relative)

init_stacks

boolean init_stacks()

dump_stacks

void dump_stacks(int count)

val_init

void val_init()

val_push

void val_push(HtmlParserVal val)

val_pop

HtmlParserVal val_pop()

val_drop

void val_drop(int cnt)

val_peek

HtmlParserVal val_peek(int relative)

getDelegate

public ParserDelegate getDelegate()

yyerror

public void yyerror(String error)

setParserDelegate

public void setParserDelegate(ParserDelegate delegate)
Set the ParserDelegate. Can be a SaxHandlerDelegate or DebugDelegate. Could be used to write a DOM handler too.

Parameters:
ParserDelegate - to set

getParserDelegate

public ParserDelegate getParserDelegate()
Get the current ParserDelegate


lexerInit

public void lexerInit()
Initialize the lexer hash. Setup the default lexer and any others. This is called by the constructor, so new lexers can be added at any time after the parser is built.


getSemanticLexer

public SemanticLexer getSemanticLexer(String name)
Check the possibility of an alternate lexer for this semantic state. E.g. script tags would invoke the ScriptLexer which creates a token stream different than X/HTML markup


setSemanticLexer

public void setSemanticLexer(String name)
Change the lexer to the one specified in the name. If no lexer for this token exists, the previous lexer remains in effect. The state of the current lexer is copied to the new lexer. Note, by default "html" refers to the HtmlLexer which is set when HtmlParser is initialized. However, no html tag is required to set it, it is the first lexe by default. The html tag has no effect. Note: This may change in the future. The existance of a xml processing instruction may switch the lexer from the one.


revertSemanticLexer

public void revertSemanticLexer()
                         throws UnspecifiedSemanticLexerException
Revert the SemanticLexer to the default value. This is signified by the key "default". Under notmal circumstances, this would be HtmlLexer. But it might be different if the xml PI were seen and that specific processing instruction set the lexer to an XML lexer.

Throws:
UnspecifiedSemanticLexerException - thrown if the Default lexer disappeared.

addSemanticLexer

public void addSemanticLexer(String name,
                             SemanticLexer lexer)
Add a new Semantic Lexer to the hash of available lexers. Once set, the parser will switch lexers to to this one. The case is set to lower case before it is stored as a key. The end tag will revert the lexer if set. This handles cases like The lexer must implement SemanticLexer and must be constructed with this parsers Reader (reader.) yyparser.addSemanyicLexer("style", new StyleLexer(yyparser.getReader(), yyparser));

Parameters:
name - The lower case name of the tag or attribute this should key on.
lexer - The SemanticLexer to use when this name token appears.
See Also:
setSemanticLexer

getReader

public Reader getReader()
Return the reader the parser is using.


setReader

public void setReader(Reader r)
Set the reader the parser is using. Also establishes any default and newly defined SemanticLexers


main

public static void main(String[] args)
                 throws IOException
Throws:
IOException

yylexdebug

void yylexdebug(int state,
                int ch)

yyparse

int yyparse()

run

public void run()
A default run method, used for operating this parser object in the background. It is intended for extending Thread or implementing Runnable. Turn off with -Jnorun .



Copyright © 2007-2008. All Rights Reserved.