public void MultiLineString() { string str = @"hover = await Styled.Css($@"" padding: 32px; background-color: hotpink;"""; List <Line> lines = Tokenizer.Parse(str); Assert.AreEqual(3, lines.Count); Assert.AreEqual(TokenType.Text, lines[0].Tokens[0].TokenType); Assert.AreEqual(TokenType.QuotedString, lines[0].Tokens[1].TokenType); QuotedString quotedString = (QuotedString)lines[0].Tokens[1]; Assert.AreEqual(LineType.MultiLineStart, quotedString.LineType); Assert.AreEqual(QuoteMarkType.DoubleQuote, quotedString.QuoteMark); Assert.AreEqual(true, quotedString.IsMultiLineStatement); Assert.AreEqual(TokenType.QuotedString, lines[1].Tokens[0].TokenType); quotedString = (QuotedString)lines[1].Tokens[0]; Assert.AreEqual(LineType.MultiLine, quotedString.LineType); Assert.AreEqual(QuoteMarkType.DoubleQuote, quotedString.QuoteMark); Assert.AreEqual(TokenType.QuotedString, lines[2].Tokens[0].TokenType); quotedString = (QuotedString)lines[2].Tokens[0]; Assert.AreEqual(LineType.MultiLineEnd, quotedString.LineType); Assert.AreEqual(QuoteMarkType.DoubleQuote, quotedString.QuoteMark); }
public void Parse_Binary_Comparison_QuotedString_Success(string input, LogicalOperatorKind expectedLogicalOperatorKind, ComparisonKind expectedLeftComparisonKind, ComparisonKind expectedRightComparisonKind, string expectedLeftLeftString, string expectedLeftRightString, string expectedRightLeftString, string expectedRightRightString) { AssertParser.SucceedsWith(Parsers.Logical, input, actualLogical => { Assert.Equal(expectedLogicalOperatorKind, actualLogical.OperatorKind); // Left-hand comparison. Compare leftComparison = Assert.IsType <Compare>(actualLogical.Left); Assert.Equal(expectedLeftComparisonKind, leftComparison.ComparisonKind); QuotedString leftLeftString = Assert.IsType <QuotedString>(leftComparison.Left); Assert.Equal(expectedLeftLeftString, leftLeftString.StringContent); QuotedString leftRightString = Assert.IsType <QuotedString>(leftComparison.Right); Assert.Equal(expectedLeftRightString, leftRightString.StringContent); // Right-hand comparison. Compare rightComparison = Assert.IsType <Compare>(actualLogical.Right); Assert.Equal(expectedRightComparisonKind, rightComparison.ComparisonKind); QuotedString rightLeftString = Assert.IsType <QuotedString>(rightComparison.Left); Assert.Equal(expectedRightLeftString, rightLeftString.StringContent); QuotedString rightRightString = Assert.IsType <QuotedString>(rightComparison.Right); Assert.Equal(expectedRightRightString, rightRightString.StringContent); }); }
public override ILexer <ChunkExtensionValue> Create() { var innerLexer = Alternation.Create( Token.Create(), QuotedString.Create()); return(new ChunkExtensionValueLexer(innerLexer)); }
private void BuildRendeQuotedTag(RenderTreeBuilder builder, QuotedString quotedTag) { string quote = GetQuoteChar(quotedTag.QuoteMark); if (quotedTag.LineType == LineType.SingleLine || quotedTag.LineType == LineType.MultiLineStart) { if (quotedTag.IsMultiLineStatement) { builder.OpenElement(Next(), "span"); builder.AddAttribute(Next(), "class", _themeQuotedStringClass); builder.AddContent(Next(), '@'); builder.CloseElement(); } builder.OpenElement(Next(), "span"); builder.AddAttribute(Next(), "class", _themeQuotedStringClass); builder.AddContent(Next(), quote); builder.CloseElement(); if (quotedTag.IsCSStatement) { builder.OpenElement(Next(), "span"); builder.AddAttribute(Next(), "class", _themeRazorKeywordClass); builder.AddContent(Next(), '@'); if (quotedTag.HasParentheses) { builder.AddContent(Next(), "("); } builder.CloseElement(); } } builder.OpenElement(Next(), "span"); builder.AddAttribute(Next(), "class", _themeQuotedStringClass); builder.AddContent(Next(), quotedTag.Content); builder.CloseElement(); if (quotedTag.LineType == LineType.SingleLine || quotedTag.LineType == LineType.MultiLineEnd) { if (quotedTag.HasParentheses) { builder.OpenElement(Next(), "span"); builder.AddAttribute(Next(), "class", _themeRazorKeywordClass); builder.AddContent(Next(), ')'); builder.CloseElement(); } builder.OpenElement(Next(), "span"); builder.AddAttribute(Next(), "class", _themeQuotedStringClass); builder.AddContent(Next(), quote); builder.CloseElement(); } }
public void ParseCompare_QuotedStrings_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftContent, string expectedRightContent) { AssertParser.SucceedsWith(Parsers.Comparison, input, actualComparison => { Assert.Equal(expectedComparisonKind, actualComparison.ComparisonKind); Assert.NotNull(actualComparison.Left); QuotedString left = Assert.IsType <QuotedString>(actualComparison.Left); Assert.Equal(expectedLeftContent, left.StringContent); Assert.NotNull(actualComparison.Right); QuotedString right = Assert.IsType <QuotedString>(actualComparison.Right); Assert.Equal(expectedRightContent, right.StringContent); }); }
public void Parse_Unary_Not_Comparison_QuotedString_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftString, string expectedRightString) { AssertParser.SucceedsWith(Parsers.Logical, input, actualLogical => { Assert.Equal(LogicalOperatorKind.Not, actualLogical.OperatorKind); Compare comparison = Assert.IsType <Compare>(actualLogical.Right); Assert.Equal(expectedComparisonKind, comparison.ComparisonKind); QuotedString leftString = Assert.IsType <QuotedString>(comparison.Left); Assert.Equal(expectedLeftString, leftString.StringContent); QuotedString rightString = Assert.IsType <QuotedString>(comparison.Right); Assert.Equal(expectedRightString, rightString.StringContent); }); }
/// <summary> /// The execute. /// </summary> /// <param name="context"> /// The context. /// </param> /// <returns> /// The HTTP Response message /// </returns> protected override object Execute(CodeActivityContext context) { if (this.Content.Expression == null) { return(new HttpResponseMessage <T>(this.StatusCode)); } else { var response = new HttpResponseMessage <T>(this.Content.Get(context), this.StatusCode); if (!(this.ETag == null || this.ETag.Get(context) == null)) { response.Headers.ETag = new EntityTagHeaderValue(QuotedString.Get(this.ETag.Get(context))); } return(response); } }
private string InsertQuotedStrings(string strC, List <string> h) { StringBuilder sb = new StringBuilder(); StringBuilder QuotedString = null; for (int intI = 0; intI < strC.Length; intI++) { char chrC = strC[intI]; if (chrC == '"') { if (QuotedString == null) { QuotedString = new StringBuilder(); } else { sb.Append('"'); int intNumber; // State("default") is not a number, result of 'CorrectStates' if (int.TryParse(QuotedString.ToString(), out intNumber)) { sb.Append(h[intNumber]); } else { sb.Append(QuotedString.ToString()); } sb.Append('"'); QuotedString = null; } continue; } if (QuotedString == null) { sb.Append(chrC); } else { QuotedString.Append(chrC); } } return(sb.ToString()); }
public void Parse_QuotedStrings_Success(string input, ComparisonKind expectedComparisonKind, string expectedLeftContent, string expectedRightContent) { AssertParser.SucceedsWith(Parsers.Root, input, actualRoot => { Assert.Equal(1, actualRoot.Children.Count); ExpressionNode actualExpression = actualRoot.Children[0]; Compare actualComparison = Assert.IsType <Compare>(actualExpression); Assert.Equal(expectedComparisonKind, actualComparison.ComparisonKind); Assert.NotNull(actualComparison.Left); QuotedString left = Assert.IsType <QuotedString>(actualComparison.Left); Assert.Equal(expectedLeftContent, left.StringContent); Assert.NotNull(actualComparison.Right); QuotedString right = Assert.IsType <QuotedString>(actualComparison.Right); Assert.Equal(expectedRightContent, right.StringContent); }); }
protected override IEnumerable <Result <RdmToken> > Tokenize(TextSpan input) { var next = SkipWhiteSpace(input); if (!next.HasValue) { yield break; } do { if (next.Value == '#') { var comment = Comment.ShellStyle(next.Location); next = comment.Remainder.ConsumeChar(); } else if (next.Value == '\"') { var str = QuotedString.CStyle(next.Location); if (!str.HasValue) { yield return(Result.CastEmpty <string, RdmToken>(str)); } next = str.Remainder.ConsumeChar(); yield return(Result.Value(RdmToken.QuotedString, str.Location, str.Remainder)); } else if (char.IsLetter(next.Value)) { var keywordStart = next.Location; do { next = next.Remainder.ConsumeChar(); } while (next.HasValue && char.IsLetterOrDigit(next.Value)); yield return(Result.Value(RdmToken.Identifier, keywordStart, next.Location)); } else if (char.IsDigit(next.Value)) { var integer = Numerics.Integer(next.Location); yield return(Result.Value(RdmToken.Number, next.Location, integer.Remainder)); next = integer.Remainder.ConsumeChar(); } else if (_operators.TryGetValue(next.Value, out var @operator)) { yield return(Result.Value(@operator, next.Location, next.Remainder)); next = next.Remainder.ConsumeChar(); } else { yield return(Result.Empty <RdmToken>(next.Location, $"unrecognized `{next.Value}`")); next = next.Remainder.ConsumeChar(); // Skip the character anyway } next = SkipWhiteSpace(next.Location); } while (next.HasValue); }
public void DoubleQuotedStringExceptionTest( ) { const string doubleQuotedString = "\"asdf ghijk \u0394"; Assert.AreEqual(doubleQuotedString, QuotedString.Parse(doubleQuotedString)); }
public void DoubleQuotedStringTest( ) { const string doubleQuotedString = "\"asdf ghijk \u0394\""; Assert.AreEqual(doubleQuotedString.Trim( ).Trim('"'), QuotedString.Text( ).Parse(doubleQuotedString)); }
private string RemoveQuotedStrings(string strC, out List <string> h) { h = new List <string>(); StringBuilder sb = new StringBuilder(); StringBuilder QuotedString = null; for (int intI = 0; intI < strC.Length; intI++) { char chrC = strC[intI]; if (chrC == '"') { if (QuotedString != null) { // end of a quoted string sb.Append('"'); sb.Append(h.Count.ToString()); sb.Append('"'); h.Add(QuotedString.ToString()); QuotedString = null; continue; } else { if (chrC == '"') { // start of a new quoted string QuotedString = new StringBuilder(); continue; } // it was just a newline char, and not in a string } } if (QuotedString == null) { sb.Append(chrC); } else { if (chrC == '\n') { QuotedString.Append('\\'); chrC = 'n'; } if (chrC != '\\') { QuotedString.Append(chrC); } else // it is a backslash { intI++; chrC = strC[intI]; if (chrC == 't') // tabs are 4 spaces in SL world!! { QuotedString.Append(" "); } else // nope, it is no tab, just output it all { QuotedString.Append('\\'); QuotedString.Append(chrC); } } } } return(sb.ToString()); }
protected RuleParser() { Whitespace = Rep(Char(' ').Or(Char('\t').Or(Char('\n')).Or(Char('\r')))); NewLine = Rep(Char('\r').And(Char('\n')).Or(Char('\n'))); Printable = Rep(Char(char.IsLetterOrDigit).Or(Char(char.IsWhiteSpace)).Or(Char('.')).Or(Char(','))); Id = from w in Whitespace from c in Char(char.IsLetter) from cs in Rep(Char(char.IsLetterOrDigit)) select new string(new[] { c }.Concat(cs).ToArray()); QuotedString = from w in Whitespace from enq in Char('"').Or(Char('\'')) from text in Printable from deq in Char(enq) select new string(text); ListSeparator = from w in Whitespace from ch in Char(',') select new ListSeparator(); Minus = from w in Whitespace from op in Char('-') select(Operator) new MinusOperator(); Plus = from w in Whitespace from op in Char('+') select(Operator) new PlusOperator(); Multiply = from w in Whitespace from op in Char('*') select(Operator) new MultiplyOperator(); Divide = from w in Whitespace from op in Char('/') select(Operator) new DivideOperator(); Equal = from w in Whitespace from op in Char('=').And(Char('=')) select(Comparator) new EqualComparator(); NotEqual = from w in Whitespace from op in Char('!').And(Char('=')) select(Comparator) new NotEqualComparator(); GreaterThanOrEqual = from w in Whitespace from op in Char('>').And(Char('=')) select(Comparator) new GreaterThanOrEqualComparator(); LessThanOrEqual = from w in Whitespace from op in Char('<').And(Char('=')) select(Comparator) new LessThanOrEqualComparator(); LessThan = from w in Whitespace from op in Char('<') select(Comparator) new LessThanComparator(); GreaterThan = from w in Whitespace from op in Char('<') select(Comparator) new GreaterThanComparator(); Operators = Multiply.Or(Divide).Or(Plus).Or(Minus); Comparators = NotEqual.Or(GreaterThanOrEqual).Or(LessThanOrEqual).Or(Equal).Or(GreaterThan).Or(LessThan); Condition = from w in Whitespace from id in Id from op in Comparators from value in QuotedString select new RuleConditionImpl(id, op, value); NextCondition = from sep in ListSeparator from cond in Condition select cond; MatchConditions = from first in Condition from rest in Rep(NextCondition) select new[] { first }.Concat(rest).ToArray(); TypeMatch = from w in Whitespace from className in Id from open in Char('(') from conditions in MatchConditions from close in Char(')') select(RuleConditionImpl) new ClassRuleCondition(className, conditions); Variable = from w in Whitespace from flag in Char('$') from id in Id select new Variable(id); AssignedMatch = from v in Variable from w in Whitespace from c in Char(':') from t in TypeMatch select(RuleConditionImpl) new AssignedRuleCondition(v, t); Rule = from open in Id where open == "rule" from name in QuotedString.Or(Id) from when in Id where when == "when" from conditions in Rep(AssignedMatch.Or(TypeMatch.Or(Condition))) from then in Id where then == "then" from theEnd in Id where theEnd == "end" select new RuleDefinition(name, conditions); }