Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
WikiBlockTerminal.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  public enum WikiBlockType {
10  CodeBlock,
11  Anchor,
13  Url,
14  FileLink, //looks like it is the same as Url
15  Image,
16  }
17 
19  public readonly WikiBlockType BlockType;
20 
21  public WikiBlockTerminal(string name, WikiBlockType blockType, string openTag, string closeTag, string htmlElementName)
22  : base(name, WikiTermType.Block, openTag, closeTag, htmlElementName) {
23  BlockType = blockType;
24  }
25 
26  public override Token TryMatch(ParsingContext context, ISourceStream source) {
27  if (!source.MatchSymbol(OpenTag, true)) return null;
28  source.PreviewPosition += OpenTag.Length;
29  var endPos = source.Text.IndexOf(CloseTag, source.PreviewPosition);
30  string content;
31  if(endPos > 0) {
32  content = source.Text.Substring(source.PreviewPosition, endPos - source.PreviewPosition);
33  source.PreviewPosition = endPos + CloseTag.Length;
34  } else {
35  content = source.Text.Substring(source.PreviewPosition, source.Text.Length - source.PreviewPosition);
36  source.PreviewPosition = source.Text.Length;
37  }
38  var token = source.CreateToken(this.OutputTerminal, content);
39  return token;
40  }
41 
42 
43  }//class
44 }//namespace
override Token TryMatch(ParsingContext context, ISourceStream source)
WikiBlockTerminal(string name, WikiBlockType blockType, string openTag, string closeTag, string htmlElementName)
Interface for Terminals to access the source stream and produce tokens.
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.
readonly WikiBlockType BlockType