Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
_ISourceStream.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.Linq;
16 using System.Text;
17 
18 namespace Irony.Parsing {
19  //
20  /// <summary>
21  /// Interface for Terminals to access the source stream and produce tokens.
22  /// </summary>
23  public interface ISourceStream {
24 
25  /// <summary>
26  /// Returns the source text
27  /// </summary>
28  string Text { get; }
29  /// <summary>
30  /// Current start location (position, row, column) of the new token
31  /// </summary>
32  SourceLocation Location { get; set; }
33 
34  /// <summary>
35  /// Gets or sets the current preview position in the source file. Must be greater or equal to Location.Position
36  /// </summary>
37  int PreviewPosition { get; set; }
38  /// <summary>
39  /// Gets a char at preview position
40  /// </summary>
41  char PreviewChar { get; }
42  /// <summary>
43  /// Gets the char at position next after the PrevewPosition
44  /// </summary>
45  char NextPreviewChar { get; } //char at PreviewPosition+1
46 
47  /// <summary>
48  /// Creates a new token based on current preview position.
49  /// </summary>
50  /// <param name="terminal">A terminal associated with the token.</param>
51  /// <returns>New token.</returns>
52  Token CreateToken(Terminal terminal);
53 
54  /// <summary>
55  /// Creates a new token based on current preview position and sets its Value field.
56  /// </summary>
57  /// <param name="terminal">A terminal associated with the token.</param>
58  /// <param name="value">The value associated with the token.</param>
59  /// <returns>New token.</returns>
60  Token CreateToken(Terminal terminal, object value);
61 
62  /// <summary>
63  /// Creates error token with custom error message as its Value.
64  /// </summary>
65  /// <param name="message">Message template, can contain placeholder like {0} to be filled by values from <c>args</c>.</param>
66  /// <param name="args">A list of message arguments</param>
67  /// <returns>An error token.</returns>
68  Token CreateErrorToken(string message, params object[] args);
69 
70  /// <summary>
71  /// Tries to match the symbol with the text at current preview position.
72  /// </summary>
73  /// <param name="symbol">A symbol to match</param>
74  /// <param name="ignoreCase">True if char casing should be ignored.</param>
75  /// <returns>True if there is a match; otherwise, false.</returns>
76  bool MatchSymbol(string symbol, bool ignoreCase);
77 
78  int TabWidth { get; set;}
79  bool EOF();
80 
81  /*
82  //This member is intentionally removed from ISourceStream and made private in SourceStream class. The purpose is to discourage
83  its use or imitation - it produces a new string object which means new garbage for GC. All Irony-defined Terminal classes
84  are implemented without it, but you can always reproduce the implementation in your custom code if you really need it
85  string GetPreviewText();
86  */
87 
88  }//interface
89 
90 
91 }
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