public ValueCell(StructField def, IConvertible value, string displayValue, int offset) : base(def) { _value = value; _displayValue = displayValue; _offset = offset; }
protected ReferenceBase(StructField baseField, string attrName, string targetName, TextPosition position) { _baseField = baseField; _attrName = attrName; _targetName = targetName; _position = position; }
internal void SetFieldAttribute(StructField field, string key, string value, TextPosition pos) { if (field == null) return; Type fieldType = field.GetType(); while(true) { Dictionary<string, AttributeType> fieldsForType; if (_registry.TryGetValue(fieldType, out fieldsForType)) { AttributeType attrType; if (fieldsForType.TryGetValue(key, out attrType)) { SetFieldAttributeValue(field, key, attrType, value, pos); return; } } if (fieldType.Equals(typeof(StructField))) break; fieldType = fieldType.BaseType; } try { field.SetAttribute(key, value); } catch(Exception) { throw new ParseException("Unknown attribute " + key, pos); } }
private void LoadFieldGroup(StructLexer lexer, StructDef structDef, StructField parentField) { lexer.GetNextToken(StructTokenType.OpenCurly); StructField linkToField = null; while (lexer.PeekNextToken() != StructTokenType.CloseCurly) { StructField field = LoadField(lexer, structDef, parentField); if (field != null) { bool isLinked = false; if (linkToField != null) { isLinked = linkToField.CanLinkField(field); } if (isLinked) { linkToField.LinkField(field); } else { linkToField = field; } field.Validate(); } } lexer.GetNextToken(StructTokenType.CloseCurly); }
private StructField LoadField(StructLexer lexer, StructDef structDef, StructField parentField) { List <Attribute> attrs = new List <Attribute>(); LoadAttributes(lexer, attrs); TextPosition fieldPosition = lexer.CurrentPosition; string fieldType = lexer.GetNextToken(StructTokenType.String); StructField field = null; try { field = _fieldFactory.CreateField(structDef, fieldType, _attributeRegistry); field.Name = fieldType; field.Position = fieldPosition; } catch (Exception ex) { _errors.Add(new ParseException(ex.Message, fieldPosition)); } LoadAttributes(lexer, attrs); if (lexer.PeekNextToken() != StructTokenType.Semicolon && lexer.PeekNextToken() != StructTokenType.OpenCurly) { TextPosition pos = lexer.CurrentPosition; string tag = lexer.GetNextToken(StructTokenType.String); LoadAttributes(lexer, attrs); if (field != null) { _attributeRegistry.SetFieldAttribute(field, field.DefaultAttribute, tag, pos); } } foreach (Attribute attr in attrs) { _attributeRegistry.SetFieldAttribute(field, attr.Key, attr.Value, attr.Position); } if (lexer.PeekNextToken() == StructTokenType.OpenCurly) { LoadFieldGroup(lexer, structDef, field); } else { lexer.GetNextToken(StructTokenType.Semicolon); } if (field != null) { field.EndPosition = lexer.LastTokenEndPosition; if (parentField == null) { structDef.AddField(field); } else { parentField.AddChildField(field); } } return(field); }
internal void LinkField(StructField field) { if (_linkedFields == null) { _linkedFields = new List <StructField>(); } _linkedFields.Add(field); field._linkedToField = this; }
public void AddChildField(StructField field) { if (!_acceptsChildren) { throw new Exception("Field does not accept children"); } if (_childFields == null) { _childFields = new List <StructField>(); } _childFields.Add(field); }
internal void SetFieldAttribute(StructField field, string key, string value, TextPosition pos) { if (field == null) { return; } Type fieldType = field.GetType(); while (true) { Dictionary <string, AttributeType> fieldsForType; if (_registry.TryGetValue(fieldType, out fieldsForType)) { AttributeType attrType; if (fieldsForType.TryGetValue(key, out attrType)) { SetFieldAttributeValue(field, key, attrType, value, pos); return; } } if (fieldType.Equals(typeof(StructField))) { break; } fieldType = fieldType.BaseType; } try { field.SetAttribute(key, value); } catch (Exception) { throw new ParseException("Unknown attribute " + key, pos); } }
private static void SetFieldAttributeValue(StructField field, string key, AttributeType type, string value, TextPosition pos) { switch (type) { case AttributeType.Expression: try { field.SetAttributeValue(key, ExpressionParser.Parse(value)); } catch (ParseException ex) { throw new ParseException(ex.Message, pos.OffsetBy(ex.Position)); } break; case AttributeType.String: field.SetAttributeValue(key, value); break; case AttributeType.Int: field.SetAttributeValue(key, Int32.Parse(value)); break; case AttributeType.Bool: field.SetAttributeValue(key, (Int32.Parse(value) != 0)); break; case AttributeType.StructRef: field.StructDef.StructFile.AddReference(new StructReference(field, key, value, pos)); break; case AttributeType.EnumRef: field.StructDef.StructFile.AddReference(new EnumReference(field, key, value, pos)); break; } }
public void AddField(StructField field) { _fields.Add(field); }
public ExprCell(StructField def, StructInstance instance, Expression expression) : base(def) { _instance = instance; _expression = expression; }
public void AddChildField(StructField field) { if (!_acceptsChildren) throw new Exception("Field does not accept children"); if (_childFields == null) _childFields = new List<StructField>(); _childFields.Add(field); }
protected internal virtual bool CanLinkField(StructField nextField) { return false; }
public EnumReference(StructField baseField, string attrName, string targetName, TextPosition position) : base(baseField, attrName, targetName, position) { }
private void LoadFieldGroup(StructLexer lexer, StructDef structDef, StructField parentField) { lexer.GetNextToken(StructTokenType.OpenCurly); StructField linkToField = null; while(lexer.PeekNextToken() != StructTokenType.CloseCurly) { StructField field = LoadField(lexer, structDef, parentField); if (field != null) { bool isLinked = false; if (linkToField != null) isLinked = linkToField.CanLinkField(field); if (isLinked) linkToField.LinkField(field); else linkToField = field; field.Validate(); } } lexer.GetNextToken(StructTokenType.CloseCurly); }
internal void LinkField(StructField field) { if (_linkedFields == null) _linkedFields = new List<StructField>(); _linkedFields.Add(field); field._linkedToField = this; }
private static void SetFieldAttributeValue(StructField field, string key, AttributeType type, string value, TextPosition pos) { switch(type) { case AttributeType.Expression: try { field.SetAttributeValue(key, ExpressionParser.Parse(value)); } catch(ParseException ex) { throw new ParseException(ex.Message, pos.OffsetBy(ex.Position)); } break; case AttributeType.String: field.SetAttributeValue(key, value); break; case AttributeType.Int: field.SetAttributeValue(key, Int32.Parse(value)); break; case AttributeType.Bool: field.SetAttributeValue(key, (Int32.Parse(value) != 0)); break; case AttributeType.StructRef: field.StructDef.StructFile.AddReference(new StructReference(field, key, value, pos)); break; case AttributeType.EnumRef: field.StructDef.StructFile.AddReference(new EnumReference(field, key, value, pos)); break; } }
protected internal virtual bool CanLinkField(StructField nextField) { return(false); }
public static StructCell CreateErrorCell(StructField def, string errorMessage) { return(new ValueCell(def, new ErrValue(errorMessage), -1)); }
protected StructCell(StructField def) { _def = def; }
public static StructCell CreateErrorCell(StructField def, string errorMessage) { return new ValueCell(def, new ErrValue(errorMessage), -1); }
private StructField LoadField(StructLexer lexer, StructDef structDef, StructField parentField) { List<Attribute> attrs = new List<Attribute>(); LoadAttributes(lexer, attrs); TextPosition fieldPosition = lexer.CurrentPosition; string fieldType = lexer.GetNextToken(StructTokenType.String); StructField field = null; try { field = _fieldFactory.CreateField(structDef, fieldType, _attributeRegistry); field.Name = fieldType; field.Position = fieldPosition; } catch(Exception ex) { _errors.Add(new ParseException(ex.Message, fieldPosition)); } LoadAttributes(lexer, attrs); if (lexer.PeekNextToken() != StructTokenType.Semicolon && lexer.PeekNextToken() != StructTokenType.OpenCurly) { TextPosition pos = lexer.CurrentPosition; string tag = lexer.GetNextToken(StructTokenType.String); LoadAttributes(lexer, attrs); if (field != null) _attributeRegistry.SetFieldAttribute(field, field.DefaultAttribute, tag, pos); } foreach (Attribute attr in attrs) _attributeRegistry.SetFieldAttribute(field, attr.Key, attr.Value, attr.Position); if (lexer.PeekNextToken() == StructTokenType.OpenCurly) LoadFieldGroup(lexer, structDef, field); else lexer.GetNextToken(StructTokenType.Semicolon); if (field != null) { field.EndPosition = lexer.LastTokenEndPosition; if (parentField == null) structDef.AddField(field); else parentField.AddChildField(field); } return field; }