private void ValidateExpression(StringTokenizer t) { this.EvaluationPath = new List <AcmaSchemaAttribute>(); this.Transforms = new List <Transform>(); this.Errors = new List <TokenError>(); this.View = HologramView.Proposed; bool hasOptionalData = false; Token token; if (t.CurrentToken == null) { token = t.Next(); } else { token = t.CurrentToken; } int startingPosition = token.Position; if (token.Kind == TokenKind.OpenSquareBracket) { hasOptionalData = true; if (!this.GetPreText(t)) { this.Errors.Add(new TokenError("'{' expected", t.CurrentToken.Line, t.CurrentToken.Column, null, this.context)); return; } } else if (token.Kind != TokenKind.OpenBrace) { this.Errors.Add(new TokenError("'{' expected", token.Line, token.Column, token.Value, this.context)); return; } token = t.Next(); if (token.Kind == TokenKind.Hash) { this.View = HologramView.Current; token = t.Next(); } else if (token.Kind != TokenKind.Word) { this.Errors.Add(new TokenError("'#' or attribute name expected", token.Line, token.Column, token.Value, this.context)); return; } while (true) { Token attributeToken = null; if (token.Kind != TokenKind.Word) { this.Errors.Add(new TokenError("Expected attribute name", token.Line, token.Column, token.Value, this.context)); return; } AcmaSchemaAttribute attribute = null; if (!ActiveConfig.DB.HasAttribute(token.Value)) { this.Errors.Add(new TokenError("The attribute was not found", token.Line, token.Column, token.Value, this.context)); return; } else { attribute = ActiveConfig.DB.GetAttribute(token.Value); attributeToken = token; } token = t.Next(); if (token.Kind == TokenKind.ClosedBrace) { if (this.EvaluationPath.Count == 0) { if (this.objectClass != null) { if (!this.objectClass.HasAttribute(attribute.Name)) { this.Errors.Add(new TokenError(string.Format("Attribute not found in object class '{0}'", this.objectClass.Name), attributeToken.Line, attributeToken.Column, attributeToken.Value, this.context)); return; } } } if (hasOptionalData) { if (!this.GetPostText(t)) { this.Errors.Add(new TokenError("']' expected", t.CurrentToken.Line, t.CurrentToken.Column, null, this.context)); return; } } this.Attribute = attribute; this.Declaration = t.Data.Substring(startingPosition, t.CurrentPosition - startingPosition); return; } else if (token.Kind == TokenKind.ReferenceOperator) { if (attribute.Type != ExtendedAttributeType.Reference) { this.Errors.Add(new TokenError("Non-reference attribute found in reference chain", attributeToken.Line, attributeToken.Column, attributeToken.Value, this.context)); return; } else { if (this.EvaluationPath.Count == 0) { if (this.objectClass != null) { if (!this.objectClass.HasAttribute(attribute.Name)) { this.Errors.Add(new TokenError(string.Format("Attribute not found in object class '{0}'", this.objectClass.Name), attributeToken.Line, attributeToken.Column, attributeToken.Value, this.context)); return; } } } this.EvaluationPath.Add(attribute); token = t.Next(); continue; } } else if (token.Kind == TokenKind.TransformOperator) { this.Attribute = attribute; TransformParser transformTokenizer = new TransformParser(t, TokenKind.ClosedBrace, this.context); if (transformTokenizer.HasErrors) { foreach (TokenError error in transformTokenizer.Errors) { this.Errors.Add(error); } return; } else { if (hasOptionalData) { if (!this.GetPostText(t)) { this.Errors.Add(new TokenError("']' expected", t.CurrentToken.Line, t.CurrentToken.Column, null, this.context)); return; } } this.Transforms = transformTokenizer.Transforms; this.Declaration = t.Data.Substring(startingPosition, t.CurrentPosition - startingPosition); return; } } else { this.Errors.Add(new TokenError("Expected '}', '->' or '>>'", token.Line, token.Column, token.Value, this.context)); return; } } }
private void ValidateExpression(StringTokenizer t) { this.Transforms = new List <Transform>(); this.Errors = new List <TokenError>(); this.VariableParameter = null; this.VariableName = null; Token token; if (t.CurrentToken == null) { token = t.Next(); } else { token = t.CurrentToken; } int startPos = token.Position; // Ensure we are starting with a % if (token.Kind != TokenKind.PercentSign) { this.Errors.Add(new TokenError("'%' expected", token.Line, token.Column, token.Value, this.context)); return; } token = t.Next(); // Make sure the second token is a word if (token.Kind != TokenKind.Word) { this.Errors.Add(new TokenError("Expected variable name", token.Line, token.Column, token.Value, this.context)); return; } // Make sure the variable name we found actually exists if (!VariableDeclaration.GetVariableNames().Contains(token.Value)) { this.Errors.Add(new TokenError("Unknown variable", token.Line, token.Column, token.Value, this.context)); return; } else { this.VariableName = token.Value; } token = t.Next(); // We have reached the end of the declaration if (token.Kind == TokenKind.PercentSign) { this.Declaration = t.Data.Substring(startPos, t.CurrentPosition - startPos); return; } else if (token.Kind == TokenKind.Colon) { token = t.Next(); // Make sure we have a word for the variable parameter if (token.Kind != TokenKind.Word) { this.Errors.Add(new TokenError("Expected variable parameter", token.Line, token.Column, token.Value, this.context)); return; } if (VariableDeclaration.DoesVariableSupportParameters(this.VariableName)) { if (VariableDeclaration.IsValidParameter(this.VariableName, token.Value)) { this.VariableParameter = token.Value; } else { this.Errors.Add(new TokenError(string.Format("Specified parameter was not valid for Variable '{0}'", this.VariableName), token.Line, token.Column, token.Value, this.context)); return; } } else { this.Errors.Add(new TokenError(string.Format("Variable '{0}' does not support parameters", this.VariableName), token.Line, token.Column, token.Value, this.context)); return; } token = t.Next(); // Check to see if we have reached the end of the declaration if (token.Kind == TokenKind.PercentSign) { this.Declaration = t.Data.Substring(startPos, t.CurrentPosition - startPos); return; } } if (token.Kind == TokenKind.TransformOperator) { TransformParser transformTokenizer = new TransformParser(t, TokenKind.PercentSign, this.context); if (transformTokenizer.HasErrors) { foreach (TokenError error in transformTokenizer.Errors) { this.Errors.Add(error); } return; } else { this.Transforms = transformTokenizer.Transforms; this.Declaration = t.Data.Substring(startPos, t.CurrentPosition - startPos); return; } } else // We expect either an declaration end (%), a parameter operator (:), or a transform operator (>>) { this.Errors.Add(new TokenError("Expected '%', ':', '>>'", token.Line, token.Column, token.Value, this.context)); return; } }