STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
TypeAssignment.cs
Go to the documentation of this file.
1 /*
2  * Created by SharpDevelop.
3  * User: lextm
4  * Date: 2008/5/18
5  * Time: 13:24
6  *
7  * To change this template use Tools | Options | Coding | Edit Standard Headers.
8  */
9 using System;
10 using System.Collections.Generic;
11 
12 namespace Lextm.SharpSnmpLib.Mib.Elements.Types
13 {
14  /* Please be aware of the following possible constructs:
15  *
16  * isnsRegEntityIndex OBJECT-TYPE
17  * SYNTAX IsnsEntityIndexIdOrZero
18  * ( 1 .. 4294967295 )
19  * MAX-ACCESS not-accessible
20  *
21  *
22  */
23 
26  public sealed class TypeAssignment : ITypeAssignment
27  {
28  private IModule _module;
29  private string _name;
30  private string _type;
31  private ValueRanges _ranges;
32  private ValueMap _map;
33 
42  public TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
43  {
44  _module = module;
45  _name = name;
46 
47  SymbolList typeSymbols = new SymbolList();
48  typeSymbols.Add(type);
49 
50  Symbol current = symbols.NextSymbol();
51  while (current != Symbol.EOL)
52  {
53  if (current == Symbol.OpenParentheses)
54  {
55  // parse range of unknown type
56  symbols.PutBack(current);
57  _ranges = Lexer.DecodeRanges(symbols);
58  break;
59  }
60  else if (current == Symbol.OpenBracket)
61  {
62  symbols.PutBack(current);
63  _map = Lexer.DecodeEnumerations(symbols);
64  break;
65  }
66 
67  typeSymbols.Add(current);
68  current = symbols.NextSymbol();
69  }
70 
71  _type = typeSymbols.Join(" ");
72 
73  if ((_ranges == null) && (_map == null))
74  {
75  current = symbols.NextNonEOLSymbol();
76  if (current == Symbol.OpenParentheses)
77  {
78  // parse range of unknown type
79  symbols.PutBack(current);
80  _ranges = Lexer.DecodeRanges(symbols);
81  }
82  else if (current == Symbol.OpenBracket)
83  {
84  symbols.PutBack(current);
85  _map = Lexer.DecodeEnumerations(symbols);
86  }
87  else if (current != null)
88  {
89  symbols.PutBack(current);
90  }
91  }
92 
93  if (isMacroSyntax)
94  {
95  // inside a macro the syntax is limited to one line, except there are brackets used for ranges/enums
96  return;
97  }
98 
99  // outside macro Syntax clause we wait for two consecutive linebreaks with a following valid identifier as end condition
100  Symbol previous = current;
101  Symbol veryPrevious = null;
102 
103  while ((current = symbols.NextSymbol()) != null)
104  {
105  if ((veryPrevious == Symbol.EOL) && (previous == Symbol.EOL) && current.IsValidIdentifier())
106  {
107  symbols.PutBack(current);
108  return;
109  }
110 
111  veryPrevious = previous;
112  previous = current;
113  }
114 
115  previous.Assert(false, "end of file reached");
116  }
117 
118  public string Type
119  {
120  get { return _type; }
121  }
122 
123  public ValueRanges Ranges
124  {
125  get { return _ranges; }
126  }
127 
128  public IDictionary<long, string> Map
129  {
130  get { return _map; }
131  }
132 
133  #region ITypeAssignment Member
134 
135  public IModule Module
136  {
137  get { return _module; }
138  }
139 
140  public string Name
141  {
142  get { return _name; }
143  }
144 
145  #endregion
146  }
147 }
string Join(string separator)
Definition: SymbolList.cs:99
MIB Module interface.
Definition: IModule.cs:36
static ValueRanges DecodeRanges(ISymbolEnumerator symbols)
Definition: Lexer.cs:409
static readonly Symbol EOL
Definition: Symbol.cs:198
TypeAssignment(IModule module, string name, Symbol type, ISymbolEnumerator symbols, bool isMacroSyntax)
Creates an TypeAssignment.
static ValueMap DecodeEnumerations(ISymbolEnumerator symbols)
Definition: Lexer.cs:534
static readonly Symbol OpenParentheses
Definition: Symbol.cs:211
static readonly Symbol OpenBracket
Definition: Symbol.cs:185
Lexer class that parses MIB files into symbol list.
Definition: Lexer.cs:21
Description of Symbol.
Definition: Symbol.cs:20