public override Node Convert(ParsedNode node, Node[] children) { ParsedProperty expressionList = node.FindProperty("Expressions"); return(new MaterialInstance( node.FindAttributeValue("Name"), children, ValueUtil.ParseAttributeListArray(node.FindProperty("ScalarParameterValues")?.Elements), ValueUtil.ParseAttributeListArray(node.FindProperty("TextureParameterValues")?.Elements), ValueUtil.ParseAttributeListArray(node.FindProperty("VectorParameterValues")?.Elements) )); }
internal void BindProperty(ParsedProperty parsedProperty) { var type = this.GetType(); var properties = type.GetProperties().Where(p => p.Name.Equals(parsedProperty.Name)).ToList(); if (properties.Count > 0) { var property = properties[0]; property.SetValue(this, parsedProperty.Value); } else { Console.WriteLine("There are no propety with name: " + parsedProperty.Name); } }
/// <summary> /// Properties /// </summary> public void Visit(ParsedProperty pars) { pars.PrimitiveType = ConvertStringToParsedPrimitiveType(pars.TempPrimitiveType, pars.AsLike == ParsedAsLike.Like); // to code explorer var classNode = GetExplorerListNode(pars.ClassName, CodeExplorerIconType.Block); var parentNode = GetExplorerListNode("Properties", CodeExplorerIconType.Property, classNode); var newNode = CodeItem.Factory.New(CodeExplorerIconType.Property); newNode.DisplayText = pars.Name; newNode.Flags = pars.Flags; newNode.DocumentOwner = pars.FilePath; newNode.GoToLine = pars.Line; newNode.GoToColumn = pars.Column; PushToCodeExplorer(parentNode, newNode); }
private bool ValidatePropertiesValues(string nodeName, ParsedPropertyBag propertyBag, PropertyDefinition[] propertyDefinitions, DocumentProcessorState state) { bool hasProblems = false; foreach (PropertyDefinition propertyDefinition in propertyDefinitions) { ParsedProperty parsedProperty = propertyBag.FindProperty(propertyDefinition.Name); if (null == parsedProperty) { continue; } if (!ValidatePropertyValue(nodeName, parsedProperty, propertyDefinition, state)) { hasProblems = true; } } return(!hasProblems); }
private void ParseProperty(InvocationExpressionSyntax node) { if (node == null || this._currentProperty == null) { return; } var propertyName = this.ParseLambaExpression(node); if (!string.IsNullOrEmpty(propertyName)) { this._currentProperty.PropertyName = propertyName; } // add and reset current property if (this._currentProperty.IsValid()) { this.ParsedEntity.Properties.Add(this._currentProperty); } this._currentProperty = null; }
public void BindingPropertyFromAbstractClass() { var parsedProperty_name = new ParsedProperty() { Name = "name", Value = "the name of invlass" }; var parsedProperty_text = new ParsedProperty() { Name = "text", Value = "the text value" }; var parsedProperty_iValue = new ParsedProperty() { Name = "iValue", Value = 777 }; var parsedProperty_dValue = new ParsedProperty() { Name = "dValue", Value = 777.777 }; var parsedProperty_ArValue = new ParsedProperty() { Name = "ArValue", Value = new double[] { 1.0, 2.0, 3.14 } }; var inhObject = new InhClass(); inhObject.BindProperty(parsedProperty_name); inhObject.BindProperty(parsedProperty_text); inhObject.BindProperty(parsedProperty_iValue); inhObject.BindProperty(parsedProperty_dValue); inhObject.BindProperty(parsedProperty_ArValue); Assert.AreEqual(parsedProperty_name.Value, inhObject.name); Assert.AreEqual(parsedProperty_text.Value, inhObject.text); Assert.AreEqual(parsedProperty_iValue.Value, inhObject.iValue); Assert.AreEqual(parsedProperty_dValue.Value, inhObject.dValue); Assert.AreEqual(parsedProperty_ArValue.Value, inhObject.ArValue); }
private void ParseColumnName(InvocationExpressionSyntax node) { if (node == null || this.ParsedEntity == null) { return; } var columnName = node .ArgumentList .DescendantNodes() .OfType <LiteralExpressionSyntax>() .Select(t => t.Token.ValueText) .FirstOrDefault(); if (string.IsNullOrEmpty(columnName)) { return; } this._currentProperty = new ParsedProperty { ColumnName = columnName }; }
public void Visit(ParsedProperty pars) { AppendEverything(pars); }
private bool ValidatePropertyValue(string nodeName, ParsedProperty parsedProperty, PropertyDefinition propertyDefinition, DocumentProcessorState state, bool testForArray = true) { bool wasValid = false; if (testForArray && propertyDefinition.IsArray) { if (!parsedProperty.IsArray) { wasValid = false; state.AddError($"Property \"{propertyDefinition.Name}\" on \"{nodeName}\" was expected to be an array but got something else"); return(false); } else { wasValid = true; foreach (var parsedPropertyElement in parsedProperty.Elements) { if (!ValidatePropertyValue(nodeName, parsedPropertyElement, propertyDefinition, state, false)) { wasValid = false; } } } } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.AttributeList)) { ValueUtil.TryParseAttributeList(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.BlendMode)) { ValueUtil.TryParseBlendMode(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.DecalBlendMode)) { ValueUtil.TryParseDecalBlendMode(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.Boolean)) { ValueUtil.TryParseBoolean(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.ExpressionReference)) { ValueUtil.TryParseExpressionReference(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.Float)) { ValueUtil.TryParseFloat(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.FunctionReference)) { ValueUtil.TryParseFunctionReference(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.Integer)) { ValueUtil.TryParseInteger(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.MaterialDomain)) { ValueUtil.TryParseMaterialDomain(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.SamplerType)) { ValueUtil.TryParseSamplerType(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.ShadingModel)) { ValueUtil.TryParseShadingModel(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.String)) { wasValid = true; } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.ResourceReference)) { ValueUtil.TryParseResourceReference(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.TranslucencyLightingMode)) { ValueUtil.TryParseTranslucencyLightingMode(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.Rotator)) { ValueUtil.TryParseRotator(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.Mobility)) { ValueUtil.TryParseMobility(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.WorldPositionIncludedOffsets)) { ValueUtil.TryParseWorldPositionIncludedOffsets(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.MaterialSceneAttributeInputMode)) { ValueUtil.TryParseMaterialSceneAttributeInputMode(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.SceneTextureId)) { ValueUtil.TryParseSceneTextureId(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.MaterialVectorCoordTransformSource)) { ValueUtil.TryParseMaterialVectorCoordTransformSource(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.MaterialVectorCoordTransform)) { ValueUtil.TryParseMaterialVectorCoordTransform(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.Vector2)) { ValueUtil.TryParseVector2(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.Vector3)) { ValueUtil.TryParseVector3(parsedProperty.Value, out wasValid); } else if (propertyDefinition.DataType.HasFlag(PropertyDataType.Vector4)) { ValueUtil.TryParseVector4(parsedProperty.Value, out wasValid); } else { state.AddError($"Property \"{parsedProperty.Name} on \"{nodeName}\" had unhandled data type: {propertyDefinition.DataType}"); return(false); } if (!wasValid) { state.AddError($"Property \"{parsedProperty.Name}\" on \"{nodeName}\" value is invalid: {parsedProperty.Value}"); } return(wasValid); }
/// <summary> /// Matches a new definition /// </summary> private void CreateParsedDefine(Token defineToken, bool isDynamic) { /* * all DEFINE and CREATE statement */ // info we will extract from the current statement : string name = ""; ParseFlag flags = isDynamic ? ParseFlag.Dynamic : 0; ParsedAsLike asLike = ParsedAsLike.None; ParseDefineType type = ParseDefineType.None; string tempPrimitiveType = ""; string viewAs = ""; string bufferFor = ""; string getModifier = ""; string setModifier = ""; string tempModifier = ""; int extent = 0; _lastTokenWasSpace = true; StringBuilder left = new StringBuilder(); // for temp tables: string likeTable = ""; bool isTempTable = false; var fields = new List <ParsedField>(); ParsedField currentField = new ParsedField("", "", "", 0, 0, "", "", ParsedAsLike.None); StringBuilder useIndex = new StringBuilder(); // for tt indexes var indexList = new List <ParsedIndex>(); string indexName = ""; var indexFields = new List <string>(); ParsedIndexFlag indexFlags = ParsedIndexFlag.None; var indexSort = "+"; // + for ascending, - for descending Token token; Token nextToken; Token prevToken; int state = 0; do { token = PeekAt(1); // next token if (token is TokenEos) { if (state == 14) { continue; } nextToken = PeekAtNextType <TokenWord>(1); if (!(nextToken is TokenWord)) { break; } if (nextToken.Value.ToLower() == "get") { continue; } if (nextToken.Value.ToLower() == "set") { continue; } if (nextToken.Value.ToLower() == "private") { continue; } if (nextToken.Value.ToLower() == "protected") { continue; } if (nextToken.Value.ToLower() == "public") { continue; } break; } if (token is TokenComment) { continue; } string lowerToken; bool matchedLikeTable = false; switch (state) { case 0: // matching until type of define is found if (!(token is TokenWord)) { break; } lowerToken = token.Value.ToLower(); switch (lowerToken) { case "buffer": case "browse": case "stream": case "button": case "dataset": case "frame": case "query": case "image": case "menu": case "rectangle": case "sub-menu": case "parameter": if (!Enum.TryParse(lowerToken, true, out type)) { type = ParseDefineType.None; } state++; break; case "event": type = ParseDefineType.Event; state++; break; case "property": type = ParseDefineType.Property; state++; break; case "data-source": type = ParseDefineType.DataSource; state++; break; case "var": case "variable": type = ParseDefineType.Variable; state++; break; case "temp-table": case "work-table": case "workfile": isTempTable = true; state++; break; case "new": flags |= ParseFlag.New; break; case "global": flags |= ParseFlag.Global; break; case "shared": flags |= ParseFlag.Shared; break; case "private": flags |= ParseFlag.Private; break; case "protected": flags |= ParseFlag.Protected; break; case "public": flags |= ParseFlag.Public; break; case "static": flags |= ParseFlag.Static; break; case "abstract": flags |= ParseFlag.Abstract; break; case "override": flags |= ParseFlag.Override; break; case "serializable": flags |= ParseFlag.Serializable; break; case "input": flags |= ParseFlag.Input; break; case "return": flags |= ParseFlag.Return; break; case "output": flags |= ParseFlag.Output; break; case "input-output": flags |= ParseFlag.InputOutput; break; /*default: * ParseFlag parsedFlag; * if (Enum.TryParse(lowerToken, true, out parsedFlag)) * flags |= parsedFlag; * break;*/ } break; case 1: // matching the name if (!(token is TokenWord)) { break; } name = token.Value; if ((type == ParseDefineType.Variable) || (type == ParseDefineType.Property)) { state = 10; } if (type == ParseDefineType.Buffer) { tempPrimitiveType = "buffer"; state = 81; } if (type == ParseDefineType.Parameter) { lowerToken = token.Value.ToLower(); switch (lowerToken) { case "buffer": tempPrimitiveType = lowerToken; type = ParseDefineType.Buffer; flags |= ParseFlag.Parameter; state = 80; break; case "table": case "table-handle": case "dataset": case "dataset-handle": tempPrimitiveType = lowerToken; state = 80; break; default: state = 10; break; } } if (isTempTable) { state = 20; } if (state != 1) { break; } state = 99; break; case 10: // define variable : match as or like if (!(token is TokenWord)) { break; } lowerToken = token.Value.ToLower(); if (lowerToken.Equals("as")) { asLike = ParsedAsLike.As; } else if (lowerToken.Equals("like")) { asLike = ParsedAsLike.Like; } if (asLike != ParsedAsLike.None) { state = 11; } break; case 11: // define variable : match a primitive type or a field in db if (!(token is TokenWord)) { break; } tempPrimitiveType = token.Value; state = 12; break; case 12: // define variable : match a view-as (or extent) AddTokenToStringBuilder(left, token); if (!(token is TokenWord)) { break; } lowerToken = token.Value.ToLower(); if (lowerToken.Equals("view-as")) { state = 13; } if (lowerToken.Equals("extent")) { extent = GetExtentNumber(2); } if (type == ParseDefineType.Property) { if ((lowerToken == "get") || (lowerToken == "set")) { prevToken = PeekAtNextNonType <TokenWhiteSpace>(0, true); nextToken = PeekAtNextNonType <TokenWhiteSpace>(1); if (prevToken is TokenWord) { tempModifier = String.Format("{0} {1}", prevToken.Value.ToUpper(), lowerToken.ToUpper()); } else { tempModifier = lowerToken.ToUpper(); } if (nextToken is TokenSymbol && nextToken.Value.Equals("(")) { state = 14; } if (lowerToken == "get") { getModifier = tempModifier; } else { setModifier = tempModifier; } } } break; case 13: // define variable : match a view-as AddTokenToStringBuilder(left, token); if (!(token is TokenWord)) { break; } viewAs = token.Value; state = 99; break; case 14: if (!(token is TokenWord)) { break; } lowerToken = token.Value.ToLower(); if ((lowerToken == "get") || (lowerToken == "set")) { prevToken = PeekAtNextNonType <TokenWhiteSpace>(0, true); if ((prevToken is TokenWord) && (prevToken.Value.ToLower() == "end")) { state = 12; } } break; case 20: // define temp-table if (!(token is TokenWord)) { break; } lowerToken = token.Value.ToLower(); switch (lowerToken) { case "field": // matches FIELD state = 22; break; case "index": // matches INDEX state = 25; break; case "use-index": // matches USE-INDEX (after a like/like-sequential, we can have this keyword) state = 26; break; case "help": // a field has a help text: state = 27; break; case "initial": // a field has an initial value state = 29; break; case "format": // a field has a format state = 30; break; case "extent": // a field is extent: currentField.Extent = GetExtentNumber(2); break; default: // matches a LIKE table // ReSharper disable once ConditionIsAlwaysTrueOrFalse, resharper doesn't get this one if ((lowerToken.Equals("like") || lowerToken.Equals("like-sequential")) && !matchedLikeTable) { state = 21; } // After a USE-UNDEX and the index name, we can match a AS PRIMARY for the previously defined index if (lowerToken.Equals("primary") && useIndex.Length > 0) { useIndex.Append("!"); } break; } break; case 21: // define temp-table : match a LIKE table, get the table name in asLike // ReSharper disable once RedundantAssignment matchedLikeTable = true; if (!(token is TokenWord)) { break; } likeTable = token.Value.ToLower(); state = 20; break; case 22: // define temp-table : matches a FIELD name if (!(token is TokenWord)) { break; } currentField = new ParsedField(token.Value, "", "", 0, 0, "", "", ParsedAsLike.None); state = 23; break; case 23: // define temp-table : matches a FIELD AS or LIKE if (!(token is TokenWord)) { break; } currentField.AsLike = token.Value.EqualsCi("like") ? ParsedAsLike.Like : ParsedAsLike.As; state = 24; break; case 24: // define temp-table : match a primitive type or a field in db if (!(token is TokenWord)) { break; } currentField.TempPrimitiveType = token.Value; // push the field to the fields list fields.Add(currentField); state = 20; break; case 25: // define temp-table : match an index name if (!(token is TokenWord)) { break; } indexName = token.Value; state = 28; break; case 28: // define temp-table : match the definition of the index if (!(token is TokenWord)) { break; } lowerToken = token.Value.ToLower(); if (lowerToken.Equals("unique")) { indexFlags = indexFlags | ParsedIndexFlag.Unique; } else if (lowerToken.Equals("primary")) { indexFlags = indexFlags | ParsedIndexFlag.Primary; } else if (lowerToken.Equals("word-index")) { indexFlags = indexFlags | ParsedIndexFlag.WordIndex; } else if (lowerToken.Equals("ascending")) { // match a sort order for a field indexSort = "+"; var lastField = indexFields.LastOrDefault(); if (lastField != null) { indexFields.RemoveAt(indexFields.Count - 1); indexFields.Add(lastField.Replace("-", "+")); } } else if (lowerToken.Equals("descending")) { // match a sort order for a field indexSort = "-"; var lastField = indexFields.LastOrDefault(); if (lastField != null) { indexFields.RemoveAt(indexFields.Count - 1); indexFields.Add(lastField.Replace("+", "-")); } } else if (lowerToken.Equals("index")) { // matching a new index if (!String.IsNullOrEmpty(indexName)) { indexList.Add(new ParsedIndex(indexName, indexFlags, indexFields.ToList())); } indexName = ""; indexFields.Clear(); indexFlags = ParsedIndexFlag.None; indexSort = "+"; state = 25; } else { // Otherwise, it's a field name indexFields.Add(token.Value + indexSort); } break; case 26: // define temp-table : match a USE-INDEX name if (!(token is TokenWord)) { break; } useIndex.Append(","); useIndex.Append(token.Value); state = 20; break; case 27: // define temp-table : match HELP for a field if (!(token is TokenString)) { break; } currentField.Description = GetTokenStrippedValue(token); state = 20; break; case 29: // define temp-table : match INITIAL for a field if (!(token is TokenWhiteSpace)) { currentField.InitialValue = GetTokenStrippedValue(token); state = 20; } break; case 30: // define temp-table : match FORMAT for a field if (!(token is TokenWhiteSpace)) { currentField.Format = GetTokenStrippedValue(token); state = 20; } break; case 80: // define parameter : match a temptable, table, dataset or buffer name if (!(token is TokenWord)) { break; } if (token.Value.ToLower().Equals("for")) { break; } name = token.Value; state++; break; case 81: // match the table/dataset name that the buffer or handle is FOR if (!(token is TokenWord)) { break; } lowerToken = token.Value.ToLower(); if (lowerToken.Equals("for") || lowerToken.Equals("temp-table")) { break; } bufferFor = lowerToken; state = 99; break; case 99: // matching the rest of the define AddTokenToStringBuilder(left, token); break; } } while (MoveNext()); if (state <= 1) { return; } if (!string.IsNullOrEmpty(indexName)) { indexList.Add(new ParsedIndex(indexName, indexFlags, indexFields)); } if (isTempTable) { // TEMP-TABLE var newTable = new ParsedTable(name, defineToken, ParsedTableType.TT, null, null, name, null, likeTable, fields, indexList, new List <ParsedTrigger>(), useIndex.ToString(), false, false) { // = end position of the EOS of the statement EndPosition = token.EndPosition, Flags = flags }; AddParsedItem(newTable, defineToken.OwnerNumber); } else if (type == ParseDefineType.Property) { var newProperty = new ParsedProperty(name, defineToken, GetCurrentBlock <ParsedScope>(), tempPrimitiveType) { Flags = flags, EndPosition = token.EndPosition, GetString = getModifier, SetString = setModifier }; AddParsedItem(newProperty, defineToken.OwnerNumber); } else { // other DEFINE var newDefine = NewParsedDefined(name, flags, defineToken, token, asLike, left.ToString(), type, tempPrimitiveType, viewAs, bufferFor, extent); AddParsedItem(newDefine, defineToken.OwnerNumber); // case of a parameters, add it to the current scope (if procedure) var currentScope = GetCurrentBlock <ParsedScopeBlock>() as ParsedProcedure; if (type == ParseDefineType.Parameter && currentScope != null) { if (currentScope.Parameters == null) { currentScope.Parameters = new List <ParsedDefine>(); } currentScope.Parameters.Add(newDefine); } } }