⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 css2.jj

📁 cssparser -- CSS 的语法解析器。采用java语言编写。可用在服务端生成页面。
💻 JJ
📖 第 1 页 / 共 3 页
字号:
    SACMediaListImpl ml = new SACMediaListImpl();}{    try {        <MEDIA_SYM> ( <S> )*        mediaList(ml)        {            start = true;            _docHandler.startMedia(ml);        }        <LBRACE> ( <S> )*        ( mediaRuleList() )?        <RBRACE>    } finally {        if (start) {            _docHandler.endMedia(ml);        }    }}void mediaList(SACMediaListImpl ml) :{    String s;}{    s = medium()    ( <COMMA> ( <S> )* { ml.add(s); } s = medium() )*    { ml.add(s); }}void mediaRuleList() :{}{  ( ( styleRule() | pageRule() | unknownRule() ) ( <S> )* )+ }void mediaRuleSingle() :{}{  ( styleRule() | pageRule() | unknownRule() )}//// medium//   : IDENT S*//   ;//String medium() :{  Token t;}{  t = <IDENT> ( <S> )* { return t.image; }}//// page//   : PAGE_SYM S* IDENT? pseudo_page? S*//     '{' S* declaration [ ';' S* declaration ]* '}' S*//   ;//void pageRule() :{    Token t = null;    String s = null;    boolean start = false;}{    try {        <PAGE_SYM> ( <S> )*        ( LOOKAHEAD(2) ( t = <IDENT> ( <S> )* ) |        ( t = <IDENT> s = pseudoPage() ( <S> )* ) |        ( s = pseudoPage() ( <S> )* ) )?        //  ( t = <IDENT> { jjtThis.setIdent( t.image ); } )?        //  ( s = pseudoPage() { jjtThis.setPseudoPage( s ); } )? ( <S> )*        <LBRACE> ( <S> )*        {            start = true;            _docHandler.startPage((t != null) ? unescape(t.image) : null, s);        }        ( declaration() )?        ( <SEMICOLON> ( <S> )* ( declaration() )? )*        <RBRACE>    } finally {        if (start) {            _docHandler.endPage((t != null) ? unescape(t.image) : null, s);        }    }}//// pseudoPage//   : ':' IDENT//   ;//String pseudoPage() :{  Token t;}{  <COLON> t = <IDENT> { return t.image; }}//// font_face//   : FONT_FACE_SYM S*//     '{' S* declaration [ ';' S* declaration ]* '}' S*//   ;//void fontFaceRule() :{    boolean start = false;}{    try {        <FONT_FACE_SYM> ( <S> )*        <LBRACE> ( <S> )* { start = true; _docHandler.startFontFace(); }        ( declaration() )?        ( <SEMICOLON> ( <S> )* ( declaration() )? )*        <RBRACE>    } finally {        if (start) {            _docHandler.endFontFace();        }    }}//// operator//   : '/' S* | ',' S* |//   ;//LexicalUnit operator(LexicalUnit prev) :{  Token t;}{  t = <SLASH> ( <S> )*   { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_SLASH); }  | t = <COMMA> ( <S> )* { return new LexicalUnitImpl(prev, LexicalUnit.SAC_OPERATOR_COMMA); }}//// combinator//   : '+' S* | '>' S* |//   ;//char combinator() :{  char c = ' ';}{  ( <PLUS> { c='+'; } ( <S> )*  | <GT> { c='>'; } ( <S> )*  | <S> ( ( <PLUS> { c='+'; } | <GT> { c='>'; } ) ( <S> )* )? )  { return c; }}//// unary_operator//   : '-' | '+'//   ;//char unaryOperator() :{}{  ( <MINUS> { return '-'; } | <PLUS> { return '+'; } )}//// property//   : IDENT S*//   ;//String property() :{    Token t;}{    t = <IDENT> ( <S> )*    { return unescape(t.image); }}//// ruleset//   : selector [ ',' S* selector ]*//     '{' S* declaration [ ';' S* declaration ]* '}' S*//   ;//void styleRule() :{    SelectorList selList = null;    boolean start = false;    boolean noError = true;}{    try {        selList = selectorList()        <LBRACE> ( <S> )*        {            start = true;            _docHandler.startSelector(selList);        }        ( declaration() )?        ( <SEMICOLON> ( <S> )* ( declaration() )? )*        <RBRACE>    } catch(ParseException e) {//        System.err.println("Exception in styleRule()");//        System.err.println(e.getMessage());        noError = false;        error_skipblock();    } finally {        if (start) {            _docHandler.endSelector(selList);        }    }}SelectorList selectorList() :{    SelectorListImpl selList = new SelectorListImpl();    Selector sel;}{    try {        sel = selector()        ( <COMMA> ( <S> )* { selList.add(sel); } sel = selector() )*        {            selList.add(sel);            return selList;        }    } catch (ParseException e) {        System.err.println("Exception in selectorList()");    }}//// selector//   : simple_selector [ combinator simple_selector ]*//   ;//Selector selector() :{    Selector sel;    char comb;}{    try {        sel = simpleSelector(null, ' ')        ( LOOKAHEAD(2) comb = combinator() sel = simpleSelector(sel, comb) )* ( <S> )*        {            return sel;        }    } catch (ParseException e) {        skipSelector();    }}//// simple_selector//   : element_name? [ HASH | class | attrib | pseudo ]* S*//   ;//Selector simpleSelector(Selector sel, char comb) :{    SimpleSelector simpleSel = null;    Condition c = null;}{    (        ( simpleSel = elementName()            ( c = hash(c)            | c = _class(c)            | c = attrib(c)            | c = pseudo(c)            )*        )        |        ( { simpleSel = _selectorFactory.createElementSelector(null, null); }            ( c = hash(c)            | c = _class(c)            | c = attrib(c)            | c = pseudo(c)            )+        )    )    {        if (c != null) {            simpleSel = _selectorFactory.createConditionalSelector(simpleSel, c);        }        if (sel != null) {            switch (comb) {            case ' ':                sel = _selectorFactory.createDescendantSelector(sel, simpleSel);                break;            case '+':                sel = _selectorFactory.createDirectAdjacentSelector(sel.getSelectorType(), sel, simpleSel);                break;            case '>':                sel = _selectorFactory.createChildSelector(sel, simpleSel);                break;            }        } else {            sel = simpleSel;        }        return sel;    }}//// class//   : '.' IDENT//   ;//Condition _class(Condition pred) :{    Token t;}{    <DOT> t = <IDENT>    {        Condition c = _conditionFactory.createClassCondition(null, t.image);        return (pred == null) ? c : _conditionFactory.createAndCondition(pred, c);    }}//// element_name//   : IDENT | '*'//   ;//SimpleSelector elementName() :{    Token t;}{  t=<IDENT>  { return _selectorFactory.createElementSelector(null, unescape(t.image)); }  | <ASTERISK>  { return _selectorFactory.createElementSelector(null, null); }}//// attrib//   : '[' S* IDENT S* [ [ '=' | INCLUDES | DASHMATCH ] S*//     [ IDENT | STRING ] S* ]? ']'//   ;//Condition attrib(Condition pred) :{    Token t;    String name = null;    String value = null;    int type = 0;}{    <LSQUARE> ( <S> )*    t = <IDENT> { name = unescape(t.image); } ( <S> )*    (        (            <EQUALS> { type = 1; }            |            <INCLUDES> { type = 2; }            |            <DASHMATCH> { type = 3; }        )        ( <S> )*        (            t = <IDENT> { value = t.image; }            |            t = <STRING> { value = unescape(t.image); }        )        ( <S> )*    )?    <RSQUARE>    {        Condition c = null;        switch (type) {        case 0:            c = _conditionFactory.createAttributeCondition(name, null, false, null);            break;        case 1:            c = _conditionFactory.createAttributeCondition(name, null, false, value);            break;        case 2:            c = _conditionFactory.createOneOfAttributeCondition(name, null, false, value);            break;        case 3:            c = _conditionFactory.createBeginHyphenAttributeCondition(name, null, false, value);            break;        }        return (pred == null) ? c : _conditionFactory.createAndCondition(pred, c);    }}//// pseudo//   : ':' [ IDENT | FUNCTION S* IDENT S* ')' ]//   ;//Condition pseudo(Condition pred) :{    Condition c;    Token t;    String function;    String arg;}{    <COLON>    (        t = <IDENT>        {            // There appears to be an issue here regarding "first-letter" & "first-line"            String s = unescape(t.image);		    c = _conditionFactory.createPseudoClassCondition(null, s);            return (pred == null)                ? c                : _conditionFactory.createAndCondition(pred, c);        }        |        (            t = <FUNCTION> { function = unescape(t.image); } ( <S> )*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -