Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
WikiTagTerminal.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 
6 namespace Irony.Parsing {
7 
8  //Handles formatting tags like *bold*, _italic_; also handles headings and lists
10 
11  public WikiTagTerminal(string name, WikiTermType termType, string tag, string htmlElementName)
12  : this (name, termType, tag, string.Empty, htmlElementName) { }
13 
14  public WikiTagTerminal(string name, WikiTermType termType, string openTag, string closeTag, string htmlElementName)
15  : base (name, termType, openTag, closeTag, htmlElementName) { }
16 
17  public override Token TryMatch(ParsingContext context, ISourceStream source) {
18  bool isHeadingOrList = TermType == WikiTermType.Heading || TermType == WikiTermType.List;
19  if(isHeadingOrList) {
20  bool isAfterNewLine = (context.PreviousToken == null || context.PreviousToken.Terminal == Grammar.NewLine);
21  if(!isAfterNewLine) return null;
22  }
23  if(!source.MatchSymbol(OpenTag, true)) return null;
24  source.PreviewPosition += OpenTag.Length;
25  //For headings and lists require space after
26  if(TermType == WikiTermType.Heading || TermType == WikiTermType.List) {
27  const string whitespaces = " \t\r\n\v";
28  if (!whitespaces.Contains(source.PreviewChar)) return null;
29  }
30  var token = source.CreateToken(this.OutputTerminal);
31  return token;
32  }
33 
34  }//class
35 
36 }//namespace
WikiTagTerminal(string name, WikiTermType termType, string openTag, string closeTag, string htmlElementName)
char PreviewChar
Gets a char at preview position
Interface for Terminals to access the source stream and produce tokens.
WikiTagTerminal(string name, WikiTermType termType, string tag, string htmlElementName)
override Token TryMatch(ParsingContext context, ISourceStream source)
Tokens are produced by scanner and fed to parser, optionally passing through Token filters in between...
Definition: Token.cs:74
bool MatchSymbol(string symbol, bool ignoreCase)
Tries to match the symbol with the text at current preview position.