Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CustomTerminal.cs
Go to the documentation of this file.
1 #region License
2 /* **********************************************************************************
3  * Copyright (c) Roman Ivantsov
4  * This source code is subject to terms and conditions of the MIT License
5  * for Irony. A copy of the license can be found in the License.txt file
6  * at the root of this distribution.
7  * By using this source code in any fashion, you are agreeing to be bound by the terms of the
8  * MIT License.
9  * You must not remove this notice from this software.
10  * **********************************************************************************/
11 #endregion
12 
13 using System;
14 using System.Collections.Generic;
15 using System.Text;
16 
17 namespace Irony.Parsing {
18  //Terminal based on custom method; allows creating custom match without creating new class derived from Terminal
19  public delegate Token MatchHandler(Terminal terminal, ParsingContext context, ISourceStream source);
20  public class CustomTerminal : Terminal {
21  public CustomTerminal(string name, MatchHandler handler, params string[] prefixes) : base(name) {
22  _handler = handler;
23  if (prefixes != null)
24  Prefixes.AddRange(prefixes);
25  this.EditorInfo = new TokenEditorInfo(TokenType.Unknown, TokenColor.Text, TokenTriggers.None);
26  }
27 
28  public readonly StringList Prefixes = new StringList();
29 
30  public MatchHandler Handler {
31  [System.Diagnostics.DebuggerStepThrough]
32  get {return _handler;}
33  } MatchHandler _handler;
34 
35  public override Token TryMatch(ParsingContext context, ISourceStream source) {
36  return _handler(this, context, source);
37  }
38  [System.Diagnostics.DebuggerStepThrough]
39  public override IList<string> GetFirsts() {
40  return Prefixes;
41  }
42  }//class
43 
44 
45 }
Interface for Terminals to access the source stream and produce tokens.
override IList< string > GetFirsts()
CustomTerminal(string name, MatchHandler handler, params string[] prefixes)
Tokens are produced by scanner and fed to parser, optionally passing through Token filters in between...
Definition: Token.cs:74
override Token TryMatch(ParsingContext context, ISourceStream source)
delegate Token MatchHandler(Terminal terminal, ParsingContext context, ISourceStream source)