@@ -557,208 +557,48 @@ ValidationTypes = {
557557 return result ;
558558 } ,
559559
560- "<bg-size>" : function ( expression ) {
561- //<bg-size> = [ <length> | <percentage> | auto ]{1,2} | cover | contain
562- var result = false ,
563- numeric = "<percentage> | <length> | auto" ;
564-
565- if ( ValidationTypes . isAny ( expression , "cover | contain" ) ) {
566- result = true ;
567- } else if ( ValidationTypes . isAny ( expression , numeric ) ) {
568- result = true ;
569- ValidationTypes . isAny ( expression , numeric ) ;
570- }
571-
572- return result ;
573- } ,
574-
575- "<clip-source>" : function ( expression ) {
576- return ValidationTypes . isAny ( expression , "<uri>" ) ;
577- } ,
578-
579- "<clip-path>" : function ( expression ) {
580- // <basic-shape> || <geometry-box>
581- var result = false ;
582-
583- if ( ValidationTypes . isType ( expression , "<basic-shape>" ) ) {
584- result = true ;
585- if ( expression . hasNext ( ) ) {
586- result = ValidationTypes . isType ( expression , "<geometry-box>" ) ;
587- }
588- } else if ( ValidationTypes . isType ( expression , "<geometry-box>" ) ) {
589- result = true ;
590- if ( expression . hasNext ( ) ) {
591- result = ValidationTypes . isType ( expression , "<basic-shape>" ) ;
592- }
593- }
594-
595- return result && ! expression . hasNext ( ) ;
596-
597- } ,
598-
599- "<filter-function-list>" : function ( expression ) {
600- var result , part , i ;
601- for ( i = 0 , result = true ; result && expression . hasNext ( ) ; i ++ ) {
602- result = ValidationTypes . isAny ( expression , "<filter-function> | <uri>" ) ;
603- }
604-
605- if ( i > 1 && ! result ) {
606- // More precise error message if we fail after the first
607- // parsed <filter-function>.
608- part = expression . peek ( ) ;
609- throw new ValidationError ( "Expected (<filter-function> | <uri>) but found '" + part . text + "'." , part . line , part . col ) ;
610- }
611-
612- return result ;
613-
614- } ,
615-
616- "<repeat-style>" : function ( expression ) {
617- //repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2}
618- var result = false ,
619- values = "repeat | space | round | no-repeat" ,
620- part ;
621-
622- if ( expression . hasNext ( ) ) {
623- part = expression . next ( ) ;
624-
625- if ( ValidationTypes . isLiteral ( part , "repeat-x | repeat-y" ) ) {
626- result = true ;
627- } else if ( ValidationTypes . isLiteral ( part , values ) ) {
628- result = true ;
629-
630- if ( expression . hasNext ( ) && ValidationTypes . isLiteral ( expression . peek ( ) , values ) ) {
631- expression . next ( ) ;
632- }
633- }
634- }
635-
636- return result ;
637-
638- } ,
639-
640- "<shadow>" : function ( expression ) {
641- //inset? && [ <length>{2,4} && <color>? ]
642- var result = false ,
643- count = 0 ,
644- inset = false ,
645- color = false ;
646-
647- if ( expression . hasNext ( ) ) {
648-
649- if ( ValidationTypes . isAny ( expression , "inset" ) ) {
650- inset = true ;
651- }
652-
653- if ( ValidationTypes . isAny ( expression , "<color>" ) ) {
654- color = true ;
655- }
656-
657- while ( ValidationTypes . isAny ( expression , "<length>" ) && count < 4 ) {
658- count ++ ;
659- }
660-
661-
662- if ( expression . hasNext ( ) ) {
663- if ( ! color ) {
664- ValidationTypes . isAny ( expression , "<color>" ) ;
665- }
666-
667- if ( ! inset ) {
668- ValidationTypes . isAny ( expression , "inset" ) ;
669- }
670-
671- }
672-
673- result = ( count >= 2 && count <= 4 ) ;
674-
675- }
676-
677- return result ;
678- } ,
679-
680- "<x-one-radius>" : function ( expression ) {
681- //[ <length> | <percentage> ] [ <length> | <percentage> ]?
682- var result = false ,
683- simple = "<length> | <percentage> | inherit" ;
684-
685- if ( ValidationTypes . isAny ( expression , simple ) ) {
686- result = true ;
687- ValidationTypes . isAny ( expression , simple ) ;
688- }
689-
690- return result ;
691- } ,
692-
693- "<flex>" : function ( expression ) {
694- // http://www.w3.org/TR/2014/WD-css-flexbox-1-20140325/#flex-property
695- // none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]
696- // Valid syntaxes, according to https://developer.mozilla.org/en-US/docs/Web/CSS/flex#Syntax
697- // * none
698- // * <flex-grow>
699- // * <flex-basis>
700- // * <flex-grow> <flex-basis>
701- // * <flex-grow> <flex-shrink>
702- // * <flex-grow> <flex-shrink> <flex-basis>
703- // * inherit
704- var part ,
705- result = false ;
706- if ( ValidationTypes . isAny ( expression , "none | inherit" ) ) {
707- result = true ;
708- } else {
709- if ( ValidationTypes . isType ( expression , "<flex-grow>" ) ) {
710- if ( expression . peek ( ) ) {
711- if ( ValidationTypes . isType ( expression , "<flex-shrink>" ) ) {
712- if ( expression . peek ( ) ) {
713- result = ValidationTypes . isType ( expression , "<flex-basis>" ) ;
714- } else {
715- result = true ;
716- }
717- } else if ( ValidationTypes . isType ( expression , "<flex-basis>" ) ) {
718- result = expression . peek ( ) === null ;
719- }
720- } else {
721- result = true ;
722- }
723- } else if ( ValidationTypes . isType ( expression , "<flex-basis>" ) ) {
724- result = true ;
725- }
726- }
727-
728- if ( ! result ) {
729- // Generate a more verbose error than "Expected <flex>..."
730- part = expression . peek ( ) ;
731- throw new ValidationError ( "Expected (none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]) but found '" + expression . value . text + "'." , part . line , part . col ) ;
732- }
733-
734- return result ;
735- } ,
736-
737- "<text-decoration>" : function ( expression ) {
738- // none | [ underline || overline || line-through || blink ] | inherit
739- var part ,
740- result ,
741- someOf = "[ underline || overline || line-through || blink ]" ,
742- identifiers = { } ,
743- found ;
744-
745- do {
746- part = expression . next ( ) ;
747- found = 0 ;
748- if ( someOf . indexOf ( part ) > - 1 ) {
749- if ( ! identifiers [ part ] ) {
750- identifiers [ part ] = 0 ;
751- }
752- identifiers [ part ] ++ ;
753- found = identifiers [ part ] ;
754- }
755- } while ( found == 1 && expression . hasNext ( ) ) ;
756-
757- result = found == 1 && ! expression . hasNext ( ) ;
758- if ( found === 0 && JSON . stringify ( identifiers ) == '{}' ) {
759- expression . previous ( ) ;
760- }
761- return result ;
762- }
560+ "<bg-size>" :
561+ //<bg-size> = [ <length> | <percentage> | auto ]{1,2} | cover | contain
562+ Matcher . alt ( "cover" , "contain" , Matcher . cast ( "<percentage> | <length> | auto" ) . braces ( 1 , 2 ) ) ,
563+
564+ "<clip-source>" : Matcher . cast ( "<uri>" ) ,
565+
566+ "<clip-path>" :
567+ // <basic-shape> || <geometry-box>
568+ Matcher . cast ( "<basic-shape>" ) . oror ( "<geometry-box>" ) ,
569+
570+ "<filter-function-list>" :
571+ // [ <filter-function> | <uri> ]+
572+ Matcher . cast ( "<filter-function> | <uri>" ) . plus ( ) ,
573+
574+ "<repeat-style>" :
575+ //repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2}
576+ Matcher . alt ( "repeat-x | repeat-y" , Matcher . cast ( "repeat | space | round | no-repeat" ) . braces ( 1 , 2 ) ) ,
577+
578+ "<shadow>" :
579+ //inset? && [ <length>{2,4} && <color>? ]
580+ Matcher . many ( [ true /* length is required */ ] ,
581+ Matcher . cast ( "<length>" ) . braces ( 2 , 4 ) , "inset" , "<color>" ) ,
582+
583+ "<x-one-radius>" :
584+ //[ <length> | <percentage> ] [ <length> | <percentage> ]?
585+ Matcher . cast ( "<length> | <percentage>" ) . braces ( 1 , 2 ) ,
586+
587+ "<flex>" :
588+ // http://www.w3.org/TR/2014/WD-css-flexbox-1-20140325/#flex-property
589+ // none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]
590+ // Valid syntaxes, according to https://developer.mozilla.org/en-US/docs/Web/CSS/flex#Syntax
591+ // * none
592+ // * <flex-grow>
593+ // * <flex-basis>
594+ // * <flex-grow> <flex-basis>
595+ // * <flex-grow> <flex-shrink>
596+ // * <flex-grow> <flex-shrink> <flex-basis>
597+ // * inherit
598+ Matcher . alt ( "none" , "inherit" , Matcher . cast ( "<flex-grow>" ) . then ( Matcher . cast ( "<flex-shrink>" ) . question ( ) ) . oror ( "<flex-basis>" ) ) ,
599+
600+ "<text-decoration>" :
601+ // none | [ underline || overline || line-through || blink ] | inherit
602+ Matcher . oror ( "underline" , "overline" , "line-through" , "blink" )
763603 }
764604} ;
0 commit comments