Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
QuotedValueLiteral.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  //Terminal for reading values enclosed in a pair of start/end characters. For ex, date literal #15/10/2009# in VB
9  public string StartSymbol;
10  public string EndSymbol;
11 
12  public QuotedValueLiteral(string name, string startEndSymbol, TypeCode dataType) : this(name, startEndSymbol, startEndSymbol, dataType) {}
13 
14  public QuotedValueLiteral(string name, string startSymbol, string endSymbol, TypeCode dataType) : base(name, dataType) {
15  StartSymbol = startSymbol;
16  EndSymbol = endSymbol;
17  }
18 
19  public override IList<string> GetFirsts() {
20  return new string[] {StartSymbol};
21  }
22  protected override string ReadBody(ParsingContext context, ISourceStream source) {
23  if (!source.MatchSymbol(StartSymbol, !Grammar.CaseSensitive)) return null; //this will result in null returned from TryMatch, no token
24  var start = source.Location.Position + StartSymbol.Length;
25  var end = source.Text.IndexOf(EndSymbol, start);
26  if (end < 0) return null;
27  var body = source.Text.Substring(start, end - start);
28  source.PreviewPosition = end + EndSymbol.Length; //move beyond the end of EndSymbol
29  return body;
30  }
31  }//class
32 
33 }//namespace
override string ReadBody(ParsingContext context, ISourceStream source)
Interface for Terminals to access the source stream and produce tokens.
readonly bool CaseSensitive
Gets case sensitivity of the grammar. Read-only, true by default. Can be set to false only through a ...
Definition: Grammar.cs:27
QuotedValueLiteral(string name, string startEndSymbol, TypeCode dataType)
override IList< string > GetFirsts()
bool MatchSymbol(string symbol, bool ignoreCase)
Tries to match the symbol with the text at current preview position.
QuotedValueLiteral(string name, string startSymbol, string endSymbol, TypeCode dataType)