示例#1
0
        private bool AddTerm(Term value)
        {
            if (_isFraction)
            {
                if (_terms.Length > 0)
                {
                    value  = new PrimitiveTerm(UnitType.Unknown, _terms[0] + "/" + value);
                    _terms = new TermList();
                }

                _isFraction = false;
            }

            if (_functionBuffers.Count > 0)
            {
                _functionBuffers.Peek().TermList.Add(value);
            }
            else if (_terms.Length == 0)
            {
                _terms.AddTerm(value);
            }
            else if (_parsingContext == ParsingContext.InSingleValue)
            {
                _terms.AddTerm(value);
            }
            else
            {
                return(false);
            }

            return(true);
        }
示例#2
0
 public GenericFunction(string name, IEnumerable<Term> arguments)
 {
     Name = name;
     var list = new TermList();
     foreach (var term in arguments)
     {
         list.AddTerm(term);
     }
     Arguments = list;
 }
示例#3
0
        public GenericFunction(string name, IEnumerable <Term> arguments)
        {
            Name = name;
            var list = new TermList();

            foreach (var term in arguments)
            {
                list.AddTerm(term);
            }
            Arguments = list;
        }
示例#4
0
        public GenericFunction(string name, List<Term> arguments)
        {
            this.Name = name;

            var list = new TermList();
            for (int n = 0; n < arguments.Count; n++)
            {
                list.AddTerm(arguments[n]);
                if (n == arguments.Count - 1)
                    break;
                list.AddSeparator(GrammarSegment.Comma);
            }
            this.Arguments = list;
        }
示例#5
0
        private void FinalizeProperty()
        {
            if (_property != null)
            {
                if (_terms.Length > 1)
                {
                    _property.Term = _terms;
                }
                else
                {
                    _property.Term = _terms[0];
                }
            }

            _terms    = new TermList();
            _property = null;
        }
示例#6
0
        public GenericFunction(string name, List <Term> arguments)
        {
            this.Name = name;

            var list = new TermList();

            for (int n = 0; n < arguments.Count; n++)
            {
                list.AddTerm(arguments[n]);
                if (n == arguments.Count - 1)
                {
                    break;
                }
                list.AddSeparator(GrammarSegment.Comma);
            }
            this.Arguments = list;
        }
示例#7
0
        public StyleSheet Parse(string css)
        {
            _selectorFactory = new SelectorFactory();
            _functionBuffers = new Stack <FunctionBuffer>();
            _styleSheet      = new StyleSheet();
            _activeRuleSets  = new Stack <RuleSet>();
            _lexer           = new Lexer(new StylesheetReader(css))
            {
                ErrorHandler = HandleLexerError
            };

            SetParsingContext(ParsingContext.DataBlock);

            var       tokens         = _lexer.Tokens;
            var       t              = 0;
            Exception firstError     = null;
            var       exceptionCount = 0;

            foreach (var token in tokens)
            {
                t++;

                if (_functionBuffers.Count != 0 && (_property == null || token.GrammarSegment == GrammarSegment.CurlyBracketClose))
                {
                    _skipNextProperty = false;
                    _functionBuffers.Clear();
                }
                try
                {
                    if (ParseTokenBlock(token))
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    if (firstError == null)
                    {
                        firstError = ex;
                    }
                    if (exceptionCount == 10)
                    {
                        throw new Exception(firstError.Message, firstError);
                    }
                    exceptionCount++;
                    this._terms            = new TermList();
                    this._skipNextProperty = false;
                    this._property         = null;
                    this._isFraction       = false;
                    this._functionBuffers.Clear();
                    this._activeRuleSets.Clear();
                    SetParsingContext(ParsingContext.DataBlock);
                    continue;
                }

                if (token.GrammarSegment == GrammarSegment.Delimiter && token.ToString() == "*")
                {
                    _skipNextProperty = true;
                    continue;
                }

                HandleLexerError(ParserError.UnexpectedLineBreak, ErrorMessages.Default);
            }

            if (_property != null)
            {
                ParseTokenBlock(SpecialCharacter.Semicolon);
            }

            return(_styleSheet);
        }