Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
NamedBlockKeyTerm.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using GoldParser;
4 
5 using Irony.Parsing;
6 
7 namespace SiliconStudio.Shaders.Grammar
8 {
9  internal class NamedBlockKeyTerm : DynamicKeyTerm
10  {
11  public NamedBlockKeyTerm(string text, string name)
12  : base(text, name)
13  {
14  }
15 
16  public override void Match(Tokenizer toknizer, out Token token)
17  {
18  var parser = toknizer.GoldParser;
19 
20  var location = toknizer.Location;
21  var nextSymbol = parser.ReadToken();
22 
23  while (nextSymbol.SymbolType == SymbolType.WhiteSpace || nextSymbol.Index == (int)TokenType.NewLine)
24  nextSymbol = parser.ReadToken();
25 
26  if (nextSymbol.Index != (int)TokenType.LeftCurly)
27  {
28  token = new Token(Grammar.SyntaxError, location, parser.TokenText, "Expecting '{'");
29  return;
30  }
31 
32  var startPosition = parser.CharPosition;
33 
34  bool rightCurlyFound = false;
35  int length = 0;
36  for (int i = parser.CharPosition; i < parser.TextBuffer.Length; i++, length++)
37  {
38  if (parser.TextBuffer[i] == '}')
39  {
40  rightCurlyFound = true;
41  break;
42  }
43  }
44 
45  if (!rightCurlyFound)
46  {
47  token = new Token(Grammar.SyntaxError, location, parser.TokenText, "Closing '}' not found");
48  return;
49  }
50 
51  token = new Token(this, location, parser.TextBuffer.Substring(startPosition, length), null);
52 
53  // Move the parser
54  parser.MoveBy(length+1);
55  }
56  }
57 }
readonly Terminal SyntaxError
Definition: Grammar.cs:431
Tokens are produced by scanner and fed to parser, optionally passing through Token filters in between...
Definition: Token.cs:74