?? css2.jj
字號:
/* * css2.jj * * Steady State CSS2 Parser * * Copyright (C) 1999, 2003 Steady State Software Ltd. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * To contact the authors of the library, write to Steady State Software Ltd., * 49 Littleworth, Wing, Buckinghamshire, LU7 0JX, England * * http://www.steadystate.com/css/ * mailto:css@steadystate.co.uk * * $Id: css2.jj,v 1.1.1.1 2003/12/28 21:23:02 davidsch Exp $ */options { IGNORE_CASE = true; STATIC = false;// UNICODE_INPUT = false; USER_CHAR_STREAM = true;// DEBUG_TOKEN_MANAGER = true;// DEBUG_PARSER = true;}PARSER_BEGIN(SACParser)package com.steadystate.css.parser;import java.io.*;import java.net.*;import java.util.*;import org.w3c.css.sac.*;import com.steadystate.css.parser.selectors.*;/** * @author David Schweinsberg * @version $Release$ */public class SACParser implements Parser { private InputSource _source = null; private Locale _locale = null; private DocumentHandler _docHandler = null; private ErrorHandler _errHandler = null; private SelectorFactory _selectorFactory = new SelectorFactoryImpl(); private ConditionFactory _conditionFactory = new ConditionFactoryImpl(); private boolean _quiet = true; public SACParser() { this((CharStream) null); } public void setLocale(Locale locale) throws CSSException { _locale = locale; // TODO: Search for requested locale throw new CSSException(CSSException.SAC_NOT_SUPPORTED_ERR); } public void setDocumentHandler(DocumentHandler handler) { _docHandler = handler; } public void setSelectorFactory(SelectorFactory selectorFactory) { _selectorFactory = selectorFactory; } public void setConditionFactory(ConditionFactory conditionFactory) { _conditionFactory = conditionFactory; } public void setErrorHandler(ErrorHandler handler) { _errHandler = handler; } public void parseStyleSheet(InputSource source) throws CSSException, IOException { _source = source; ReInit(getCharStream(source)); try { styleSheet(); } catch (ParseException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e); } } public void parseStyleSheet(String uri) throws CSSException, IOException { parseStyleSheet(new InputSource(uri)); } public void parseStyleDeclaration(InputSource source) throws CSSException, IOException { _source = source; ReInit(getCharStream(source)); try { styleDeclaration(); } catch (ParseException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e); } } public void parseRule(InputSource source) throws CSSException, IOException { _source = source; ReInit(getCharStream(source)); try { styleSheetRuleSingle(); } catch (ParseException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e); } } public String getParserVersion() { return "http://www.w3.org/TR/REC-CSS2"; } public SelectorList parseSelectors(InputSource source) throws CSSException, IOException { _source = source; ReInit(getCharStream(source)); SelectorList sl = null; try { sl = selectorList(); } catch (ParseException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e); } return sl; } public LexicalUnit parsePropertyValue(InputSource source) throws CSSException, IOException { _source = source; ReInit(getCharStream(source)); LexicalUnit lu = null; try { lu = expr(); } catch (ParseException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e); } return lu; } public boolean parsePriority(InputSource source) throws CSSException, IOException { _source = source; ReInit(getCharStream(source)); boolean b = false; try { b = prio(); } catch (ParseException e) { throw new CSSException(CSSException.SAC_SYNTAX_ERR, e.getMessage(), e); } return b; } private CharStream getCharStream(InputSource source) throws CSSException, IOException { if (source.getCharacterStream() != null) { return new ASCII_CharStream(source.getCharacterStream(), 1, 1); } else { // TODO: Handle other sources return null; } } private Locator getLocator() { return null; }}PARSER_END(SACParser)TOKEN_MGR_DECLS :{ private boolean _quiet = true;/* private int getLastNumPos(StringBuffer sb) { int i; for( i = 0; i < sb.length(); i++ ) if( Character.isLetter( sb.charAt( i ) ) ) break; return i - 1; }*/ private String trimBy(StringBuffer s, int left, int right) { int end = s.length(); return s.toString().substring(left, end-right); } private String trimUrl(StringBuffer s) { StringBuffer s1 = new StringBuffer( trimBy(s, 4, 1).trim() ); int end = s1.length() - 1; if ((s1.charAt(0) == '"' && s1.charAt(end) == '"') || (s1.charAt(0) == '\'' && s1.charAt(end) == '\'')) return trimBy(s1, 1, 1); else return s1.toString(); }}<DEFAULT> TOKEN :{ < S: ( " "|"\t"|"\r"|"\n"|"\f" )+ >}<DEFAULT> MORE :{ < "/*" > : COMMENT}<COMMENT> SKIP :{ < "*/" > : DEFAULT}<COMMENT> MORE :{ < ~[] > : COMMENT}<DEFAULT> TOKEN :{ < LBRACE: "{" >| < RBRACE: "}" >| < COMMA: "," >| < DOT: "." >| < SEMICOLON: ";" >| < COLON: ":" >| < ASTERISK: "*" >| < SLASH: "/" >| < PLUS: "+" >| < MINUS: "-" >| < EQUALS: "=" >| < GT: ">" >| < LSQUARE: "[" >| < RSQUARE: "]" >}<DEFAULT> TOKEN :{ < HASH: "#" <NAME> >}<DEFAULT> TOKEN :{ < STRING: <STRING1> | <STRING2> > { matchedToken.image = trimBy(image, 1, 1); }| < RROUND: ")" >}<DEFAULT> TOKEN :{ < #URL: ["!","#","$","%","&","*"-"~"] | <NONASCII> | <ESCAPE> >| < URI: "url(" ( <S> )* ( <STRING> | ( <URL> )* ) ( <S> )* <RROUND> > { matchedToken.image = trimUrl(image); }}<DEFAULT> TOKEN :{ < CDO: "<!--" >| < CDC: "-->" >| < INCLUDES: "~=" >| < DASHMATCH: "|=" >| < IMPORT_SYM: "@import" >| < PAGE_SYM: "@page" >| < MEDIA_SYM: "@media" >| < FONT_FACE_SYM: "@font-face" >| < CHARSET_SYM: "@charset" >| < ATKEYWORD: "@" <IDENT> >| < IMPORTANT_SYM: "!" ( <S> )? "important" >| < INHERIT: "inherit" >| < EMS: <NUM> "em" > { matchedToken.image = trimBy(image, 0, 2); }| < EXS: <NUM> "ex" > { matchedToken.image = trimBy(image, 0, 2); }| < LENGTH_PX: <NUM> "px" > { matchedToken.image = trimBy(image, 0, 2); }| < LENGTH_CM: <NUM> "cm" > { matchedToken.image = trimBy(image, 0, 2); }| < LENGTH_MM: <NUM> "mm" > { matchedToken.image = trimBy(image, 0, 2); }| < LENGTH_IN: <NUM> "in" > { matchedToken.image = trimBy(image, 0, 2); }| < LENGTH_PT: <NUM> "pt" > { matchedToken.image = trimBy(image, 0, 2); }| < LENGTH_PC: <NUM> "pc" > { matchedToken.image = trimBy(image, 0, 2); }| < ANGLE_DEG: <NUM> "deg" > { matchedToken.image = trimBy(image, 0, 3); }| < ANGLE_RAD: <NUM> "rad" > { matchedToken.image = trimBy(image, 0, 3); }| < ANGLE_GRAD: <NUM> "grad" > { matchedToken.image = trimBy(image, 0, 4); }| < TIME_MS: <NUM> "ms" > { matchedToken.image = trimBy(image, 0, 2); }| < TIME_S: <NUM> "s" > { matchedToken.image = trimBy(image, 0, 1); }| < FREQ_HZ: <NUM> "Hz" > { matchedToken.image = trimBy(image, 0, 2); }| < FREQ_KHZ: <NUM> "kHz" > { matchedToken.image = trimBy(image, 0, 3); }| < DIMEN: <NUM> <IDENT> >| < PERCENTAGE: <NUM> "%" > { matchedToken.image = trimBy(image, 0, 1); }| < NUMBER: <NUM> >| < RGB: "rgb(" >| < FUNCTION: <IDENT> "(" >| < IDENT: <NMSTART> ( <NMCHAR> )* >| < #NAME: ( <NMCHAR> )+ >| < NUM: ( ["0"-"9"] )+ | ( ["0"-"9"] )* "." ( ["0"-"9"] )+ >| < UNICODERANGE: "U+" ( <RANGE> | ( <HNUM> "-" <HNUM> ) ) >| < #RANGE: <Q16> | <H> ( (<Q15>)? | <H> ( (<Q14>)? | <H> ( (<Q13>)? | <H> ( (<Q12>)? | <H> ( (<Q11>)? | <H> ) ) ) ) ) >| < #Q16: "?" | "??" | "???" | "????" | "?????" | "??????" >| < #Q15: "?" | "??" | "???" | "????" | "?????" >| < #Q14: "?" | "??" | "???" | "????" >| < #Q13: "?" | "??" | "???" >| < #Q12: "?" | "??" >| < #Q11: "?" >| < #NMSTART: ["a"-"z"] | <NONASCII> | <ESCAPE> >| < #NMCHAR: ["a"-"z","0"-"9","-"] | <NONASCII> | <ESCAPE> >| < #STRING1: "\"" ( ["\t"," ","!","#","$","%","&","("-"~"] | "\\" <NL> | "\'" | <NONASCII> | <ESCAPE> )* "\"" >| < #STRING2: "\'" ( ["\t"," ","!","#","$","%","&","("-"~"] | "\\" <NL> | "\"" | <NONASCII> | <ESCAPE> )* "\'" >| < #NONASCII: ["\u0080"-"\uFFFF"] >| < #ESCAPE: <UNICODE> | ( "\\" [" "-"~","\u0080"-"\uFFFF"] ) >| < #NL: "\n" | "\r\n" | "\r" | "\f" >| < #UNICODE: "\\" <HNUM> ( " " | "\t" | "\r" | "\n" | "\f" )? >| < #HNUM: <H> | <H><H> | <H><H><H> | <H><H><H><H> | <H><H><H><H><H> | <H><H><H><H><H><H> >| < #H: ["0"-"9","a"-"f"] >}<*> TOKEN:{ < UNKNOWN: ~[] > { if (!_quiet) { System.err.println("Illegal character : " + image.toString()); } }}//// stylesheet// : [ CHARSET_SYM S* STRING S* ';' ]?// [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*// [ [ ruleset | media | page | font_face ] [S|CDO|CDC]* ]*// ;//void styleSheet() :{}{ try { { _docHandler.startDocument(_source); } styleSheetRuleList() <EOF> } finally { _docHandler.endDocument(_source); }}void styleSheetRuleList() :{}{ ( charsetRule() )? ( <S> | <CDO> | <CDC> )* ( importRule() ( <S> | <CDO> | <CDC> )* )* ( ( styleRule() | mediaRule() | pageRule() | fontFaceRule() | unknownRule() ) ( <S> | <CDO> | <CDC> )* )*}//// This is used by ASTStyleSheet.insertRule to parse a single rule//void styleSheetRuleSingle() :{}{ ( charsetRule() | importRule() | styleRule() | mediaRule() | pageRule() | fontFaceRule() | unknownRule() )}void charsetRule() :{ Token t;}{ <CHARSET_SYM> ( <S> )* t = <STRING> ( <S> )* <SEMICOLON>}void unknownRule() :{ Token t; String s;}{ t = <ATKEYWORD> { s = skip(); _docHandler.ignorableAtRule(s); }}//// import// : IMPORT_SYM S*// [STRING|URI] S* [ medium [ ',' S* medium]* ]? ';' S*// ;//void importRule() :{ Token t; String s; SACMediaListImpl ml = new SACMediaListImpl();}{ <IMPORT_SYM> ( <S> )* ( t = <STRING> | t = <URI> ) ( <S> )* ( mediaList(ml) )? <SEMICOLON> { _docHandler.importStyle(unescape(t.image), ml, null); }}//// media// : MEDIA_SYM S* medium [ ',' S* medium ]* '{' S* ruleset* '}' S*// ;//void mediaRule() :{ boolean start = false;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -