Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
FixedLengthLiteral.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 using System.Globalization;
18 
19 namespace Irony.Parsing {
20 
21  //A terminal for representing fixed-length lexemes coming up sometimes in programming language
22  // (in Fortran for ex, every line starts with 5-char label, followed by a single continuation char)
23  // It may be also used to create grammar/parser for reading data files with fixed length fields
25  public int Length;
26 
27  public FixedLengthLiteral(string name, int length, TypeCode dataType) : base(name, dataType) {
28  Length = length;
29  }
30 
31  protected override string ReadBody(ParsingContext context, ISourceStream source) {
32  source.PreviewPosition = source.Location.Position + Length;
33  var body = source.Text.Substring(source.Location.Position, Length);
34  return body;
35  }
36 
37  }//class
38 
39 }//namespace
override string ReadBody(ParsingContext context, ISourceStream source)
FixedLengthLiteral(string name, int length, TypeCode dataType)
Interface for Terminals to access the source stream and produce tokens.