home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
JFC.bin
/
style-3.2.jj
< prev
next >
Wrap
Text File
|
1998-06-30
|
9KB
|
385 lines
options {
/*
DEBUG_PARSER = true;
DEBUG_LOOKAHEAD = true;
DEBUG_TOKEN_MANAGER = true;
*/
STATIC = false;
USER_CHAR_STREAM=true;
}
PARSER_BEGIN(style32)
package com.sun.java.swing.text.html;
/*
* @(#)style-3.2.jj 1.5 97/10/10
*
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
/**
*
* @version 1.5 10/10/97
* @author Makarand Gokhale
*
*/
/**
* A Style Parser for W3C cascading style sheets
*
* The Parser calls Action methods in a callback to notify about the
* properties values, tag selectors etc
*
* The productions call into a method to deal with the action.
* These methods are called XXXAction where XXX is the name of
* the production. This allows the grammer to be used for
* multiple things without a maintenance burdon.
*
*/
class style32 {
private HTMLStyleCallback callback;
public void setCallback(HTMLStyleCallback cb){
callback = cb;
}
public static void main(String args[]) {
System.out.println("Reading from standard input...");
HTMLStyleCallbackDefault.doDebug = true;
style32 t = new style32(new java.io.InputStreamReader(System.in));
t.setCallback(new HTMLStyleCallbackDefault());
try {
if(args.length > 0){
if(args[0].equalsIgnoreCase("doc"))
t.docstylesheet();
else
t.extstylesheet();
}
else
t.extstylesheet();
System.out.println("Thank you.");
} catch (Exception e) {
System.out.println("Oops.");
System.out.println(e.getMessage());
e.printStackTrace();
}
}
public style32(java.io.Reader reader){
this(new ReaderCharStream(reader, 1,1));
}
public void ReInit(java.io.Reader reader){
ReInit(new ReaderCharStream(reader, 1,1));
}
}
PARSER_END(style32)
// ================================================================
// Skip Comments
SKIP :
{
< ( " " | "\t" | "\n" | "\r" )+ >
| < "<!--" >
| < "-->" >
| < "/*" > : STYLECOMMENT
}
<STYLECOMMENT> SKIP:
{
< ( ~["*"] )+ >
| < "*" ( ~["/"] )+ >
| < "*/" > : DEFAULT
}
TOKEN [IGNORE_CASE] :
{
<STAGO: "<" > : STYLETAG
| <ETAGO: "</" > : STYLETAG
| <A: "a" >
| <ADDRESS: "address" >
| <APPLET: "applet" >
| <AREA: "area" >
| <B: "b" >
| <BASE: "base" >
| <BASEFONT: "basefont" >
| <BIG: "big" >
| <BLOCKQUOTE: "blockquote" >
| <BODY: "body" >
| <BR: "br" >
| <CAPTION: "caption" >
| <CENTER: "center" >
| <CITE: "cite" >
| <CODE: "code" >
| <DD: "dd" >
| <DFN: "dfn" >
| <DIR: "dir" >
| <DIV: "div" >
| <DL: "dl" >
| <DT: "dt" >
| <EM: "em" >
| <FONT: "font" >
| <FORM: "form" >
| <H1: "h1" >
| <H2: "h2" >
| <H3: "h3" >
| <H4: "h4" >
| <H5: "h5" >
| <H6: "h6" >
| <HEAD: "head" >
| <HR: "hr" >
| <HTML: "html" >
| <I: "i" >
| <IMG: "img" >
| <INPUT: "input" >
| <ISINDEX: "isindex" >
| <KBD: "kbd" >
| <LI: "li" >
| <LINK: "link" >
| <MAP: "map" >
| <MENU: "menu" >
| <META: "meta" >
| <OL: "ol" >
| <OPTION: "option" >
| <P: "p" >
| <PARAM: "param" >
| <PRE: "pre" >
| <PROMPT: "prompt" >
| <SAMP: "samp" >
| <SCRIPT: "script" >
| <SELECT: "select" >
| <SMALL: "small" >
| <STRIKE: "strike" >
| <STRONG: "strong" >
| <STYLE: "style" >
| <SUB: "sub" >
| <SUP: "sup" >
| <TABLE: "table" >
| <TD: "td" >
| <TEXTAREA: "textarea" >
| <TH: "th" >
| <TITLE: "title" >
| <TR: "tr" >
| <TT: "tt" >
| <U: "u" >
| <UL: "ul" >
| <VAR: "var" >
| <UNKNOWN: (["a"-"z", "A"-"Z","0"-"9"])+ >
| <DOT: "." > : CLASSNAME
| <COLON: ":" > : PSEUDOCLASS
| <SPROP: "{" > : PROPERTY
| <COMMA: "," >
}
<STYLETAG> SKIP:
{
< ( " " | "\t" | "\n" | "\r" )+ >
}
<STYLETAG> TOKEN [IGNORE_CASE]:
{
<STYLETAG0: "style" > : SATTLIST
}
<SATTLIST> SKIP:
{
< ( " " | "\t" | "\n" | "\r" )+ >
}
<SATTLIST> TOKEN [IGNORE_CASE]:
{
<SA_NAME: "type" >
| <T_EQ: "=" > : SATTVAL
| <TAGC: ">" > : DEFAULT
}
<SATTVAL> TOKEN :
{
<SA_VAL: "\"" ( ~["\""] )* "\"" > : SATTLIST
}
<CLASSNAME> TOKEN :
{
<#ALPHA: ["a"-"z","A"-"Z","_","-","."] >
| <#NUM: ["0"-"9"] >
| <#ALPHANUM: <ALPHA> | <NUM> >
| <C_NAME: <ALPHA> ( <ALPHANUM> )* > :DEFAULT
}
<PSEUDOCLASS> TOKEN [IGNORE_CASE]:
{
<PLINK: "link" > :DEFAULT
| <ACTIVE: "active" > :DEFAULT
| <VISITED: "visited" > :DEFAULT
| <FIRSTLINE: "first-line" > :DEFAULT
| <FIRSTLETTER: "first-letter" > :DEFAULT
}
<PROPERTY> SKIP :
{
< (" " | "\t" | "\n" | "\r")+ >
}
<PROPERTY> TOKEN [IGNORE_CASE]:
{
<#PALPHA: ["a"-"z","A"-"Z","_","-","."] >
| <#PNUM: ["0"-"9"] >
| <#PALPHANUM: <PALPHA> | <PNUM> >
| <P_NAME: <PALPHA> ( <PALPHANUM> )* >
| <PCOLON: ":" > : PROPERTY_VALUE
}
<PROPERTY_VALUE> SKIP :
{
< ( " " | "\t" | "\n" | "\r")+ >
}
<PROPERTY_VALUE> TOKEN [IGNORE_CASE]:
{
<#VALPHA: ["a"-"z","A"-"Z","_","-","."] >
| <#VNUM: ["0"-"9"] >
| <#VSPECIAL: [ "#","%" ] >
| <#VALPHANUM: <VALPHA> | <VNUM> | <VSPECIAL> >
| <P_VALUE: ( <VALPHANUM> )+ >
| <PARENOPEN: "(" >: VALUE_SPECIAL
| <VCOMMA: "," >
| <SEMICOLON: ";" >: PROPERTY
| <EPROP: "}" >: DEFAULT
}
<VALUE_SPECIAL> SKIP :
{
< ( " " | "\t" | "\n" | "\r")+ >
}
<VALUE_SPECIAL> TOKEN [IGNORE_CASE]:
{
<#VSALPHA: ["a"-"z","A"-"Z","_","-","."] >
| <#VSNUM: ["0"-"9"] >
| <#VSSPECIAL: ["/",":","#","%","," , " ", "\t", "\r", "\n"] >
| <#VSALPHANUM: <VSALPHA> | <VSNUM> | <VSSPECIAL> >
| <PS_VALUE: ( <VSALPHANUM> )+ >
| <PARENCLOSE: ")" >: PROPERTY_VALUE
}
// ================================================================
void docstylesheet():{}
{
<STAGO> <STYLETAG0> [ <SA_NAME><T_EQ><SA_VAL>] <TAGC>
extstylesheet()
[<ETAGO> <STYLETAG0> <TAGC>]
}
void extstylesheet():{}
{
(style())*
}
void style():{}
{
tagstyle() (deptagstyle())* (<COMMA> tagstyle() (deptagstyle())*)*
(<SPROP>) { callback.propsOpenAction();}
property() (<SEMICOLON> property())*
<EPROP> { callback.propsCloseAction();}
}
void deptagstyle():{}
{
tagstyle()
{
callback.depTagAction();
}
}
void tagstyle():
{
Token t1=null, t2 = null;
}
{
( LOOKAHEAD(2) tag() <DOT> t2=<C_NAME> | tag() | t1=<DOT> t2=<C_NAME>)
{
if(t1 != null)
callback.tagAction("generic");
if(t2 != null)
callback.classAction(t2.image);
}
pseudoclass()
}
void pseudoclass():
{
Token t = null;
}
{
[(<COLON> ( t=<PLINK> | t=<ACTIVE> | t=<VISITED> | t=<FIRSTLINE> | t=<FIRSTLETTER>) )]
{
if(t != null){
callback.pseudoclassAction(t.image);
t= null;
}
}
}
void property() :
{
Token t= null;
}
{
t=<P_NAME>
{
callback.propertyAction(t.image);
}
<PCOLON> value() ( [<VCOMMA>] value())*
}
void value() :
{
Token t1= null, t2= null, t3= null, t4=null;
}
{
(t1 = <P_VALUE> ) ( t2= <PARENOPEN> t3=<PS_VALUE> t4=<PARENCLOSE>)?
{
if(t2 != null)
callback.valueAction(t1.image+t2.image+t3.image+t4.image);
else
callback.valueAction(t1.image);
}
}
void tag():
{
Token t = null;
}
{
(t = <A> | t = <ADDRESS> | t = <APPLET> | t = <AREA> | t = <B> | t = <BASE> | t = <BASEFONT>
| t = <BIG> | t = <BLOCKQUOTE> | t = <BODY> | t = <BR> | t = <CAPTION> | t = <CENTER> | t = <CITE>
| t = <CODE> | t = <DD> | t = <DFN> | t = <DIR> | t = <DIV> | t = <DL> | t = <DT> | t = <EM> | t = <FONT>
| t = <FORM> | t = <H1> | t = <H2> | t = <H3> | t = <H4> | t = <H5> | t = <H6> | t = <HEAD> |t = <HR>
|t = <HTML> |t = <I> |t = <IMG> |t = <INPUT> |t = <ISINDEX> |t = <KBD> |t = <LI> |t = <LINK> |t = <MAP> |t = <MENU>
|t = <META> |t = <OL> |t = <OPTION> |t = <P> |t = <PARAM> |t = <PRE> |t = <PROMPT> |t = <SAMP> |t = <SCRIPT>
|t = <SELECT> |t = <SMALL> |t = <STRIKE> |t = <STRONG> |t = <STYLE> |t = <SUB> |t = <SUP> |t = <TABLE>
|t = <TD> |t = <TEXTAREA> |t = <TH> |t = <TITLE> |t = <TR> |t = <TT> |t = <U> |t = <UL> |t = <VAR> |t = <UNKNOWN>)
{
callback.tagAction(t.image);
}
}