private static ScannerResult ScanCloseParenToken(SourceReader reader) { (var sourceChar, var nextReader) = reader.Read(')'); var extent = SourceExtent.From(sourceChar); return(new ScannerResult(new CloseParenToken(extent), nextReader)); }
private static ScannerResult ScanIdentifierToken(SourceReader reader) { var thisReader = reader; var sourceChar = default(SourceChar); var sourceChars = new List <SourceChar>(); var nameChars = new StringBuilder(); // firstIdentifierChar (sourceChar, thisReader) = thisReader.Read(ArmStringValidator.IsFirstIdentifierChar); sourceChars.Add(sourceChar); nameChars.Append(sourceChar.Value); // *( nextIdentifierChar ) while (!thisReader.Eof() && thisReader.Peek(ArmStringValidator.IsNextIdentifierChar)) { (sourceChar, thisReader) = thisReader.Read(); sourceChars.Add(sourceChar); nameChars.Append(sourceChar.Value); } // return the result var extent = SourceExtent.From(sourceChars); var name = nameChars.ToString(); return(new ScannerResult( new IdentifierToken(extent, name), thisReader )); }
private static ScannerResult ScanDotOperatorToken(SourceReader reader) { (var sourceChar, var nextReader) = reader.Read('.'); var extent = SourceExtent.From(sourceChar); return(new ScannerResult(new DotOperatorToken(extent), nextReader)); }
private static ScannerResult ScanOpenBracketToken(SourceReader reader) { (var sourceChar, var nextReader) = reader.Read('['); var extent = SourceExtent.From(sourceChar); return(new ScannerResult(new OpenBracketToken(extent), nextReader)); }
private void CreateHardBreakSpan(Match regexMatch, SourceExtent sourceExtent) { this.StartParagraph(); _currentParagraphSpans.Add( new HardBreakSpan( sourceExtent)); }
public CodeBlockNode(string languageMoniker, string codeBlockContents, SourceExtent sourceExtent) : base(codeBlockContents.Trim(), sourceExtent) { if (!string.IsNullOrEmpty(languageMoniker)) { this.LanguageMoniker = languageMoniker; } }
private void CreateTickCodeBlock(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); _currentDocument.AddChildNode( new CodeBlockNode( regexMatch.Groups[2].Value, sourceExtent)); }
private void CreateBoldSpan(Match regexMatch, SourceExtent sourceExtent) { this.StartParagraph(); _currentParagraphSpans.Add( new TextSpan( regexMatch.Groups[1].Value, sourceExtent, TextSpanStyle.Bold)); }
private void CreateHyperlinkSpan(Match regexMatch, SourceExtent sourceExtent) { this.StartParagraph(); _currentParagraphSpans.Add( new HyperlinkSpan( regexMatch.Groups[1].Value, regexMatch.Groups[2].Value, sourceExtent)); }
private void CreateHashHeader2(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); _currentDocument.AddChildNode( new HeadingNode( regexMatch.Groups[3].Value, regexMatch.Groups[2].Value.Length, sourceExtent)); }
private static ScannerResult ScanStringLiteralToken(SourceReader reader) { const char SINGLEQUOTE = '\''; var thisReader = reader; var sourceChar = default(SourceChar); var sourceChars = new List <SourceChar>(); var stringChars = new StringBuilder(); // read the first single-quote (sourceChar, thisReader) = thisReader.Read(SINGLEQUOTE); sourceChars.Add(sourceChar); // read the remaining characters var isTerminated = false; while (!thisReader.Eof()) { var peek = thisReader.Peek(); sourceChars.Add(peek); if (peek.Value == SINGLEQUOTE) { thisReader = thisReader.Next(); if (!thisReader.Eof() && (thisReader.Peek().Value == SINGLEQUOTE)) { // an escaped single-quote (i.e. "''") sourceChars.Add(peek); stringChars.Append(SINGLEQUOTE); thisReader = thisReader.Next(); } else { // the closing single-quote character isTerminated = true; break; } } else { // we just read a literal string character stringChars.Append(peek.Value); thisReader = thisReader.Next(); } } // make sure we found the end of the string if (!isTerminated) { throw new InvalidOperationException("Unterminated string found."); } // return the result var extent = SourceExtent.From(sourceChars); var stringValue = stringChars.ToString(); return(new ScannerResult( new StringLiteralToken(extent, stringValue), thisReader )); }
public HelpSchemaException(SourceExtent extent, string message) : base( String.Format( "{0}:{1} '{2}'\n {3}", extent.Line.Start, extent.Column.Start, GetSnippet(extent.OriginalText), message) ) { }
private void CreateItalicSpan(Match regexMatch, SourceExtent sourceExtent) { this.StartParagraph(); _currentParagraphSpans.Add( new TextSpan( regexMatch.Groups[1].Value, sourceExtent, this._parserMode, TextSpanStyle.Italic)); }
public Lexer AddScanner(char value, Func <SourceExtent, SyntaxToken> factoryMethod) { return(this.AddScanner( value, (reader) => { (var sourceChar, var nextReader) = reader.Read(value); var extent = SourceExtent.From(sourceChar); return new ScannerResult( factoryMethod(extent), nextReader ); } )); }
private void CreateHashHeader2(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); _currentDocument.AddChildNode( new HeadingNode( regexMatch.Groups[3].Value, regexMatch.Groups[2].Value.Length, sourceExtent, // Detect if a line break after the header exists. Mutiple line breaks will be reduced to one. (regexMatch.Groups[4].Captures.Count > 1) ? SectionFormatOption.LineBreakAfterHeader : SectionFormatOption.None)); }
private void CreateUnderlineHeader(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); int headerLevel = regexMatch.Groups[2].Value[0] == '=' ? 1 : 2; _currentDocument.AddChildNode( new HeadingNode( regexMatch.Groups[1].Value, headerLevel, sourceExtent)); }
private void CreateUnderlineHeader(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); int headerLevel = regexMatch.Groups[2].Value[0] == '=' ? 1 : 2; _currentDocument.AddChildNode( new HeadingNode( regexMatch.Groups[1].Value, headerLevel, sourceExtent, // Detect if a line break after the header exists. Mutiple line breaks will be reduced to one. (regexMatch.Groups[3].Captures.Count > 1) ? SectionFormatOption.LineBreakAfterHeader : SectionFormatOption.None)); }
private void CreateNormalSpan(string spanText, SourceExtent sourceExtent) { this.StartParagraph(); // TODO: Replace all newlines with spaces? We // might want to add line breaks only when the // user has intentionally typed a hard break string // ( \r\n) // If the span is merely whitespace, don't add it if (!string.IsNullOrWhiteSpace(spanText)) { _currentParagraphSpans.Add( new TextSpan( spanText, sourceExtent)); } }
private static ScannerResult ScanIntegerToken(SourceReader reader) { var thisReader = reader; var sourceChar = default(SourceChar); var sourceChars = new List <SourceChar>(); var sign = 1; var value = 0; // read the sign switch (thisReader.Peek().Value) { case '-': sign = -1; (sourceChar, thisReader) = thisReader.Read('-'); sourceChars.Add(sourceChar); break; case '+': sign = +1; (sourceChar, thisReader) = thisReader.Read('+'); sourceChars.Add(sourceChar); break; } // digit (sourceChar, thisReader) = thisReader.Read(ArmStringValidator.IsDigit); sourceChars.Add(sourceChar); value = value * 10 + (sourceChar.Value - '0'); // *( digit ) while (!thisReader.Eof() && thisReader.Peek(ArmStringValidator.IsDigit)) { (sourceChar, thisReader) = thisReader.Read(); sourceChars.Add(sourceChar); value = value * 10 + (sourceChar.Value - '0'); } // return the result var extent = SourceExtent.From(sourceChars); return(new ScannerResult( new IntegerToken(extent, sign * value), thisReader )); }
private static ScannerResult ScanWhitespaceToken(SourceReader reader) { var thisReader = reader; var sourceChar = default(SourceChar); var sourceChars = new List <SourceChar>(); // read the first whitespace character (sourceChar, thisReader) = thisReader.Read(ArmStringValidator.IsWhitespace); sourceChars.Add(sourceChar); // read the remaining whitespace while (!thisReader.Eof() && thisReader.Peek(ArmStringValidator.IsWhitespace)) { (sourceChar, thisReader) = thisReader.Read(); sourceChars.Add(sourceChar); } // return the result var extent = SourceExtent.From(sourceChars); var value = extent.ToString(); return(new ScannerResult( new WhitespaceToken(extent, value), thisReader )); }
internal WhitespaceToken(SourceExtent extent) : base(extent) { }
public HeadingNode(string headingText, int headingLevel, SourceExtent sourceExtent) : base(headingText, sourceExtent) { this.HeadingLevel = headingLevel; }
public TextSpan(string spanText, SourceExtent sourceExtent, TextSpanStyle spanStyle = TextSpanStyle.Normal) : base(UnwindMarkdownCharsEscaping(spanText.Trim()), sourceExtent) { this.Style = spanStyle; }
public CloseParenToken(SourceExtent extent) : base(extent) { }
public AttributeCloseToken(SourceExtent extent) : base(extent) { }
internal IntegerLiteralToken(SourceExtent extent, long value) : base(extent) { this.Value = value; }
public CodeBlockNode(string codeBlockContents, SourceExtent sourceExtent) : base(codeBlockContents.Trim(), sourceExtent) { }
private void CreateParagraph(Match regexMatch, SourceExtent sourceExtent) { this.FinishParagraph(); this.StartParagraph(); }
private void CreateSoftBreakSpan(Match regexMatch, SourceExtent sourceExtent) { // Don't create a span? }
public TextNode(string textContents, SourceExtent sourceExtent) { this.Text = textContents; this.SourceExtent = sourceExtent; }
public HeadingNode(string headingText, int headingLevel, SourceExtent sourceExtent) : base(headingText, sourceExtent) { this.HeadingLevel = headingLevel; }
internal IdentifierToken(SourceExtent extent, string name) : base(extent) { this.Name = name; }
public NullLiteralToken(SourceExtent extent) : base(extent) { }
public HardBreakSpan(SourceExtent sourceExtent) : base("\n", sourceExtent, Parser.ParserMode.Full) { }
public HardBreakSpan(SourceExtent sourceExtent) : base("\n", sourceExtent) { }