protected override void DoExecute(ParseContext context) { context.Input.Read(3); context.UpdateCurrentChar(); OpenScope(new HorizontalRulerScope(), context); CloseCurrentScope(context); }
protected override void DoExecute(ParseContext context) { var depth = 1; while (context.Input.Peek() == '!') { depth++; context.Input.Read(); } context.Input.SeekToNonWhitespace(); //ignore spaces/tabs context.UpdateCurrentChar(); OpenScope(new HeaderScope(depth), context); }
protected override sealed void DoExecute(ParseContext context) { var peek = context.Input.Peek(); var functionNameBuilder = new StringBuilder(); while (peek != ButterflyStringReader.NoValue && peek != '|' && peek != ']') { functionNameBuilder.Append((char)context.Input.Read()); peek = context.Input.Peek(); } var closer = context.Input.Read(); //| or ] var name = functionNameBuilder.ToString(); var data = new Dictionary<string, string>(); if (closer != ']') { //read module options peek = context.Input.Peek(); var optionStringBuilder = new StringBuilder(); while (peek != ButterflyStringReader.NoValue) { if (peek == ']') { context.Input.Read(); if (context.Input.Peek() != ']') { //module closer break; } //fallthrough: output a literal "]" } else if (peek == '|') { context.Input.Read(); if (context.Input.Peek() != '|') { ParseOptions(optionStringBuilder.ToString(), data); optionStringBuilder.Clear(); } //fallthrough: output a literal "|" } optionStringBuilder.Append((char)context.Input.Read()); peek = context.Input.Peek(); } //handle the last option if (optionStringBuilder.Length > 0) { ParseOptions(optionStringBuilder.ToString(), data); } } context.UpdateCurrentChar(); OpenAndCloseScope(CreateScope(name, data, context), context); }
protected override void DoExecute(ParseContext context) { OpenScope(new UnparsedScope(), context); var match = unparsedRegex.Match(context.Input.PeekSubstring); if (!match.Success) { throw new ParseException("Unparsed scope never closes"); } var text = match.Groups[1].Value.Replace("]]", "]"); context.Input.Read(match.Value.Length); context.UpdateCurrentChar(); context.Analyzer.WriteAndEscape(text); CloseCurrentScope(context); }
protected override void DoExecute(ParseContext context) { var peek = context.Input.Peek(); var listText = new StringBuilder(((char)context.CurrentChar).ToString(), 3); while (peek == '*' || peek == '#') { listText.Append((char)context.Input.Read()); peek = context.Input.Peek(); } //ignore whitespace after * or # context.Input.SeekToNonWhitespace(); context.UpdateCurrentChar(); HandleList(listText.ToString(), context); }
protected override void DoExecute(ParseContext context) { IScope rowScope = new TableRowLineScope(); if (context.Input.Peek() == '{') { context.AdvanceInput(); rowScope = new TableRowScope(); } var cellType = ScopeTypeCache.TableCell; if (context.Input.Peek() == '!') { context.AdvanceInput(); cellType = ScopeTypeCache.TableHeader; } context.Input.SeekToNonWhitespace(); context.UpdateCurrentChar(); if (!context.Scopes.ContainsType(ScopeTypeCache.Table)) { //no tables, so create a new one OpenScope(new TableScope(), context); OpenScope(rowScope, context); } else if (context.Scopes.ContainsType(ScopeTypeCache.TableCell, ScopeTypeCache.TableHeader)) { //close table cell var currentScope = context.Scopes.PeekOrDefault(); if (currentScope == null || (currentScope.GetType() != ScopeTypeCache.TableCell && currentScope.GetType() != ScopeTypeCache.TableHeader)) { throw new ParseException("Cannot close table cell until all containing scopes are closed"); } CloseCurrentScope(context); } else if (!context.Scopes.ContainsType(ScopeTypeCache.TableRow, ScopeTypeCache.TableRowLine)) { OpenScope(rowScope, context); } //figure out if we need to open a new cell or not //criteria: // - not EOL // - we're in a row terminated by a line break and the next char is not a new line (signifying a new row) // - OR we're in a row not terminated by a line break if ( context.Input.Peek() != ButterflyStringReader.NoValue && ( (context.Scopes.ContainsType(ScopeTypeCache.TableRowLine) && context.Input.Peek() != '\n') || context.Scopes.ContainsType(ScopeTypeCache.TableRow) ) ) { OpenScope(cellType == ScopeTypeCache.TableHeader ? (IScope)new TableHeaderScope() : new TableCellScope(), context); } }
protected override void DoExecute(ParseContext context) { OpenScope(new PreformattedScope(GetLanguage(context)), context); //this strategy ignores any formatting //read until }}}} var match = codeRegex.Match(context.Input.PeekSubstring); if (!match.Success) { throw new ParseException("Preformatted scope never closes"); } var text = match.Groups[1].Value; context.Input.Read(match.Value.Length); context.UpdateCurrentChar(); context.Analyzer.WriteAndEscape(text); CloseCurrentScope(context); }