private NVExpression ParseNVStringLiteralOrDictionary() { // NVStringLiteralOrDictionary -> { nvText | NVReference } // -> "%" "{" [ NVDictionaryItem { "," NVDictionaryItem } ] "}". NVExpression expr = null; if (CurrentTokenType == TokenType.NVDictionaryPercent) { _scanner.GetToken(); MatchToken(TokenType.NVDictionaryLCurly); if (CurrentTokenType == TokenType.NVDictionaryKey) { ParseNVDictionaryItem(); while (CurrentTokenType == TokenType.NVComma) { _scanner.GetToken(); ParseNVDictionaryItem(); } } MatchToken(TokenType.NVDictionaryRCurly); //TODO: Change to DictionaryExpression, this is just a expr = new NVBoolExpression(false); expr.Position = new Position(GetCurrentTokenPosition()); } else { //TODO: { nvText | NVReference } while (CurrentTokenType != TokenType.NVDoubleQuote) { if (CurrentTokenType == TokenType.NVStringLiteral) { expr = new NVStringExpression(_scanner.CurrentToken.Image); expr.Position = new Position(GetCurrentTokenPosition()); } //TODO make only work in intellisense mode else if (CurrentTokenType == TokenType.Error) { //TODO: check if this is causing CVSI to lock up return(new NVStringExpression("")); } else { AddError(string.Format("Unexpected token type '{0}'", CurrentTokenType)); break; } _scanner.GetToken(); } } return(expr); }
public void ParseBooleanExpression() { Parser parser; NVBoolExpression exprTrue = (NVBoolExpression)GetExpressionFromTemplate("true", out parser); Assert.AreEqual(true, exprTrue.Value); AssertNoErrors(parser); NVBoolExpression exprFalse = (NVBoolExpression)GetExpressionFromTemplate("false", out parser); Assert.AreEqual(false, exprFalse.Value); AssertNoErrors(parser); }
private NVExpression ParseNVRangeOrArray() { // NVRangeOrArray -> ".." NVExpression // -> { "," NVExpression }. NVExpression expr; if (CurrentTokenType == TokenType.NVDoubleDot) { _scanner.GetToken(); ParseNVExpression(); //TODO: replace with NVRangeExpression expr = new NVBoolExpression(false); expr.Position = new Position(GetCurrentTokenPosition()); } else { while (CurrentTokenType != TokenType.NVRBrack) { if (CurrentTokenType == TokenType.NVComma) { _scanner.GetToken(); } else { AddError("Expected ','"); break; } ParseNVExpression(); } //TODO: replace with NVArrayExpression expr = new NVBoolExpression(false); expr.Position = new Position(GetCurrentTokenPosition()); } return(expr); }
private NVExpression ParseNVPrimary() { // NVPrimary -> NVReference // -> "(" NVExpression ")" // -> "true" // -> "false" // -> nvIntegerLiteral // -> "'" nvStringLiteral "'" // -> "\"" NVStringLiteralOrDictionary "\"" // -> "[" [ NVExpression NVRangeOrArray ] "]". NVExpression expr = null; if (CurrentTokenType == TokenType.NVDollar) { //TODO: Change to ParseNVDesignatorExpression ParseNVReference(); expr = new NVBoolExpression(false); expr.Position = new Position(GetCurrentTokenPosition()); } else if (CurrentTokenType == TokenType.NVLParen) { _scanner.GetToken(); expr = ParseNVExpression(); MatchToken(TokenType.NVRParen); } else if (CurrentTokenType == TokenType.NVTrue) { expr = new NVBoolExpression(true); expr.Position = new Position(GetCurrentTokenPosition()); _scanner.GetToken(); } else if (CurrentTokenType == TokenType.NVFalse) { expr = new NVBoolExpression(false); expr.Position = new Position(GetCurrentTokenPosition()); _scanner.GetToken(); } else if (CurrentTokenType == TokenType.NVIntegerLiteral) { expr = new NVNumExpression(int.Parse(_scanner.CurrentToken.Image)); expr.Position = new Position(GetCurrentTokenPosition()); _scanner.GetToken(); } else if (CurrentTokenType == TokenType.NVSingleQuote) { _scanner.GetToken(); if (CurrentTokenType == TokenType.NVStringLiteral) { expr = new NVStringExpression(_scanner.CurrentToken.Image); expr.Position = new Position(GetCurrentTokenPosition()); _scanner.GetToken(); } if (CurrentTokenType == TokenType.NVSingleQuote) { _scanner.GetToken(); } else { AddError("Expected single quote for closing string literal"); } } else if (CurrentTokenType == TokenType.NVDoubleQuote) { _scanner.GetToken(); expr = ParseNVStringLiteralOrDictionary(); MatchToken(TokenType.NVDoubleQuote); } else if (CurrentTokenType == TokenType.NVLBrack) { _scanner.GetToken(); if (CurrentTokenType != TokenType.NVRBrack) { ParseNVExpression(); expr = ParseNVRangeOrArray(); } else { //TODO: replace with an empty NVArrayExpression expr = new NVBoolExpression(false); expr.Position = new Position(GetCurrentTokenPosition()); } MatchToken(TokenType.NVRBrack); } else { AddError(string.Format("Expected expression, was '{0}'", CurrentTokenType)); } return(expr); }