public CSharpCodeParser() { _implicitExpressionParser = WrapSimpleBlockParser(BlockType.Expression, ParseImplicitExpression); _identifierHandlers = new Dictionary<string, BlockParser>() { { "if", WrapSimpleBlockParser(BlockType.Statement, ParseIfStatement) }, { "do", WrapSimpleBlockParser(BlockType.Statement, ParseDoStatement) }, { "try", WrapSimpleBlockParser(BlockType.Statement, ParseTryStatement) }, { "for", WrapSimpleBlockParser(BlockType.Statement, ParseConditionalBlockStatement) }, { "foreach", WrapSimpleBlockParser(BlockType.Statement, ParseConditionalBlockStatement) }, { "while", WrapSimpleBlockParser(BlockType.Statement, ParseConditionalBlockStatement) }, { "switch", WrapSimpleBlockParser(BlockType.Statement, ParseConditionalBlockStatement) }, { "lock", WrapSimpleBlockParser(BlockType.Statement, ParseConditionalBlockStatement) }, { "using", ParseUsingStatement }, { "case", WrapSimpleBlockParser(BlockType.Statement, ParseCaseBlock) }, { "default", WrapSimpleBlockParser(BlockType.Statement, ParseCaseBlock) } }; RazorKeywords = new Dictionary<string, BlockParser>() { { "section", WrapSimpleBlockParser(BlockType.Section, ParseSectionBlock) }, { "inherits", WrapSimpleBlockParser(BlockType.Directive, ParseInheritsStatement) }, { "helper", WrapSimpleBlockParser(BlockType.Helper, ParseHelperBlock) }, { "functions", ParseFunctionsBlock }, { "namespace", HandleReservedWord }, { "class", HandleReservedWord }, { "layout", HandleReservedWord } }; }
public VBCodeParser() { KeywordHandlers = new Dictionary<string, BlockParser>(StringComparer.OrdinalIgnoreCase) { { "code", CreateKeywordBlockParser("Code", isSpecialBlock: true, blockType: BlockType.Statement, terminatorTokens: new string[] {"End", "Code"}) }, { "do", CreateKeywordBlockParser("Do", supportsExitAndContinue: true, acceptRestOfLine: true, terminatorTokens: new string[] {"Loop"}) }, { "while", CreateKeywordBlockParser("While", supportsExitAndContinue: true, terminatorTokens: new string[] {"End", "While"}) }, { "if", CreateKeywordBlockParser("If", terminatorTokens: new string[] {"End", "If"}) }, { "select", CreateKeywordBlockParser("Select", blockName: "Select Case", terminatorTokens: new string[] {"End", "Select"}) }, { "for", CreateKeywordBlockParser("For", supportsExitAndContinue: true, acceptRestOfLine: true, terminatorTokens: new string[] {"Next"}) }, { "try", CreateKeywordBlockParser("Try", terminatorTokens: new string[] {"End", "Try"}) }, { "with", CreateKeywordBlockParser("With", terminatorTokens: new string[] {"End", "With"}) }, { "synclock", CreateKeywordBlockParser("SyncLock", terminatorTokens: new string[] {"End", "SyncLock"}) }, { "using", CreateKeywordBlockParser("Using", terminatorTokens: new string[] {"End", "Using"}) }, { "functions", CreateKeywordBlockParser("Functions", isSpecialBlock: true, blockType: BlockType.Functions, terminatorTokens: new string[] {"End", "Functions"}) }, { "section", ParseSectionStatement }, { "imports", ParseImportsStatement }, { "inherits", ParseInheritsStatement }, { "option", ParseOptionStatement }, { "helper", ParseHelperBlock }, { "namespace", HandleReservedWord }, { "class", HandleReservedWord }, { "layout", HandleReservedWord } }; HelperBodyParser = CreateKeywordBlockParser("Helper", isSpecialBlock: true, terminatorTokens: new string[] { "End", "Helper" }); }
/// <summary> /// Creates a <see cref="FlexiCodeBlock"/>. /// </summary> /// <param name="blockName">The <see cref="FlexiCodeBlock"/>'s BEM block name.</param> /// <param name="title">The <see cref="FlexiCodeBlock"/>'s title.</param> /// <param name="copyIcon">The <see cref="FlexiCodeBlock"/>'s copy icon as an HTML fragment.</param> /// <param name="renderHeader">The value specifying whether to render the <see cref="FlexiCodeBlock"/>'s header.</param> /// <param name="language">The programming langauge of the <see cref="FlexiCodeBlock"/>'s code.</param> /// <param name="code">The <see cref="FlexiCodeBlock"/>'s code.</param> /// <param name="codeNumLines">The number of lines the <see cref="FlexiCodeBlock"/>'s code spans.</param> /// <param name="syntaxHighlighter">The syntax highlighter to highlight the <see cref="FlexiCodeBlock"/>'s code with.</param> /// <param name="lineNumbers">The <see cref="NumberedLineRange"/>s specifying line numbers to render.</param> /// <param name="omittedLinesIcon">The <see cref="FlexiCodeBlock"/>'s omitted lines icon as an HTML fragment.</param> /// <param name="highlightedLines">The <see cref="LineRange"/>s specifying lines to highlight.</param> /// <param name="highlightedPhrases">The <see cref="PhraseGroup"/>s specifying phrases to highlight.</param> /// <param name="renderingMode">The <see cref="FlexiCodeBlock"/>'s rendering mode.</param> /// <param name="attributes">The HTML attributes for the <see cref="FlexiCodeBlock"/>'s root element.</param> /// <param name="blockParser">The <see cref="BlockParser"/> parsing the <see cref="FlexiCodeBlock"/>.</param> public FlexiCodeBlock( string blockName, string title, string copyIcon, bool renderHeader, string language, string code, int codeNumLines, SyntaxHighlighter syntaxHighlighter, ReadOnlyCollection <NumberedLineRange> lineNumbers, string omittedLinesIcon, ReadOnlyCollection <LineRange> highlightedLines, ReadOnlyCollection <Phrase> highlightedPhrases, FlexiCodeBlockRenderingMode renderingMode, ReadOnlyDictionary <string, string> attributes, BlockParser blockParser) : base(blockParser) { BlockName = blockName; Title = title; CopyIcon = copyIcon; RenderHeader = renderHeader; Language = language; Code = code; CodeNumLines = codeNumLines; SyntaxHighlighter = syntaxHighlighter; LineNumbers = lineNumbers; OmittedLinesIcon = omittedLinesIcon; HighlightedLines = highlightedLines; HighlightedPhrases = highlightedPhrases; RenderingMode = renderingMode; Attributes = attributes; }
/// <summary> /// Creates a <see cref="FlexiVideoBlock"/>. /// </summary> /// <param name="blockName">The <see cref="FlexiVideoBlock"/>'s BEM block name.</param> /// <param name="src">The <see cref="FlexiVideoBlock"/>'s source URI.</param> /// <param name="type">The <see cref="FlexiVideoBlock"/>'s MIME type.</param> /// <param name="poster">The <see cref="FlexiVideoBlock"/>'s poster URI.</param> /// <param name="width">The <see cref="FlexiVideoBlock"/>'s width.</param> /// <param name="height">The <see cref="FlexiVideoBlock"/>'s height.</param> /// <param name="aspectRatio">The <see cref="FlexiVideoBlock"/>'s aspect ratio.</param> /// <param name="duration">The <see cref="FlexiVideoBlock"/>'s duration.</param> /// <param name="spinner">The <see cref="FlexiVideoBlock"/>'s spinner as an HTML fragment.</param> /// <param name="playIcon">The <see cref="FlexiVideoBlock"/>'s play icon as an HTML fragment.</param> /// <param name="pauseIcon">The <see cref="FlexiVideoBlock"/>'s pause icon as an HTML fragment.</param> /// <param name="fullscreenIcon">The <see cref="FlexiVideoBlock"/>'s fullscreen icon as an HTML fragment.</param> /// <param name="exitFullscreenIcon">The <see cref="FlexiVideoBlock"/>'s exit fullscreen icon as an HTML fragment.</param> /// <param name="errorIcon">The <see cref="FlexiVideoBlock"/>'s error icon as an HTML fragment.</param> /// <param name="attributes">The HTML attributes for the <see cref="FlexiVideoBlock"/>'s root element.</param> /// <param name="blockParser">The <see cref="BlockParser"/> parsing the <see cref="FlexiVideoBlock"/>.</param> public FlexiVideoBlock(string blockName, string src, string type, string poster, double width, double height, double aspectRatio, double duration, string spinner, string playIcon, string pauseIcon, string fullscreenIcon, string exitFullscreenIcon, string errorIcon, ReadOnlyDictionary <string, string> attributes, BlockParser blockParser) : base(blockParser) { BlockName = blockName; Src = src; Type = type; Poster = poster; Width = width; Height = height; AspectRatio = aspectRatio; Duration = duration; Spinner = spinner; PlayIcon = playIcon; PauseIcon = pauseIcon; FullscreenIcon = fullscreenIcon; ExitFullscreenIcon = exitFullscreenIcon; ErrorIcon = errorIcon; Attributes = attributes; }
/// <summary> /// Creates a <see cref="FlexiCardBlock"/>. /// </summary> /// <param name="blockProcessor">The <see cref="BlockProcessor"/> processing the <see cref="FlexiCardBlock"/>.</param> /// <param name="blockParser">The <see cref="BlockParser"/> parsing the <see cref="FlexiCardBlock"/>.</param> /// <exception cref="BlockException">Thrown if <paramref name="blockProcessor"/>'s <see cref="BlockProcessor.CurrentContainer"/> is not /// a <see cref="ProxyFlexiCardsBlock"/>.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="blockProcessor"/> is <c>null</c>.</exception> public override FlexiCardBlock Create(BlockProcessor blockProcessor, BlockParser blockParser) { if (!(blockProcessor.CurrentContainer is ProxyFlexiCardsBlock proxyFlexiCardsBlock)) { throw new BlockException(nameof(FlexiCardBlock), blockProcessor.LineIndex, blockProcessor.Column, string.Format(Strings.BlockException_Shared_BlockCanOnlyExistWithinASpecificTypeOfBlock, nameof(FlexiCardBlock), nameof(FlexiCardsBlock))); } IFlexiCardBlockOptions flexiCardBlockOptions = _flexiCardBlockOptionsFactory. Create(proxyFlexiCardsBlock.FlexiCardsBlockOptions.DefaultCardOptions, blockProcessor); // Create block return(new FlexiCardBlock(flexiCardBlockOptions.Url, flexiCardBlockOptions.BackgroundIcon, flexiCardBlockOptions.Attributes, blockParser) { Column = blockProcessor.Column, Span = new SourceSpan(blockProcessor.Start, 0) // MultipartBlockParser will update end // Line is assigned by BlockProcessor }); }
/// <summary> /// Parse code containing a list of statements. /// </summary> public Block ParseBlock(string code, Block block) { var reader = new BlockParser(code); var analyzer = new BlockAnalyzer(block); foreach (CodeSegment sc in reader) { TokenStream t = TokenReader.Read(sc); LaxExpression s = analyzer.AnalyzeStatement(t); if (s == null) continue; block.Statements.Add(s); } var unitEval = new TypeEvaluator(block); var constEval = new ConstEvaluater(block); foreach (var c in block.Constants.Values) { unitEval.Eval(c.Value); constEval.Eval(c); } foreach (var e in block.Statements) { unitEval.Eval(e); } return block; }
public void SerializePoco() { BlockParser.Serialize(new T1 { Name = "a1" }).Should().Be(@"<T1> <Name>a1</Name> </T1>"); }
private static FlexiQuoteBlock CreateFlexiQuoteBlock(string blockName = default, string icon = default, int citeLink = default, ReadOnlyDictionary <string, string> attributes = default, BlockParser blockParser = default) { return(new FlexiQuoteBlock(blockName, icon, citeLink, attributes, blockParser)); }
/// <summary> /// Creates a <see cref="FlexiCardsBlock"/>. /// </summary> /// <param name="blockName">The <see cref="FlexiCardsBlock"/>'s BEM block name.</param> /// <param name="cardSize">The display size of contained <see cref="FlexiCardBlock"/>s.</param> /// <param name="attributes">HTML attributes for the <see cref="FlexiCardsBlock"/>'s root element.</param> /// <param name="blockParser">The <see cref="BlockParser"/> parsing the <see cref="FlexiCardsBlock"/>.</param> public FlexiCardsBlock(string blockName, FlexiCardBlockSize cardSize, ReadOnlyDictionary <string, string> attributes, BlockParser blockParser) : base(blockParser) { BlockName = blockName; CardSize = cardSize; Attributes = attributes; }
/// <summary> /// Creates a <see cref="FlexiCardBlock"/>. /// </summary> /// <param name="url">The URL the <see cref="FlexiCardBlock"/> points to.</param> /// <param name="backgroundIcon">The <see cref="FlexiCardBlock"/>'s background icon as an HTML fragment.</param> /// <param name="attributes">HTML attributes for the <see cref="FlexiCardBlock"/>'s root element.</param> /// <param name="blockParser">The <see cref="BlockParser"/> parsing the <see cref="FlexiCardBlock"/>.</param> public FlexiCardBlock(string url, string backgroundIcon, ReadOnlyDictionary <string, string> attributes, BlockParser blockParser) : base(blockParser) { Url = url; BackgroundIcon = backgroundIcon; Attributes = attributes; }
private static FlexiFigureBlock CreateFlexiFigureBlock(string blockName = default, string name = default, bool renderName = default, string linkLabelContent = default, string id = default, ReadOnlyDictionary <string, string> attributes = default, BlockParser blockParser = default) { return(new FlexiFigureBlock(blockName, name, renderName, linkLabelContent, id, attributes, blockParser)); }
protected internal BlockParser WrapSimpleBlockParser(BlockType type, BlockParser blockParser) { return (block) => { if (block.IsTopLevel) { StartBlock(type); block.ResumeSpans(Context); } return blockParser(block); }; }
private BlockParser GetBlockParser(CodeBlockInfo block, BlockParser fallbackParser, out bool isStatementBlock) { BlockParser parser = null; isStatementBlock = true; if (block.Name == null || !_identifierHandlers.TryGetValue(block.Name, out parser)) { isStatementBlock = false; if (block.Name == null || !block.IsTopLevel || !RazorKeywords.TryGetValue(block.Name, out parser)) { parser = fallbackParser; } } return parser; }
private BlockParser GetBlockParser(CodeBlockInfo block, BlockParser fallbackParser) { bool _ = false; // Don't care in this case return GetBlockParser(block, fallbackParser, out _); }