private bool ValidateFunction(GenericFunction term, out StyleValueFunction func) { func = StyleValueFunction.Unknown; if (term.Arguments.Length == 0) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.MissingFunctionArgument, string.Format(glossary.missingFunctionArgument, term.Name), m_CurrentLine); return(false); } if (term.Name == k_VariableFunctionName) { func = StyleValueFunction.Var; return(ValidateVarFunction(term)); } try { func = StyleValueFunctionExtension.FromUssString(term.Name); } catch (System.Exception) { var prop = m_Builder.currentProperty; m_Errors.AddValidationWarning(string.Format(glossary.unknownFunction, term.Name, prop.name), prop.line); return(false); } return(true); }
private bool ValidateFunction(GenericFunction term, out StyleValueFunction func) { func = StyleValueFunction.Unknown; if (term.Arguments.Length == 0) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.MissingFunctionArgument, term.Name); return(false); } if (term.Name == k_VariableFunctionName) { func = StyleValueFunction.Var; return(ValidateVarFunction(term)); } try { func = StyleValueFunctionExtension.FromUssString(term.Name); } catch (Exception) { var prop = m_Builder.currentProperty; m_Errors.AddValidationWarning($"Unknown function {term.Name} in declaration {prop.name}: {term.Name}", prop.line); return(false); } return(true); }
private static void AddValues(StyleSheetBuilderHelper helper, IEnumerable <Value> values) { foreach (var value in values) { switch (value.ValueType) { case StyleValueType.Keyword: helper.builder.AddValue(value.AsKeyword()); break; case StyleValueType.Color: helper.builder.AddValue(value.AsColor()); break; case StyleValueType.Float: helper.builder.AddValue(value.AsFloat()); break; case StyleValueType.Dimension: helper.builder.AddValue(value.AsDimension()); break; case StyleValueType.Enum: case StyleValueType.Variable: case StyleValueType.String: case StyleValueType.ResourcePath: helper.builder.AddValue(value.AsString(), value.ValueType); break; case StyleValueType.Function: // First param: function name // Second param: number of arguments // Rest of args: must be saved as values. var functionValue = value as Function; helper.builder.AddValue(StyleValueFunctionExtension.FromUssString(functionValue.AsString())); var nbArgs = functionValue.args.Count - 1; for (var argIndex = 0; argIndex < functionValue.args.Count; ++argIndex) { nbArgs += functionValue.args[argIndex].Length; } helper.builder.AddValue(nbArgs); for (var argIndex = 0; argIndex < functionValue.args.Count; ++argIndex) { AddValues(helper, functionValue.args[argIndex]); if (argIndex < functionValue.args.Count - 1) { helper.builder.AddValue(value.AsString(), StyleValueType.FunctionSeparator); } } break; default: throw new Exception("Unhandled value type: " + value.ValueType); } } }