private Expression ParseProperty(StyleSyntaxTokenizer tokenizer) { Expression expression = null; StyleSyntaxToken styleSyntaxToken = tokenizer.current; bool flag = styleSyntaxToken.type != StyleSyntaxTokenType.SingleQuote; if (flag) { throw new Exception(string.Format("Unexpected token '{0}' in property expression. Expected ''' token", styleSyntaxToken.type)); } styleSyntaxToken = tokenizer.MoveNext(); bool flag2 = styleSyntaxToken.type != StyleSyntaxTokenType.String; if (flag2) { throw new Exception(string.Format("Unexpected token '{0}' in property expression. Expected 'string' token", styleSyntaxToken.type)); } string text = styleSyntaxToken.text; string text2; bool flag3 = !StylePropertyCache.TryGetSyntax(text, out text2); if (flag3) { throw new Exception("Unknown property '" + text + "' <''> expression."); } bool flag4 = !this.m_ParsedExpressionCache.TryGetValue(text2, out expression); if (flag4) { this.m_CombinatorStack.Push(ExpressionCombinator.Group); expression = this.Parse(text2); } styleSyntaxToken = tokenizer.MoveNext(); bool flag5 = styleSyntaxToken.type != StyleSyntaxTokenType.SingleQuote; if (flag5) { throw new Exception(string.Format("Unexpected token '{0}' in property expression. Expected ''' token", styleSyntaxToken.type)); } styleSyntaxToken = tokenizer.MoveNext(); bool flag6 = styleSyntaxToken.type != StyleSyntaxTokenType.GreaterThan; if (flag6) { throw new Exception(string.Format("Unexpected token '{0}' in property expression. Expected '>' token", styleSyntaxToken.type)); } return(new Expression(ExpressionType.Combinator) { combinator = ExpressionCombinator.Group, subExpressions = new Expression[] { expression } }); }
private Expression ParseProperty(StyleSyntaxTokenizer tokenizer) { Expression exp = null; StyleSyntaxToken token = tokenizer.current; if (token.type != StyleSyntaxTokenType.SingleQuote) { throw new Exception($"Unexpected token '{token.type}' in property expression. Expected ''' token"); } token = tokenizer.MoveNext(); if (token.type != StyleSyntaxTokenType.String) { throw new Exception($"Unexpected token '{token.type}' in property expression. Expected 'string' token"); } string propertyName = token.text; string syntax; if (!StylePropertyCache.TryGetSyntax(propertyName, out syntax)) { throw new Exception($"Unknown property '{propertyName}' <''> expression."); } // Check if it's in the cache first if (!m_ParsedExpressionCache.TryGetValue(syntax, out exp)) { // Expanded property are in a group to honor the precedence rule // Pushing the ExpressionCombinator.Group allow the next call to Parse to stop at this location m_CombinatorStack.Push(ExpressionCombinator.Group); // Recursively call Parse to expand the property syntax exp = Parse(syntax); } token = tokenizer.MoveNext(); if (token.type != StyleSyntaxTokenType.SingleQuote) { throw new Exception($"Unexpected token '{token.type}' in property expression. Expected ''' token"); } token = tokenizer.MoveNext(); if (token.type != StyleSyntaxTokenType.GreaterThan) { throw new Exception($"Unexpected token '{token.type}' in property expression. Expected '>' token"); } var group = new Expression(ExpressionType.Combinator); group.combinator = ExpressionCombinator.Group; group.subExpressions = new Expression[] { exp }; return(group); }
public StyleVariableResolver.Result ResolveVarFunction(ref int index) { this.m_ResolvedVarStack.Clear(); this.m_ValidationExpression = null; bool flag = !this.m_Property.isCustomProperty; StyleVariableResolver.Result result; if (flag) { string syntax; bool flag2 = !StylePropertyCache.TryGetSyntax(this.m_Property.name, out syntax); if (flag2) { Debug.LogAssertion("Unknown style property " + this.m_Property.name); result = StyleVariableResolver.Result.Invalid; return(result); } this.m_ValidationExpression = StyleVariableResolver.s_SyntaxParser.Parse(syntax); } int num; string variableName; StyleVariableResolver.ParseVarFunction(this.m_Sheet, this.m_Handles, ref index, out num, out variableName); StyleVariableResolver.Result result2 = this.ResolveVariable(variableName); bool flag3 = result2 > StyleVariableResolver.Result.Valid; if (flag3) { bool flag4 = result2 == StyleVariableResolver.Result.NotFound && num > 1 && !this.m_Property.isCustomProperty; if (flag4) { StyleValueHandle[] arg_D8_0 = this.m_Handles; int num2 = index + 1; index = num2; StyleValueHandle styleValueHandle = arg_D8_0[num2]; Debug.Assert(styleValueHandle.valueType == StyleValueType.FunctionSeparator, string.Format("Unexpected value type {0} in var function", styleValueHandle.valueType)); bool flag5 = styleValueHandle.valueType == StyleValueType.FunctionSeparator && index + 1 < this.m_Handles.Length; if (flag5) { index++; result2 = this.ResolveFallback(ref index); } } else { this.m_ResolvedValues.Clear(); } } result = result2; return(result); }
public Result ResolveVarFunction(ref int index) { m_ResolvedVarStack.Clear(); m_ValidationExpression = null; if (!m_Property.isCustomProperty) { string syntax; if (!StylePropertyCache.TryGetSyntax(m_Property.name, out syntax)) { Debug.LogAssertion($"Unknown style property {m_Property.name}"); return(Result.Invalid); } m_ValidationExpression = s_SyntaxParser.Parse(syntax); } int argc; string varName; ParseVarFunction(m_Sheet, m_Handles, ref index, out argc, out varName); var result = ResolveVariable(varName); if (result != Result.Valid) { // var() fallback if (result == Result.NotFound && argc > 1 && !m_Property.isCustomProperty) { var h = m_Handles[++index]; Debug.Assert(h.valueType == StyleValueType.FunctionSeparator, $"Unexpected value type {h.valueType} in var function"); if (h.valueType == StyleValueType.FunctionSeparator && index + 1 < m_Handles.Length) { ++index; result = ResolveFallback(ref index); } } else { m_ResolvedValues.Clear(); } } return(result); }
public bool ValidateResolvedValues() { // Cannot validate custom property before it's assigned so it's always true in this case if (m_Property.isCustomProperty) { return(true); } if (!StylePropertyCache.TryGetSyntax(m_Property.name, out var syntax)) { Debug.LogAssertion($"Unknown style property {m_Property.name}"); return(false); } var validationExpression = s_SyntaxParser.Parse(syntax); var result = m_Matcher.Match(validationExpression, m_ResolvedValues); return(result.success); }
public static List <string> GetStyleKeywords(string binding) { if (string.IsNullOrEmpty(binding)) { return(StyleFieldConstants.KLDefault); } var syntaxParser = new StyleSyntaxParser(); #if UNITY_2019_3_OR_NEWER var syntaxFound = StylePropertyCache.TryGetSyntax(binding, out var syntax); #else var syntaxFound = StyleFieldConstants.StylePropertySyntaxCache.TryGetValue(binding, out var syntax); #endif if (!syntaxFound) { return(StyleFieldConstants.KLDefault); } var expression = syntaxParser.Parse(syntax); if (expression == null) { return(StyleFieldConstants.KLDefault); } var hasAuto = FindKeywordInExpression(expression, StyleFieldConstants.KeywordAuto); var hasNone = FindKeywordInExpression(expression, StyleFieldConstants.KeywordNone); if (hasAuto) { return(StyleFieldConstants.KLAuto); } else if (hasNone) { return(StyleFieldConstants.KLNone); } return(StyleFieldConstants.KLDefault); }
private Expression ParseDataType(StyleSyntaxTokenizer tokenizer) { Expression exp = null; StyleSyntaxToken token = tokenizer.current; if (token.type != StyleSyntaxTokenType.LessThan) { throw new Exception($"Unexpected token '{token.type}' in data type expression. Expected '<' token"); } token = tokenizer.MoveNext(); switch (token.type) { case StyleSyntaxTokenType.String: if (StylePropertyCache.TryGetNonTerminalValue(token.text, out var syntaxAlias)) { exp = ParseNonTerminalValue(syntaxAlias); } else { DataType dataType = DataType.None; try { object enumValue = Enum.Parse(typeof(DataType), token.text.Replace("-", ""), true); if (enumValue != null) { dataType = (DataType)enumValue; } } catch (Exception) { throw new Exception($"Unknown data type '{token.text}'"); } exp = new Expression(ExpressionType.Data); exp.dataType = dataType; } tokenizer.MoveNext(); break; case StyleSyntaxTokenType.SingleQuote: exp = ParseProperty(tokenizer); break; default: throw new Exception($"Unexpected token '{token.type}' in data type expression"); } token = tokenizer.current; if (token.type != StyleSyntaxTokenType.GreaterThan) { throw new Exception($"Unexpected token '{token.type}' in data type expression. Expected '>' token"); } tokenizer.MoveNext(); return(exp); }