home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / VCAFE.3.0A / JFC.bin / style-3.2.jj < prev    next >
Text File  |  1998-06-30  |  9KB  |  385 lines

  1. options {
  2. /*
  3.     DEBUG_PARSER = true;
  4.     DEBUG_LOOKAHEAD = true;
  5.     DEBUG_TOKEN_MANAGER = true;
  6.     */
  7.     STATIC = false;
  8.     USER_CHAR_STREAM=true;
  9. }
  10.  
  11. PARSER_BEGIN(style32)
  12.  
  13. package com.sun.java.swing.text.html;
  14. /*
  15.  * @(#)style-3.2.jj    1.5 97/10/10
  16.  * 
  17.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  18.  * 
  19.  * This software is the confidential and proprietary information of Sun
  20.  * Microsystems, Inc. ("Confidential Information").  You shall not
  21.  * disclose such Confidential Information and shall use it only in
  22.  * accordance with the terms of the license agreement you entered into
  23.  * with Sun.
  24.  * 
  25.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  26.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  27.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  28.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  29.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  30.  * THIS SOFTWARE OR ITS DERIVATIVES.
  31.  * 
  32.  */
  33.  
  34.  
  35. /**
  36.  *
  37.  * @version     1.5 10/10/97
  38.  * @author      Makarand Gokhale
  39.  *
  40.  */
  41.  
  42. /**
  43.  * A Style Parser for W3C  cascading style sheets
  44.  *
  45.  * The Parser calls Action methods in a callback to notify about the 
  46.  * properties values, tag selectors etc
  47.  *
  48.  * The productions call into a method to deal with the action.
  49.  * These methods are called XXXAction where XXX is the name of
  50.  * the production.  This allows the grammer to be used for
  51.  * multiple things without a maintenance burdon.
  52.  * 
  53.  */
  54.  
  55. class style32 {
  56.     private    HTMLStyleCallback    callback;
  57.     public void    setCallback(HTMLStyleCallback cb){
  58.         callback = cb;
  59.     }
  60.  
  61.   public static void main(String args[]) {
  62.     System.out.println("Reading from standard input...");
  63.     HTMLStyleCallbackDefault.doDebug = true;
  64.     style32 t = new style32(new java.io.InputStreamReader(System.in));
  65.         t.setCallback(new HTMLStyleCallbackDefault());
  66.     try {
  67.             if(args.length > 0){
  68.                 if(args[0].equalsIgnoreCase("doc"))
  69.               t.docstylesheet();
  70.                 else
  71.               t.extstylesheet();
  72.             }
  73.             else
  74.                 t.extstylesheet();
  75.  
  76.  
  77.       System.out.println("Thank you.");
  78.     } catch (Exception e) {
  79.       System.out.println("Oops.");
  80.       System.out.println(e.getMessage());
  81.       e.printStackTrace();
  82.     }
  83.   }
  84.  
  85.  
  86.     public style32(java.io.Reader reader){
  87.         this(new ReaderCharStream(reader, 1,1));
  88.     }
  89.     public void ReInit(java.io.Reader reader){
  90.         ReInit(new ReaderCharStream(reader, 1,1));
  91.     }
  92. }
  93.  
  94. PARSER_END(style32)
  95.  
  96. // ================================================================
  97.  
  98. // Skip Comments
  99. SKIP :
  100. {
  101.     <        ( " " | "\t" | "\n" | "\r" )+    >
  102. |    <        "<!--"     >
  103. |    <        "-->"     >
  104. | <   "/*"    > : STYLECOMMENT
  105. }
  106.  
  107. <STYLECOMMENT> SKIP:
  108. {
  109.   <   ( ~["*"] )+     >
  110. | <   "*" ( ~["/"] )+     >
  111. | <   "*/"        > : DEFAULT
  112. }
  113.  
  114.  
  115. TOKEN [IGNORE_CASE] :
  116. {
  117.     <STAGO:   "<"       > : STYLETAG
  118. | <ETAGO:   "</"        > : STYLETAG
  119. |    <A:        "a"                >    
  120. |    <ADDRESS:    "address"            >    
  121. |    <APPLET:    "applet"            >    
  122. |    <AREA:        "area"                >    
  123. |    <B:        "b"                >    
  124. |    <BASE:        "base"                >    
  125. |    <BASEFONT:    "basefont"            >    
  126. |    <BIG:        "big"                >    
  127. |    <BLOCKQUOTE:    "blockquote"            >    
  128. |    <BODY:        "body"                >    
  129. |    <BR:        "br"                >    
  130. |    <CAPTION:    "caption"            >    
  131. |    <CENTER:    "center"            >    
  132. |    <CITE:        "cite"                >    
  133. |    <CODE:        "code"                >    
  134. |    <DD:        "dd"                >    
  135. |    <DFN:        "dfn"                >    
  136. |    <DIR:        "dir"                >    
  137. |    <DIV:        "div"                >    
  138. |    <DL:        "dl"                >    
  139. |    <DT:        "dt"                >    
  140. |    <EM:        "em"                >    
  141. |    <FONT:        "font"                >    
  142. |    <FORM:        "form"                >    
  143. |    <H1:        "h1"                >    
  144. |    <H2:        "h2"                >    
  145. |    <H3:        "h3"                >    
  146. |    <H4:        "h4"                >    
  147. |    <H5:        "h5"                >    
  148. |    <H6:        "h6"                >    
  149. |    <HEAD:        "head"                >    
  150. |    <HR:        "hr"                >    
  151. |    <HTML:        "html"                >    
  152. |    <I:        "i"                >    
  153. |    <IMG:        "img"                >    
  154. |    <INPUT:        "input"                >    
  155. |    <ISINDEX:    "isindex"            >    
  156. |    <KBD:        "kbd"                >    
  157. |    <LI:        "li"                >    
  158. |    <LINK:        "link"                >    
  159. |    <MAP:        "map"                >    
  160. |    <MENU:        "menu"                >    
  161. |    <META:        "meta"                >    
  162. |    <OL:        "ol"                >    
  163. |    <OPTION:    "option"            >    
  164. |    <P:        "p"                >    
  165. |    <PARAM:        "param"                >    
  166. |    <PRE:        "pre"                >    
  167. |    <PROMPT:    "prompt"            >    
  168. |    <SAMP:        "samp"                >    
  169. |    <SCRIPT:    "script"            >    
  170. |    <SELECT:    "select"            >    
  171. |    <SMALL:        "small"                >    
  172. |    <STRIKE:    "strike"            >    
  173. |    <STRONG:    "strong"            >    
  174. |    <STYLE:        "style"                >    
  175. |    <SUB:        "sub"                >    
  176. |    <SUP:        "sup"                >    
  177. |    <TABLE:        "table"                >    
  178. |    <TD:        "td"                >    
  179. |    <TEXTAREA:    "textarea"            >    
  180. |    <TH:        "th"                >    
  181. |    <TITLE:        "title"                >    
  182. |    <TR:        "tr"                >    
  183. |    <TT:        "tt"                >    
  184. |    <U:        "u"                >    
  185. |    <UL:        "ul"                >    
  186. |    <VAR:        "var"                >    
  187. | <UNKNOWN: (["a"-"z", "A"-"Z","0"-"9"])+         > 
  188. |    <DOT:            "."                > : CLASSNAME
  189. |    <COLON:        ":"                >    : PSEUDOCLASS
  190. | <SPROP:     "{"                > : PROPERTY
  191. |    <COMMA:    ","    > 
  192.  
  193. }
  194.  
  195. <STYLETAG> SKIP:
  196. {
  197.     <        ( " " | "\t" | "\n" | "\r" )+    >
  198. }
  199. <STYLETAG> TOKEN [IGNORE_CASE]:
  200. {
  201.     <STYLETAG0: "style" > : SATTLIST
  202. }
  203. <SATTLIST> SKIP:
  204. {
  205.     <        ( " " | "\t" | "\n" | "\r" )+    >
  206. }
  207. <SATTLIST> TOKEN [IGNORE_CASE]:
  208. {
  209.     <SA_NAME:    "type"    >
  210. |    <T_EQ: "="    >  : SATTVAL
  211. |    <TAGC: ">"    > : DEFAULT
  212. }
  213.  
  214. <SATTVAL> TOKEN :
  215. {
  216.     <SA_VAL:   "\"" ( ~["\""] )* "\""    > : SATTLIST
  217. }
  218.  
  219. <CLASSNAME> TOKEN :
  220. {
  221.       <#ALPHA:  ["a"-"z","A"-"Z","_","-","."] >
  222.     | <#NUM:    ["0"-"9"]     >
  223.     | <#ALPHANUM: <ALPHA> | <NUM>     >
  224.     | <C_NAME:  <ALPHA> ( <ALPHANUM> )*   > :DEFAULT
  225. }
  226.  
  227. <PSEUDOCLASS> TOKEN [IGNORE_CASE]:
  228. {
  229.    <PLINK:    "link"    >  :DEFAULT
  230. |  <ACTIVE:    "active"    >  :DEFAULT
  231. |  <VISITED:    "visited"    >  :DEFAULT
  232. |  <FIRSTLINE:    "first-line"    >  :DEFAULT
  233. |  <FIRSTLETTER:    "first-letter"    >  :DEFAULT
  234.  
  235. }
  236.  
  237. <PROPERTY> SKIP :
  238. {
  239.     <        (" " | "\t" | "\n" | "\r")+     >
  240. }
  241. <PROPERTY> TOKEN [IGNORE_CASE]:
  242. {
  243.       <#PALPHA:  ["a"-"z","A"-"Z","_","-","."] >
  244.     | <#PNUM:    ["0"-"9"]     >
  245.     | <#PALPHANUM: <PALPHA> | <PNUM>     >
  246.     | <P_NAME:  <PALPHA> ( <PALPHANUM> )*   > 
  247.   | <PCOLON:    ":"    > : PROPERTY_VALUE
  248. }
  249.  
  250. <PROPERTY_VALUE> SKIP :
  251. {
  252.     <    (    " " | "\t" | "\n" | "\r")+     >
  253. }
  254. <PROPERTY_VALUE> TOKEN [IGNORE_CASE]:
  255. {
  256.       <#VALPHA:  ["a"-"z","A"-"Z","_","-","."] >
  257.     | <#VNUM:    ["0"-"9"]     >
  258.     | <#VSPECIAL: [ "#","%" ] >
  259.     | <#VALPHANUM: <VALPHA> | <VNUM>  | <VSPECIAL>    >
  260.     | <P_VALUE:  ( <VALPHANUM> )+   > 
  261.     | <PARENOPEN: "("  >: VALUE_SPECIAL
  262.     | <VCOMMA: "," >
  263.     | <SEMICOLON:    ";"    >: PROPERTY
  264.     |    <EPROP:    "}" >: DEFAULT
  265. }
  266.  
  267.  
  268. <VALUE_SPECIAL> SKIP :
  269. {
  270.     <    (    " " | "\t" | "\n" | "\r")+     >
  271. }
  272. <VALUE_SPECIAL> TOKEN [IGNORE_CASE]:
  273. {
  274.       <#VSALPHA:  ["a"-"z","A"-"Z","_","-","."] >
  275.     | <#VSNUM:    ["0"-"9"]     >
  276.     | <#VSSPECIAL:    ["/",":","#","%","," , " ", "\t", "\r", "\n"]     >
  277.     | <#VSALPHANUM: <VSALPHA> | <VSNUM> | <VSSPECIAL>     >
  278.     | <PS_VALUE:  ( <VSALPHANUM> )+   > 
  279.     | <PARENCLOSE: ")"  >: PROPERTY_VALUE
  280.     
  281. }
  282.  
  283.  
  284. // ================================================================
  285.  
  286. void docstylesheet():{}
  287. {
  288.     <STAGO> <STYLETAG0> [ <SA_NAME><T_EQ><SA_VAL>] <TAGC>
  289.     extstylesheet()
  290.     [<ETAGO> <STYLETAG0> <TAGC>]
  291.  
  292. }
  293. void extstylesheet():{}
  294. {
  295.     (style())*
  296. }    
  297. void style():{}
  298. {
  299.     tagstyle() (deptagstyle())*  (<COMMA> tagstyle() (deptagstyle())*)* 
  300.     (<SPROP>) { callback.propsOpenAction();}
  301.     property() (<SEMICOLON> property())*
  302.     <EPROP> { callback.propsCloseAction();}
  303. }    
  304.  
  305. void deptagstyle():{}
  306. {
  307.     tagstyle()
  308.     {
  309.         callback.depTagAction();
  310.     }
  311. }
  312. void tagstyle():
  313. {
  314.     Token t1=null, t2 = null;
  315. }
  316. {
  317.     ( LOOKAHEAD(2) tag() <DOT> t2=<C_NAME> |  tag() | t1=<DOT> t2=<C_NAME>)
  318.     {
  319.         if(t1 != null)
  320.             callback.tagAction("generic");
  321.         if(t2 != null)
  322.             callback.classAction(t2.image);
  323.     }
  324.     pseudoclass()
  325. }
  326.  
  327. void pseudoclass():
  328. {
  329.     Token t = null;
  330. }
  331. {
  332.     [(<COLON> ( t=<PLINK> | t=<ACTIVE> | t=<VISITED> | t=<FIRSTLINE> | t=<FIRSTLETTER>) )]
  333.     {
  334.         if(t != null){
  335.             callback.pseudoclassAction(t.image);
  336.             t= null;
  337.         }
  338.     }
  339. }
  340.  
  341. void property() :
  342. {
  343.     Token t= null;
  344. }
  345. {
  346.     t=<P_NAME>
  347.     {
  348.         callback.propertyAction(t.image);
  349.     }    
  350.     <PCOLON> value() ( [<VCOMMA>] value())*
  351. }
  352.  
  353. void value() :
  354. {
  355.     Token t1= null, t2= null, t3= null, t4=null;
  356. }
  357. {
  358.     (t1 = <P_VALUE> ) ( t2= <PARENOPEN> t3=<PS_VALUE> t4=<PARENCLOSE>)?
  359.     {
  360.         if(t2 != null)
  361.         callback.valueAction(t1.image+t2.image+t3.image+t4.image);
  362.         else
  363.         callback.valueAction(t1.image);
  364.     }    
  365. }
  366.  
  367. void tag():
  368. {
  369.     Token t = null;
  370. }
  371. {
  372.     (t = <A> | t = <ADDRESS> | t = <APPLET> | t = <AREA> | t = <B> | t = <BASE> | t = <BASEFONT>
  373.     | t = <BIG> | t = <BLOCKQUOTE> | t = <BODY> | t = <BR> | t = <CAPTION> | t = <CENTER> | t = <CITE>
  374.     | t = <CODE> | t = <DD> | t = <DFN> | t = <DIR> | t = <DIV> | t = <DL> | t = <DT> | t = <EM> | t = <FONT>
  375.     | t = <FORM> | t = <H1> | t = <H2> | t = <H3> | t = <H4> | t = <H5> | t = <H6> | t = <HEAD> |t = <HR>
  376. |t = <HTML> |t = <I> |t = <IMG> |t = <INPUT> |t = <ISINDEX> |t = <KBD> |t = <LI> |t = <LINK> |t = <MAP> |t = <MENU>
  377. |t = <META> |t = <OL> |t = <OPTION> |t = <P> |t = <PARAM> |t = <PRE> |t = <PROMPT> |t = <SAMP> |t = <SCRIPT>
  378. |t = <SELECT> |t = <SMALL> |t = <STRIKE> |t = <STRONG> |t = <STYLE> |t = <SUB> |t = <SUP> |t = <TABLE>
  379. |t = <TD> |t = <TEXTAREA> |t = <TH> |t = <TITLE> |t = <TR> |t = <TT> |t = <U> |t = <UL> |t = <VAR> |t = <UNKNOWN>)
  380.  
  381.     {
  382.         callback.tagAction(t.image);
  383.     }
  384. }
  385.