public SpanConstructor Accepts(AcceptedCharacters accepted) { return With(eh => eh.AcceptedCharacters = accepted); }
protected override void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { SingleSpanBlockTest(document, blockType, spanType, acceptedCharacters, expectedError: null); }
public Block EscapedMarkupTagBlock(string prefix, string suffix, AcceptedCharacters acceptedCharacters) { return new MarkupTagBlock( _factory.Markup(prefix), _factory.BangEscape(), _factory.Markup(suffix).Accepts(acceptedCharacters)); }
protected void ImplicitExpressionTest(string input, string expected, AcceptedCharacters acceptedCharacters, params RazorError[] errors) { ParseBlockTest(input, new ExpressionBlock( new ImplicitExpressionSpan(expected, CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: acceptedCharacters)), errors); }
public static void RunSingleAtEscapeTest(Action<string, Block> testMethod, AcceptedCharacters lastSpanAcceptedCharacters = AcceptedCharacters.None) { var factory = SpanFactory.CreateCsHtml(); testMethod("<foo>@@bar</foo>", new MarkupBlock( factory.Markup("<foo>"), factory.Markup("@").Hidden(), factory.Markup("@bar</foo>").Accepts(lastSpanAcceptedCharacters))); }
public static void RunSingleAtEscapeTest(Action<string, Block> testMethod, AcceptedCharacters lastSpanAcceptedCharacters = AcceptedCharacters.None) { testMethod("<foo>@@bar</foo>", new MarkupBlock( new MarkupSpan("<foo>"), new MarkupSpan("@", hidden: true), new MarkupSpan("@bar</foo>", hidden: false, acceptedCharacters: lastSpanAcceptedCharacters) ) ); }
protected void ImplicitExpressionTest(string input, string expected, AcceptedCharacters acceptedCharacters, params RazorError[] errors) { var factory = CreateSpanFactory(); ParseBlockTest(SyntaxConstants.TransitionString + input, new ExpressionBlock( factory.CodeTransition(), factory.Code(expected) .AsImplicitExpression(KeywordSet) .Accepts(acceptedCharacters)), errors); }
public void ParseBlockMethodParsesNullConditionalOperatorImplicitExpression_Bracket( string implicitExpresison, string expectedImplicitExpression, AcceptedCharacters acceptedCharacters, RazorError[] expectedErrors) { // Act & Assert ImplicitExpressionTest( implicitExpresison, expectedImplicitExpression, acceptedCharacters, expectedErrors); }
public static void RunMultiAtEscapeTest(Action<string, Block> testMethod, AcceptedCharacters lastSpanAcceptedCharacters = AcceptedCharacters.None) { testMethod("<foo>@@@@@bar</foo>", new MarkupBlock( new MarkupSpan("<foo>"), new MarkupSpan("@", hidden: true), new MarkupSpan("@"), new MarkupSpan("@", hidden: true), new MarkupSpan("@"), new ExpressionBlock( new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None), new ImplicitExpressionSpan("bar", CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false, acceptedCharacters: AcceptedCharacters.NonWhiteSpace) ), new MarkupSpan("</foo>", hidden: false, acceptedCharacters: lastSpanAcceptedCharacters) )); }
public void SimpleMarkupSwitch(string keyword, string endSequence, AcceptedCharacters acceptedCharacters) { ParseBlockTest(keyword + Environment.NewLine + " If True Then" + Environment.NewLine + " @<p>It's True!</p>" + Environment.NewLine + " End If" + Environment.NewLine + endSequence, new StatementBlock( Factory.Code(keyword + "\r\n If True Then\r\n").AsStatement(), new MarkupBlock( Factory.Markup(" "), Factory.MarkupTransition(), Factory.Markup("<p>It's True!</p>\r\n").Accepts(AcceptedCharacters.None)), Factory.Code(" End If\r\n" + endSequence).AsStatement().Accepts(acceptedCharacters))); }
public static void RunMultiAtEscapeTest(Action<string, Block> testMethod, AcceptedCharacters lastSpanAcceptedCharacters = AcceptedCharacters.None) { var factory = SpanFactory.CreateCsHtml(); testMethod("<foo>@@@@@bar</foo>", new MarkupBlock( factory.Markup("<foo>"), factory.Markup("@").Hidden(), factory.Markup("@"), factory.Markup("@").Hidden(), factory.Markup("@"), new ExpressionBlock( factory.CodeTransition(), factory.Code("bar") .AsImplicitExpression(CSharpCodeParser.DefaultKeywords) .Accepts(AcceptedCharacters.NonWhiteSpace)), factory.Markup("</foo>").Accepts(lastSpanAcceptedCharacters))); }
public Block EscapedMarkupTagBlock( string prefix, string suffix, AcceptedCharacters acceptedCharacters, params SyntaxTreeNode[] children) { var newChildren = new List<SyntaxTreeNode>( new SyntaxTreeNode[] { _factory.Markup(prefix), _factory.BangEscape(), _factory.Markup(suffix).Accepts(acceptedCharacters) }); newChildren.AddRange(children); return new MarkupTagBlock(newChildren.ToArray()); }
public void SingleLineMarkupSwitch(string keyword, string endSequence, AcceptedCharacters acceptedCharacters) { ParseBlockTest(keyword + Environment.NewLine + " If True Then" + Environment.NewLine + " @:<p>It's True!</p>" + Environment.NewLine + " This is code!" + Environment.NewLine + " End If" + Environment.NewLine + endSequence, new StatementBlock( Factory.Code(keyword + "\r\n If True Then\r\n").AsStatement(), new MarkupBlock( Factory.Markup(" "), Factory.MarkupTransition(), Factory.MetaMarkup(":", HtmlSymbolType.Colon), Factory.Markup("<p>It's True!</p>\r\n") .With(new SingleLineMarkupEditHandler(CSharpLanguageCharacteristics.Instance.TokenizeString)) .Accepts(AcceptedCharacters.None)), Factory.Code(" This is code!\r\n End If\r\n" + endSequence) .AsStatement() .Accepts(acceptedCharacters))); }
public ImplicitExpressionSpan(SourceLocation start, string content, ISet<string> keywords, bool acceptTrailingDot, AcceptedCharacters acceptedCharacters) : base(start, content) { Keywords = keywords ?? new HashSet<string>(); AcceptTrailingDot = acceptTrailingDot; AcceptedCharacters = acceptedCharacters; }
public TestSimpleSpan(SpanKind kind, string content, AcceptedCharacters acceptedCharacters) : base(kind, content, hidden: false, acceptedCharacters: acceptedCharacters) { }
public SingleLineMarkupEditHandler(Func<string, IEnumerable<ISymbol>> tokenizer, AcceptedCharacters accepted) : base(tokenizer, accepted) { }
private void RunRazorCommentBetweenClausesTest(string preComment, string postComment, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { ParseBlockTest(preComment + "@* Foo *@ @* Bar *@" + postComment, new StatementBlock( new CodeSpan(preComment), new CommentBlock( new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None), new MetaCodeSpan("*", hidden: false, acceptedCharacters: AcceptedCharacters.None), new CommentSpan(" Foo "), new MetaCodeSpan("*", hidden: false, acceptedCharacters: AcceptedCharacters.None), new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None) ), new CodeSpan(" "), new CommentBlock( new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None), new MetaCodeSpan("*", hidden: false, acceptedCharacters: AcceptedCharacters.None), new CommentSpan(" Bar "), new MetaCodeSpan("*", hidden: false, acceptedCharacters: AcceptedCharacters.None), new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None) ), new CodeSpan(postComment, hidden: false, acceptedCharacters: acceptedCharacters))); }
private void RunSingleLineMarkupSwitchTest(string keyword, string endSequence, AcceptedCharacters acceptedCharacters = AcceptedCharacters.None) { ParseBlockTest(keyword + @" If True Then @:<p>It's True!</p> This is code! End If " + endSequence, new StatementBlock( new CodeSpan(keyword + @" If True Then "), new MarkupBlock( new MarkupSpan(" "), new TransitionSpan(RazorParser.TransitionString, hidden: false, acceptedCharacters: AcceptedCharacters.None), new MetaCodeSpan(":"), new SingleLineMarkupSpan(@"<p>It's True!</p> ", hidden: false, acceptedCharacters: AcceptedCharacters.None) ), new CodeSpan(@" This is code! End If " + endSequence, hidden: false, acceptedCharacters: acceptedCharacters) )); }
protected override void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { SingleSpanBlockTest(document, spanContent, blockType, spanType, acceptedCharacters, expectedErrors: null); }
public AutoCompleteEditHandler(Func <string, IEnumerable <ISymbol> > tokenizer, AcceptedCharacters accepted) : base(tokenizer, accepted) { }
public Block MarkupTagBlock(string content, AcceptedCharacters acceptedCharacters) { return(new MarkupTagBlock( _factory.Markup(content).Accepts(acceptedCharacters) )); }
private bool MethodCallOrArrayIndex(AcceptedCharacters acceptedCharacters) { if (!EndOfFile) { if (CurrentSymbol.Type == CSharpSymbolType.LeftParenthesis || CurrentSymbol.Type == CSharpSymbolType.LeftBracket) { // If we end within "(", whitespace is fine Span.EditHandler.AcceptedCharacters = AcceptedCharacters.Any; CSharpSymbolType right; bool success; using (PushSpanConfig((span, prev) => { prev(span); span.EditHandler.AcceptedCharacters = AcceptedCharacters.Any; })) { right = Language.FlipBracket(CurrentSymbol.Type); success = Balance(BalancingModes.BacktrackOnFailure | BalancingModes.AllowCommentsAndTemplates); } if (!success) { AcceptUntil(CSharpSymbolType.LessThan); } if (At(right)) { AcceptAndMoveNext(); // At the ending brace, restore the initial accepted characters. Span.EditHandler.AcceptedCharacters = acceptedCharacters; } return(MethodCallOrArrayIndex(acceptedCharacters)); } if (CurrentSymbol.Type == CSharpSymbolType.Dot) { var dot = CurrentSymbol; if (NextToken()) { if (At(CSharpSymbolType.Identifier) || At(CSharpSymbolType.Keyword)) { // Accept the dot and return to the start Accept(dot); return(true); // continue } else { // Put the symbol back PutCurrentBack(); } } if (!IsNested) { // Put the "." back PutBack(dot); } else { Accept(dot); } } else if (!At(CSharpSymbolType.WhiteSpace) && !At(CSharpSymbolType.NewLine)) { PutCurrentBack(); } } // Implicit Expression is complete return(false); }
public SpanEditHandler(Func <string, IEnumerable <ISymbol> > tokenizer, AcceptedCharacters accepted) { AcceptedCharacters = accepted; Tokenizer = tokenizer; }
protected virtual void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { SingleSpanBlockTest(document, blockType, spanType, acceptedCharacters, expectedError: null); }
protected virtual Block CreateSimpleBlockAndSpan(string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { var span = Factory.Span(spanType, spanContent, spanType == SpanKind.Markup).Accepts(acceptedCharacters); var b = new BlockBuilder() { Type = blockType }; return(ConfigureAndAddSpanToBlock(b, span)); }
protected virtual void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedErrors) { var builder = new BlockBuilder(); builder.Type = blockType; ParseBlockTest( document, ConfigureAndAddSpanToBlock( builder, Factory.Span(spanType, spanContent, spanType == SpanKind.Markup) .Accepts(acceptedCharacters)), expectedErrors ?? new RazorError[0]); }
public AutoCompleteEditHandler(Func<string, IEnumerable<ISymbol>> tokenizer, AcceptedCharacters accepted) : base(tokenizer, accepted) { }
public static SpanConstructor Accepts(this SpanConstructor self, AcceptedCharacters accepted) { return(self.With(eh => eh.AcceptedCharacters = accepted)); }
private void RunRazorCommentBetweenClausesTest(string preComment, string postComment, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { ParseBlockTest(preComment + "@* Foo *@ @* Bar *@" + postComment, new StatementBlock( Factory.Code(preComment).AsStatement(), new CommentBlock( Factory.CodeTransition(CSharpSymbolType.RazorCommentTransition), Factory.MetaCode("*", CSharpSymbolType.RazorCommentStar).Accepts(AcceptedCharacters.None), Factory.Comment(" Foo ", CSharpSymbolType.RazorComment), Factory.MetaCode("*", CSharpSymbolType.RazorCommentStar).Accepts(AcceptedCharacters.None), Factory.CodeTransition(CSharpSymbolType.RazorCommentTransition) ), Factory.Code(" ").AsStatement(), new CommentBlock( Factory.CodeTransition(CSharpSymbolType.RazorCommentTransition), Factory.MetaCode("*", CSharpSymbolType.RazorCommentStar).Accepts(AcceptedCharacters.None), Factory.Comment(" Bar ", CSharpSymbolType.RazorComment), Factory.MetaCode("*", CSharpSymbolType.RazorCommentStar).Accepts(AcceptedCharacters.None), Factory.CodeTransition(CSharpSymbolType.RazorCommentTransition) ), Factory.Code(postComment).AsStatement().Accepts(acceptedCharacters))); }
public static new HelperHeaderSpan Create(ParserContext context, bool complete, AcceptedCharacters acceptedCharacters) { return(new HelperHeaderSpan(context.CurrentSpanStart, context.ContentBuffer.ToString(), complete) { AcceptedCharacters = acceptedCharacters }); }
protected void ImplicitExpressionTest(string input, AcceptedCharacters acceptedCharacters, params RazorError[] errors) { ImplicitExpressionTest(input, input, acceptedCharacters, errors); }
public SingleLineMarkupEditHandler(Func <string, IEnumerable <ISymbol> > tokenizer, AcceptedCharacters accepted) : base(tokenizer, accepted) { }
private void RunSimpleWrappedMarkupTest(string prefix, string markup, string suffix, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { ParseBlockTest(prefix + markup + suffix, new StatementBlock( new CodeSpan(prefix), new MarkupBlock( new MarkupSpan(markup, hidden: false, acceptedCharacters: AcceptedCharacters.None) ), new CodeSpan(suffix, hidden: false, acceptedCharacters: acceptedCharacters) )); }
protected Span(ParserContext context, SpanKind kind, bool hidden, AcceptedCharacters acceptedCharacters) : this(kind, context.CurrentSpanStart, context.ContentBuffer.ToString(), hidden, acceptedCharacters) { }
protected virtual void SingleSpanBlockTest(string document, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedError) { SingleSpanBlockTest(document, document, blockType, spanType, acceptedCharacters, expectedError); }
protected Span(SpanKind kind, SourceLocation start, string content, bool hidden, AcceptedCharacters acceptedCharacters) : this(kind, content, hidden, acceptedCharacters) { _start = start; }
protected internal void Output(AcceptedCharacters accepts) { Configure(null, accepts); Output(); }
internal MetaCodeSpan(string content, bool hidden, AcceptedCharacters acceptedCharacters) : base(SpanKind.MetaCode, content, hidden, acceptedCharacters) { }
protected internal void Output(SpanKind kind, AcceptedCharacters accepts) { Configure(kind, accepts); Output(); }
public MetaCodeSpan(SourceLocation start, string content, bool hidden, AcceptedCharacters acceptedCharacters) : base(SpanKind.MetaCode, start, content, hidden, acceptedCharacters) { }
internal ImplicitExpressionSpan(string content, ISet<string> keywords, bool acceptTrailingDot, AcceptedCharacters acceptedCharacters) : base(content) { Keywords = keywords ?? new HashSet<string>(); AcceptTrailingDot = acceptTrailingDot; AcceptedCharacters = acceptedCharacters; }
public static MetaCodeSpan Create(ParserContext context, bool hidden, AcceptedCharacters acceptedCharacters) { return(new MetaCodeSpan(context.CurrentSpanStart, context.ContentBuffer.ToString(), hidden, acceptedCharacters)); }
public static ImplicitExpressionSpan Create(ParserContext context, ISet<string> keywords, bool acceptTrailingDot, AcceptedCharacters acceptedCharacters) { return new ImplicitExpressionSpan(context.CurrentSpanStart, context.ContentBuffer.ToString(), keywords, acceptTrailingDot, acceptedCharacters); }
public static SpanConstructor Accepts(this SpanConstructor self, AcceptedCharacters accepted) { return self.With(eh => eh.AcceptedCharacters = accepted); }
public static ImplicitExpressionSpan Create(ParserContext context, ISet <string> keywords, bool acceptTrailingDot, AcceptedCharacters acceptedCharacters) { return(new ImplicitExpressionSpan(context.CurrentSpanStart, context.ContentBuffer.ToString(), keywords, acceptTrailingDot, acceptedCharacters)); }
protected override void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedErrors) { Block b = CreateSimpleBlockAndSpan(spanContent, blockType, spanType, acceptedCharacters); ParseBlockTest(document, b, expectedErrors ?? new RazorError[0]); }
protected virtual void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { SingleSpanBlockTest(document, spanContent, blockType, spanType, acceptedCharacters, expectedErrors: null); }
private void RunSimpleWrappedMarkupTest(string prefix, string markup, string suffix, MarkupBlock expectedMarkup, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { ParseBlockTest(prefix + markup + suffix, new StatementBlock( Factory.Code(prefix).AsStatement(), expectedMarkup, Factory.Code(suffix).AsStatement().Accepts(acceptedCharacters) )); }
protected virtual Block CreateSimpleBlockAndSpan(string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters = AcceptedCharacters.Any) { var span = Factory.Span(spanType, spanContent, spanType == SpanKind.Markup).Accepts(acceptedCharacters); var b = new BlockBuilder() { Type = blockType }; return ConfigureAndAddSpanToBlock(b, span); }
internal CommentSpan(string content, bool hidden, AcceptedCharacters acceptedCharacters) : base(SpanKind.Comment, content, hidden, acceptedCharacters) { }
public CommentSpan(SourceLocation start, string content, bool hidden, AcceptedCharacters acceptedCharacters) : base(SpanKind.Comment, start, content, hidden, acceptedCharacters) { }
public static CommentSpan Create(ParserContext context, bool hidden, AcceptedCharacters acceptedCharacters) { return new CommentSpan(context.CurrentSpanStart, context.ContentBuffer.ToString(), hidden, acceptedCharacters); }
public SpanEditHandler(Func<string, IEnumerable<ISymbol>> tokenizer, AcceptedCharacters accepted) { AcceptedCharacters = accepted; Tokenizer = tokenizer; }
public SpanConstructor Accepts(AcceptedCharacters accepted) { return(With(eh => eh.AcceptedCharacters = accepted)); }
protected override void SingleSpanBlockTest(string document, string spanContent, BlockType blockType, SpanKind spanType, AcceptedCharacters acceptedCharacters, params RazorError[] expectedErrors) { var b = CreateSimpleBlockAndSpan(spanContent, blockType, spanType, acceptedCharacters); ParseBlockTest(document, b, expectedErrors ?? new RazorError[0]); }
private bool MethodCallOrArrayIndex(AcceptedCharacters acceptedCharacters) { if (!EndOfFile) { if (CurrentSymbol.Type == CSharpSymbolType.LeftParenthesis || CurrentSymbol.Type == CSharpSymbolType.LeftBracket) { // If we end within "(", whitespace is fine Span.EditHandler.AcceptedCharacters = AcceptedCharacters.Any; CSharpSymbolType right; bool success; using (PushSpanConfig((span, prev) => { prev(span); span.EditHandler.AcceptedCharacters = AcceptedCharacters.Any; })) { right = Language.FlipBracket(CurrentSymbol.Type); success = Balance(BalancingModes.BacktrackOnFailure | BalancingModes.AllowCommentsAndTemplates); } if (!success) { AcceptUntil(CSharpSymbolType.LessThan); } if (At(right)) { AcceptAndMoveNext(); // At the ending brace, restore the initial accepted characters. Span.EditHandler.AcceptedCharacters = acceptedCharacters; } return(MethodCallOrArrayIndex(acceptedCharacters)); } if (At(CSharpSymbolType.QuestionMark)) { var next = Lookahead(count: 1); if (next != null) { if (next.Type == CSharpSymbolType.Dot) { // Accept null conditional dot operator (?.). AcceptAndMoveNext(); AcceptAndMoveNext(); // If the next piece after the ?. is a keyword or identifier then we want to continue. return(At(CSharpSymbolType.Identifier) || At(CSharpSymbolType.Keyword)); } else if (next.Type == CSharpSymbolType.LeftBracket) { // We're at the ? for a null conditional bracket operator (?[). AcceptAndMoveNext(); // Accept the [ and any content inside (it will attempt to balance). return(MethodCallOrArrayIndex(acceptedCharacters)); } } } else if (At(CSharpSymbolType.Dot)) { var dot = CurrentSymbol; if (NextToken()) { if (At(CSharpSymbolType.Identifier) || At(CSharpSymbolType.Keyword)) { // Accept the dot and return to the start Accept(dot); return(true); // continue } else { // Put the symbol back PutCurrentBack(); } } if (!IsNested) { // Put the "." back PutBack(dot); } else { Accept(dot); } } else if (!At(CSharpSymbolType.WhiteSpace) && !At(CSharpSymbolType.NewLine)) { PutCurrentBack(); } } // Implicit Expression is complete return(false); }