Skip to content

zaininnari/CssParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 

Repository files navigation

css parser

CSS parser by Parsing Expression Grammer(解析表現文法)

@license MIT License

depend liblary 以下のライブラリに依存しています。

  • document (ドキュメント)

    OpenpearPEG Documentation http://nimpad.jp/phppeg/

  • source (ソース)

    http://openpear.org/package/PEG
    
  • OpenpearPEG install (PEGのインストール)

      pear channel-discover openpear.org
      pear install openpear/PEG 
    

TODO

  • 引用符の文字列の回避
  • IE bug:color gray bug

specifications (仕様)

  • support vendor prefix
  • support css hacks. (cssハックは現在未対応です。) ** only underscore hack and asterisk hack.
  • セレクタ、プロパティ、値などに含まれるコメントは無視しません。
  • 「text-decoration : underline/**/overline;」は適切な内容ですが、 (「text-decoration : underline overline;」と解釈されます。) コメントを無視すると、「underlineoverline」という不明な値になってしまいます。 パーサでは、コメント部分をそのまま返しますが、 バリデータは適切に変換して処理します。

example

css string

@charset "UTF-8";
@import url("style.css") screen , print;
@font-face {
	src: local("Myfont"),url(Myfont.ttf);
}
@page :left {
	margin-left: 4cm;
}
@media screen {
	p {
		font-size: 16px;
	}
}
* #id.class>:link+:lang(ja) ,
div:first-line[attr]:before:after
{
	font-size: 16px;
	xxxxx-xxxx;       /* unknown */
}    

parser

object(CssParser_Node)[973]
  protected 'type' => string 'root' (length=4)
  protected 'offset' => int 0
  protected 'data' => 
    array
      0 => 
        object(CssParser_Node)[950]
          protected 'type' => string 'atRule' (length=6)
          protected 'offset' => int 0
          protected 'data' => 
            array
              'selector' => 
                object(CssParser_Node)[948]
                  protected 'type' => string '@charset' (length=8)
                  protected 'offset' => int 0
                  protected 'data' => string '@charset' (length=8)
              'value' => 
                object(CssParser_Node)[949]
                  protected 'type' => string 'value' (length=5)
                  protected 'offset' => int 10
                  protected 'data' => string 'UTF-8' (length=5)
      1 => 
        object(CssParser_Node)[954]
          protected 'type' => string 'atRule' (length=6)
          protected 'offset' => int 18
          protected 'data' => 
            array
              'selector' => 
                object(CssParser_Node)[951]
                  protected 'type' => string '@import' (length=7)
                  protected 'offset' => int 18
                  protected 'data' => string '@import' (length=7)
              'value' => 
                object(CssParser_Node)[952]
                  protected 'type' => string 'value' (length=5)
                  protected 'offset' => int 26
                  protected 'data' => string 'url("style.css")' (length=16)
              'mediaType' => 
                object(CssParser_Node)[953]
                  protected 'type' => string 'mediaType' (length=9)
                  protected 'offset' => int 43
                  protected 'data' => string 'screen , print' (length=14)
      2 => 
        object(CssParser_Node)[958]
          protected 'type' => string 'atRule' (length=6)
          protected 'offset' => int 59
          protected 'data' => 
            array
              'selector' => 
                object(CssParser_Node)[955]
                  protected 'type' => string '@font-face' (length=10)
                  protected 'offset' => int 59
                  protected 'data' => string '@font-face' (length=10)
              'block' => 
                array
                  0 => 
                    array
                      'property' => 
                        object(CssParser_Node)[956]
                          protected 'type' => string 'property' (length=8)
                          protected 'offset' => int 73
                          protected 'data' => string 'src' (length=3)
                      'value' => 
                        object(CssParser_Node)[957]
                          protected 'type' => string 'value' (length=5)
                          protected 'offset' => int 78
                          protected 'data' => string 'local("Myfont"),url(Myfont.ttf)' (length=31)
                      'isImportant' => boolean false
      3 => 
        object(CssParser_Node)[962]
          protected 'type' => string 'atRule' (length=6)
          protected 'offset' => int 113
          protected 'data' => 
            array
              'selector' => 
                object(CssParser_Node)[959]
                  protected 'type' => string '@page' (length=5)
                  protected 'offset' => int 113
                  protected 'data' => string '@page :left' (length=11)
              'block' => 
                array
                  0 => 
                    array
                      'property' => 
                        object(CssParser_Node)[960]
                          protected 'type' => string 'property' (length=8)
                          protected 'offset' => int 128
                          protected 'data' => string 'margin-left' (length=11)
                      'value' => 
                        object(CssParser_Node)[961]
                          protected 'type' => string 'value' (length=5)
                          protected 'offset' => int 141
                          protected 'data' => string '4cm' (length=3)
                      'isImportant' => boolean false
      4 => 
        object(CssParser_Node)[970]
          protected 'type' => string 'atRule' (length=6)
          protected 'offset' => int 148
          protected 'data' => 
            array
              'selector' => 
                object(CssParser_Node)[963]
                  protected 'type' => string '@media' (length=6)
                  protected 'offset' => int 148
                  protected 'data' => string '@media screen' (length=13)
              'value' => 
                array
                  0 => 
                    array
                      'selector' => 
                        object(CssParser_Node)[967]
                          protected 'type' => string 'selector' (length=8)
                          protected 'offset' => int 165
                          protected 'data' => string 'p' (length=1)
                      'block' => 
                        array
                          0 => 
                            array
                              'property' => 
                                object(CssParser_Node)[968]
                                  protected 'type' => string 'property' (length=8)
                                  protected 'offset' => int 171
                                  protected 'data' => string 'font-size' (length=9)
                              'value' => 
                                object(CssParser_Node)[969]
                                  protected 'type' => string 'value' (length=5)
                                  protected 'offset' => int 182
                                  protected 'data' => string '16px' (length=4)
                              'isImportant' => boolean false
      5 => 
        object(CssParser_Node)[972]
          protected 'type' => string 'ruleSet' (length=7)
          protected 'offset' => int 193
          protected 'data' => 
            array
              'selector' => 
                object(CssParser_Node)[964]
                  protected 'type' => string 'selector' (length=8)
                  protected 'offset' => int 193
                  protected 'data' => string '* #id.class>:link+:lang(ja) ,
