@@ -181,6 +181,7 @@ function doEvaluateSyntax(syntaxes, context, options) {
181181 let i = 0 ;
182182 let result ;
183183 let token = null ;
184+ // console.error(`>> doEvaluateSyntax: ${syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${JSON.stringify({syntaxes}, null, 1)}>> context: ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
184185 for ( ; i < syntaxes . length ; i ++ ) {
185186 syntax = syntaxes [ i ] ;
186187 if ( context . done ( ) ) {
@@ -210,6 +211,7 @@ function doEvaluateSyntax(syntaxes, context, options) {
210211 }
211212 else {
212213 if ( isVisited ( token , syntax , 'doEvaluateSyntax' , options ) ) {
214+ // console.error(`cyclic dependency: ${renderSyntax(syntax)}`);
213215 return {
214216 valid : SyntaxValidationResult . Drop ,
215217 node : token ,
@@ -357,6 +359,7 @@ function matchOccurence(syntax, context, options) {
357359 } ;
358360}
359361function match ( syntax , context , options ) {
362+ // console.error(`>> match(): ${renderSyntax(syntax)}\n>> ${JSON.stringify({syntax}, null, 1)}>> context: ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
360363 let success = false ;
361364 let result ;
362365 let token = context . peek ( ) ;
@@ -438,20 +441,17 @@ function match(syntax, context, options) {
438441 context
439442 } ;
440443 }
441- {
442- result = doEvaluateSyntax ( ( getParsedSyntax ( "syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */ , syntax . val + '()' ) ?. [ 0 ] ) . chi , createContext ( token . chi ) , {
443- ...options ,
444- isRepeatable : null ,
445- isList : null ,
446- occurence : null ,
447- atLeastOnce : null
448- } ) ;
449- if ( result . valid == SyntaxValidationResult . Valid ) {
450- context . next ( ) ;
451- result . context = context ;
452- return result ;
453- }
444+ // {
445+ // console.error(JSON.stringify({funcDef: (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntax as ValidationFunctionDefinitionToken).val + '()')?.[0] as ValidationFunctionToken).chi}, null, 1))
446+ //
447+ // const child = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntax as ValidationFunctionDefinitionToken).val + '()')?.[0] as ValidationFunctionToken;
448+ result = match ( getParsedSyntax ( "syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */ , syntax . val + '()' ) ?. [ 0 ] , context , options ) ;
449+ if ( result . valid == SyntaxValidationResult . Valid ) {
450+ context . next ( ) ;
451+ result . context = context ;
452+ return result ;
454453 }
454+ // }
455455 break ;
456456 case ValidationTokenEnum . DeclarationType :
457457 return doEvaluateSyntax ( getParsedSyntax ( "declarations" /* ValidationSyntaxGroupEnum.Declarations */ , syntax . val ) , context , {
@@ -548,6 +548,7 @@ function match(syntax, context, options) {
548548}
549549function matchPropertyType ( syntax , context , options ) {
550550 if ( ! [
551+ 'bg-position' ,
551552 'length-percentage' , 'flex' , 'calc-sum' , 'color' , 'color-base' , 'system-color' , 'deprecated-system-color' ,
552553 'pseudo-class-selector' , 'pseudo-element-selector'
553554 ] . includes ( syntax . val ) ) {
@@ -577,6 +578,96 @@ function matchPropertyType(syntax, context, options) {
577578 return { ...result , context } ;
578579 }
579580 switch ( syntax . val ) {
581+ case 'bg-position' : {
582+ let val ;
583+ let keyworkMatchCount = 0 ;
584+ let lengthMatchCount = 0 ;
585+ let functionMatchCount = 0 ;
586+ let isBGX = false ;
587+ let isBGY = false ;
588+ while ( token != null && keyworkMatchCount + lengthMatchCount + functionMatchCount < 3 ) {
589+ // match one value: keyword or length
590+ success = ( token . typ == EnumToken . FunctionTokenType && wildCardFuncs . includes ( token . val ) ) ;
591+ if ( success ) {
592+ functionMatchCount ++ ;
593+ context . next ( ) ;
594+ token = context . peek ( ) ;
595+ continue ;
596+ }
597+ if ( token . typ == EnumToken . WhitespaceTokenType ) {
598+ context . next ( ) ;
599+ token = context . peek ( ) ;
600+ continue ;
601+ }
602+ if ( token . typ == EnumToken . IdenTokenType ) {
603+ val = token . val . toLowerCase ( ) ;
604+ success = [ 'left' , 'center' , 'right' , 'top' , 'center' , 'bottom' ] . includes ( val ) ;
605+ if ( ! success ) {
606+ break ;
607+ }
608+ keyworkMatchCount ++ ;
609+ if ( keyworkMatchCount > 2 ) {
610+ return {
611+ valid : SyntaxValidationResult . Drop ,
612+ node : token ,
613+ syntax,
614+ error : `expected <length>` ,
615+ context
616+ } ;
617+ }
618+ if ( val == 'left' || val == 'right' ) {
619+ if ( isBGX ) {
620+ return {
621+ valid : SyntaxValidationResult . Drop ,
622+ node : token ,
623+ syntax,
624+ error : `top | bottom | <length-percentage>` ,
625+ context
626+ } ;
627+ }
628+ isBGX = true ;
629+ }
630+ if ( val == 'top' || val == 'bottom' ) {
631+ if ( isBGY ) {
632+ return {
633+ valid : SyntaxValidationResult . Drop ,
634+ node : token ,
635+ syntax,
636+ error : `expected left | right | <length-percentage>` ,
637+ context
638+ } ;
639+ }
640+ isBGY = true ;
641+ }
642+ context . next ( ) ;
643+ token = context . peek ( ) ;
644+ continue ;
645+ }
646+ success = token . typ == EnumToken . LengthTokenType || token . typ == EnumToken . PercentageTokenType || ( token . typ == EnumToken . NumberTokenType && token . val == '0' ) ;
647+ if ( ! success ) {
648+ break ;
649+ }
650+ lengthMatchCount ++ ;
651+ context . next ( ) ;
652+ token = context . peek ( ) ;
653+ }
654+ if ( keyworkMatchCount + lengthMatchCount + functionMatchCount == 0 ) {
655+ return {
656+ valid : SyntaxValidationResult . Drop ,
657+ node : token ,
658+ syntax,
659+ error : `expected <bg-position>` ,
660+ context
661+ } ;
662+ }
663+ return {
664+ valid : SyntaxValidationResult . Valid ,
665+ node : token ,
666+ syntax,
667+ error : '' ,
668+ context
669+ } ;
670+ }
580671 case 'calc-sum' :
581672 success = ( token . typ == EnumToken . FunctionTokenType && mathFuncs . includes ( token . val ) ) ||
582673 // @ts -ignore
0 commit comments