File: ImportsFrom.cs

package info (click to toggle)
lwip 2.2.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 10,008 kB
  • sloc: ansic: 109,524; cs: 6,714; sh: 115; makefile: 112; perl: 81
file content (60 lines) | stat: -rw-r--r-- 1,548 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
 * Created by SharpDevelop.
 * User: lextm
 * Date: 2008/5/31
 * Time: 12:07
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System.Collections.Generic;

namespace Lextm.SharpSnmpLib.Mib.Elements
{
    public sealed class ImportsFrom
    {
        private readonly string _module;
        private readonly List<string> _types = new List<string>();

        public ImportsFrom(Symbol last, ISymbolEnumerator symbols)
        {
            Symbol previous = last;
            Symbol current;
            while ((current = symbols.NextSymbol()) != Symbol.From)
            {
                if (current == Symbol.EOL) 
                {
                    continue;
                }
                
                if (current == Symbol.Comma)
                {
                    previous.AssertIsValidIdentifier();
                    _types.Add(previous.ToString());
                }
                
                previous = current;
            }

            previous.AssertIsValidIdentifier();
            _types.Add(previous.ToString());

            _module = symbols.NextSymbol().ToString().ToUpperInvariant(); // module names are uppercase
        }
        
        public string Module
        {
            get { return _module; }
        }

        public IList<string> Types
        {
            get { return _types; }
        }

        public override string ToString()
        {
            return string.Join(", ", _types.ToArray()) + " FROM " + _module;
        }
    }
}