source: azure_iot_hub_f767zi/trunk/asp_baseplatform/lwip/contrib-2.1.0/apps/LwipMibCompiler/SharpSnmpLib/Mib/Elements/Types/TypeAssignment.cs@ 457

Last change on this file since 457 was 457, checked in by coas-nagasima, 4 years ago

ファイルを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csharp;charset=UTF-8
File size: 4.4 KB
Line 
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 */
9using System;
10using System.Collections.Generic;
11
12namespace 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
24 /// <summary/>
25 /// </summary>
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
34 /// <summary>
35 /// Creates an <see cref="TypeAssignment" />.
36 /// </summary>
37 /// <param name="module">The module.</param>
38 /// <param name="name">The name.</param>
39 /// <param name="type">The type.</param>
40 /// <param name="symbols">The symbols.</param>
41 /// <param name="isMacroSyntax">if set to <c>true</c> indicates that the syntax clause of a macro is parsed (e.g. OBJECT-TYPE, TEXTUAL-CONVENTION).</param>
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}
Note: See TracBrowser for help on using the repository browser.