div:first-line[attr]:before:after' (length=63)
              'block' => 
                array
                  0 => 
                    array
                      'property' => 
                        object(CssParser_Node)[965]
                          protected 'type' => string 'property' (length=8)
                          protected 'offset' => int 260
                          protected 'data' => string 'font-size' (length=9)
                      'value' => 
                        object(CssParser_Node)[966]
                          protected 'type' => string 'value' (length=5)
                          protected 'offset' => int 271
                          protected 'data' => string '16px' (length=4)
                      'isImportant' => boolean false
                  1 => 
                    object(CssParser_Node)[971]
                      protected 'type' => string 'unknown' (length=7)
                      protected 'offset' => int 278
                      protected 'data' => string 'xxxxx-xxxx;       /* 宣言の形を成していないもの */
' (length=64)

other

PEAR CodeSniffer

  • PEAR を基準

以下を除外

PEAR.NamingConventions.ValidFunctionName
PEAR.Commenting.FileCommentSniff


--tab-width=4 -v -n --sniffs=PEAR.Files.LineLength,PEAR.Files.IncludingFile,PEAR.Files.LineEndings,PEAR.Classes.ClassDeclaration,PEAR.WhiteSpace.ScopeClosingBrace,PEAR.WhiteSpace.ScopeIndent,PEAR.WhiteSpace.ObjectOperatorIndent,PEAR.Commenting.FunctionComment,PEAR.Commenting.InlineComment,PEAR.Functions.FunctionCallSignature,PEAR.Functions.FunctionCallArgumentSpacing,PEAR.Functions.FunctionDeclaration,PEAR.Functions.ValidDefaultValue,PEAR.ControlStructures.InlineControlStructure,PEAR.ControlStructures.ControlSignature,PEAR.ControlStructures.MultiLineCondition,PEAR.Formatting.MultiLineAssignment,PEAR.NamingConventions.ValidClassName,PEAR.NamingConventions.ValidVariableName ${resource_loc}