/// <summary> /// Creates an <see cref="IntegerType"/> instance. /// </summary> /// <param name="module"></param> /// <param name="name"></param> /// <param name="enumerator"></param> public IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols) : base(module, name) { Types?t = GetExactType(type); type.Assert(t.HasValue, "Unknown symbol for unsigned type!"); _type = t.Value; _isEnumeration = false; Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.OpenBracket) { _isEnumeration = true; symbols.PutBack(current); _map = Lexer.DecodeEnumerations(symbols); } else if (current == Symbol.OpenParentheses) { symbols.PutBack(current); _ranges = Lexer.DecodeRanges(symbols); current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of integer types!"); } else { symbols.PutBack(current); } }
/// <summary> /// Creates an <see cref="IntegerType"/> instance. /// </summary> /// <param name="module"></param> /// <param name="name"></param> /// <param name="enumerator"></param> public IntegerType(IModule module, string name, Symbol type, ISymbolEnumerator symbols) : base (module, name) { Types? t = GetExactType(type); type.Assert(t.HasValue, "Unknown symbol for unsigned type!"); _type = t.Value; _isEnumeration = false; Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.OpenBracket) { _isEnumeration = true; symbols.PutBack(current); _map = Lexer.DecodeEnumerations(symbols); } else if (current == Symbol.OpenParentheses) { symbols.PutBack(current); _ranges = Lexer.DecodeRanges(symbols); current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of integer types!"); } else { symbols.PutBack(current); } }
private static string ParseAugments(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.Augments) { string augment = null; current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenBracket); current = symbols.NextNonEOLSymbol(); augment = current.ToString(); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseBracket); return(augment); } else if (current != null) { symbols.PutBack(current); } return(null); }
public EntityBase(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols) { _module = module; _name = preAssignSymbols[0].ToString(); Lexer.ParseOidValue(symbols, out _parent, out _value); }
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 override void EnumSymbols(ISymbolEnumerator en) { foreach (var item in Items) { item.EnumSymbols(en); } }
public override void EnumSymbols(ISymbolEnumerator en) { if (Prefix != null) { Prefix.EnumSymbols(en); } }
private static string ParseDescription(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.Description); return symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' }); }
public override void EnumSymbols(ISymbolEnumerator en) { en.EnumSymbol(WhenPos, this); WhenExpr.EnumSymbols(en); en.EnumSymbol(ThenPos, null); ThenExpr.EnumSymbols(en); }
private static string ParseAugments(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.Augments) { string augment = null; current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenBracket); current = symbols.NextNonEOLSymbol(); augment = current.ToString(); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseBracket); return augment; } else if (current != null) { symbols.PutBack(current); } return null; }
public override void EnumSymbols(ISymbolEnumerator en) { FunctionName.EnumSymbols(en); en.EnumSymbol(LeftBracket, this); Arguments.EnumSymbols(en); en.EnumSymbol(RightBracket, this); }
private static string ParseDescription(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.Description); return(symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' })); }
private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.Syntax); return(Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true)); }
public override void EnumSymbols(ISymbolEnumerator en) { if (!IsFirst) { en.EnumSymbol(CommaPos, this); } Argument.EnumSymbols(en); }
public override void EnumSymbols(ISymbolEnumerator en) { if (Ident != null) { Ident.EnumSymbols(en); } en.EnumSymbol(DotPos, this); }
public override void EnumSymbols(ISymbolEnumerator en) { Source.EnumSymbols(en); foreach (var j in Joins) { j.EnumSymbols(en); } }
public override void EnumSymbols(ISymbolEnumerator en) { SourceData.EnumSymbols(en); if (Shortcut != null) { Shortcut.EnumSymbols(en); } }
public override void EnumSymbols(ISymbolEnumerator en) { foreach (var mark in UnaryMarks) { en.EnumSymbol(mark, this); } Inner.EnumSymbols(en); }
public override void EnumSymbols(ISymbolEnumerator en) { foreach (var qal in Qualificators) { qal.EnumSymbols(en); } Name.EnumSymbols(en); }
public override void EnumSymbols(ISymbolEnumerator en) { Value.EnumSymbols(en); en.EnumSymbol(BetweenPos, this); LowerBound.EnumSymbols(en); en.EnumSymbol(AndPos, this); UpperBound.EnumSymbols(en); }
public override void EnumSymbols(ISymbolEnumerator en) { Left.EnumSymbols(en); foreach (var mark in BinaryMarks) { en.EnumSymbol(mark, this); } Right.EnumSymbols(en); }
public override void EnumSymbols(ISymbolEnumerator en) { if (ClauseWordsPos != null) { foreach (var sym in ClauseWordsPos) { en.EnumSymbol(sym, this); } } }
public override void EnumSymbols(ISymbolEnumerator en) { JoinPrefix.EnumSymbols(en); Source.EnumSymbols(en); if (Condition != null) { en.EnumSymbol(OnPos, this); Condition.EnumSymbols(en); } }
public override void EnumSymbols(ISymbolEnumerator en) { en.EnumSymbol(LeftBracket, this); Inner.EnumSymbols(en); en.EnumSymbol(RightBracket, this); if (Shortcut != null) { Shortcut.EnumSymbols(en); } }
public TrapType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols) { _module = module; _name = preAssignSymbols[0].ToString(); Symbol valueSymbol = symbols.NextNonEOLSymbol(); bool succeeded = int.TryParse(valueSymbol.ToString(), out _value); valueSymbol.Assert(succeeded, "not a decimal"); }
/// <summary> /// Creates a <see cref="Choice"/> instance. /// </summary> /// <param name="module"></param> /// <param name="name"></param> /// <param name="lexer"></param> public Choice(IModule module, string name, ISymbolEnumerator symbols) : base(module, name) { while (symbols.NextNonEOLSymbol() != Symbol.OpenBracket) { } while (symbols.NextNonEOLSymbol() != Symbol.CloseBracket) { } }
public TextualConvention(IModule module, string name, ISymbolEnumerator symbols) { _module = module; _name = name; _displayHint = ParseDisplayHint(symbols); _status = ParseStatus(symbols); _description = ParseDescription(symbols); _reference = ParseReference(symbols); _syntax = ParseSyntax(module, symbols); }
public override void EnumSymbols(ISymbolEnumerator en) { en.EnumSymbol(SelectPos, this); foreach (var res in ResultFields) { res.EnumSymbols(en); } foreach (var clause in Clauses) { clause.EnumSymbols(en); } }
private static DisplayHint ParseDisplayHint(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.DisplayHint) { return(new DisplayHint(symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' }))); } symbols.PutBack(current); return(null); }
private static DisplayHint ParseDisplayHint(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.DisplayHint) { return new DisplayHint(symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' })); } symbols.PutBack(current); return null; }
/// <summary> /// Initializes a new instance of the <see cref="MibDocument"/> class. /// </summary> /// <param name="lexer">The lexer.</param> public MibDocument(Lexer lexer) { ISymbolEnumerator symbols = lexer.GetEnumerator(); Symbol current; while ((current = symbols.NextNonEOLSymbol()) != null) { symbols.PutBack(current); _modules.Add(new MibModule(symbols)); } }
public Macro(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols) { _module = module; _name = preAssignSymbols[0].ToString(); while (symbols.NextNonEOLSymbol() != Symbol.Begin) { } while (symbols.NextNonEOLSymbol() != Symbol.End) { } }
public override void EnumSymbols(ISymbolEnumerator en) { if (IsComma) { en.EnumSymbol(CommaPos, this); } Value.EnumSymbols(en); if (Alias != null) { en.EnumSymbol(AsPos, this); Alias.EnumSymbols(en); } }
public IpAddressType(IModule module, string name, ISymbolEnumerator symbols) : base(module, name, symbols) { if (this.Size.Count != 0) { throw new MibException("Size definition not allowed for IpAddress type!"); } // IpAddress type is defined as: // IpAddress ::= // [APPLICATION 0] // IMPLICIT OCTET STRING (SIZE (4)) this.Size.Add(new ValueRange(4, null)); }
public override void EnumSymbols(ISymbolEnumerator en) { en.EnumSymbol(CasePos, this); foreach (var when in Whens) { when.EnumSymbols(en); } if (ElseVal != null) { en.EnumSymbol(ElsePos, this); ElseVal.EnumSymbols(en); } en.EnumSymbol(EndPos, this); }
private static Status ParseStatus(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.Status); try { return (Status)Enum.Parse(typeof(Status), symbols.NextNonEOLSymbol().ToString()); } catch (ArgumentException) { current.Assert(false, "Invalid/Unknown status"); } return Status.current; }
public OctetStringType(IModule module, string name, ISymbolEnumerator symbols) : base(module, name) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.OpenParentheses) { symbols.PutBack(current); _size = Lexer.DecodeRanges(symbols); current.Assert(_size.IsSizeDeclaration, "SIZE keyword is required for ranges of octet string!"); } else { symbols.PutBack(current); _size = new ValueRanges(isSizeDecl: true); } }
private static string ParseDefVal(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.DefVal) { current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenBracket); string defVal = null; current = symbols.NextNonEOLSymbol(); if (current == Symbol.OpenBracket) { int depth = 1; // TODO: decode this. while (depth > 0) { current = symbols.NextNonEOLSymbol(); if (current == Symbol.OpenBracket) { depth++; } else if (current == Symbol.CloseBracket) { depth--; } } } else { defVal = current.ToString(); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseBracket); } return defVal; } else if (current != null) { symbols.PutBack(current); } return null; }
private static string ParseReference(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.Reference) { string reference = symbols.NextNonEOLSymbol().ToString(); if ((reference.Length >= 2) && reference.StartsWith("\"") && reference.EndsWith("\"")) { return reference.Substring(1, reference.Length-2); } return reference; } symbols.PutBack(current); return null; }
public UnsignedType(IModule module, string name, Symbol type, ISymbolEnumerator symbols) : base(module, name) { Types? t = GetExactType(type); type.Assert(t.HasValue, "Unknown symbol for unsigned type!"); _type = t.Value; Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.OpenParentheses) { current.Assert((_type != Types.Counter64), "Ranges are not supported for Counter64 type!"); // our internal struct can only hold int64 values symbols.PutBack(current); _ranges = Lexer.DecodeRanges(symbols); current.Assert(!_ranges.IsSizeDeclaration, "SIZE keyword is not allowed for ranges of unsigned types!"); } else { symbols.PutBack(current); } }
/// <summary> /// Creates a <see cref="Sequence" /> instance. /// </summary> /// <param name="module">The module.</param> /// <param name="name">The name.</param> /// <param name="symbols">The enumerator.</param> public Sequence(IModule module, string name, ISymbolEnumerator symbols) : base(module, name) { // parse between ( ) Symbol temp = symbols.NextNonEOLSymbol(); int bracketSection = 0; temp.Expect(Symbol.OpenBracket); bracketSection++; while (bracketSection > 0) { temp = symbols.NextNonEOLSymbol(); if (temp == Symbol.OpenBracket) { bracketSection++; } else if (temp == Symbol.CloseBracket) { bracketSection--; } } }
private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.Syntax); /* * RFC2579 definition: * Syntax ::= -- Must be one of the following: * -- a base type (or its refinement), or * -- a BITS pseudo-type * type * | "BITS" "{" NamedBits "}" * * From section 3.5: * The data structure must be one of the alternatives defined * in the ObjectSyntax CHOICE or the BITS construct. Note * that this means that the SYNTAX clause of a Textual * Convention can not refer to a previously defined Textual * Convention. * * The SYNTAX clause of a TEXTUAL CONVENTION macro may be * sub-typed in the same way as the SYNTAX clause of an * OBJECT-TYPE macro. * * Therefore the possible values are (grouped by underlying type): * INTEGER, Integer32 * OCTET STRING, Opaque * OBJECT IDENTIFIER * IpAddress * Counter64 * Unsigned32, Counter32, Gauge32, TimeTicks * BITS * With appropriate sub-typing. */ return Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true); }
public MibModule(ISymbolEnumerator symbols) { if (symbols == null) { throw new ArgumentNullException("lexer"); } Symbol temp = symbols.NextNonEOLSymbol(); temp.AssertIsValidIdentifier(); _name = temp.ToString().ToUpperInvariant(); // all module names are uppercase temp = symbols.NextNonEOLSymbol(); temp.Expect(Symbol.Definitions); temp = symbols.NextNonEOLSymbol(); temp.Expect(Symbol.Assign); temp = symbols.NextSymbol(); temp.Expect(Symbol.Begin); temp = symbols.NextNonEOLSymbol(); if (temp == Symbol.Imports) { _imports = ParseDependents(symbols); } else if (temp == Symbol.Exports) { _exports = ParseExports(symbols); } else { symbols.PutBack(temp); } ParseEntities(symbols); }
public Exports(IModule module, ISymbolEnumerator s) { _module = module; Symbol previous = null; Symbol current; do { current = s.NextSymbol(); if (current == Symbol.EOL) { continue; } else if (((current == Symbol.Comma) || (current == Symbol.Semicolon)) && (previous != null)) { previous.AssertIsValidIdentifier(); _types.Add(previous.ToString()); } previous = current; } while (current != Symbol.Semicolon); }
public ObjectType(IModule module, SymbolList preAssignSymbols, ISymbolEnumerator symbols) : base(module, preAssignSymbols, symbols) { ParseProperties(preAssignSymbols); }
public static ValueRanges DecodeRanges(ISymbolEnumerator symbols) { ValueRanges result = new ValueRanges(); Symbol startSymbol = symbols.NextNonEOLSymbol(); Symbol current = startSymbol; current.Expect(Symbol.OpenParentheses); while (current != Symbol.CloseParentheses) { Symbol value1Symbol = symbols.NextNonEOLSymbol(); if ((value1Symbol == Symbol.Size) && !result.IsSizeDeclaration) { result.IsSizeDeclaration = true; symbols.NextNonEOLSymbol().Expect(Symbol.OpenParentheses); continue; } // check for valid number Int64? value1 = DecodeNumber(value1Symbol); if (!value1.HasValue) { value1Symbol.Assert(false, "Invalid range declaration!"); } // process next symbol ValueRange range; current = symbols.NextNonEOLSymbol(); if (current == Symbol.DoubleDot) { // its a continous range Symbol value2Symbol = symbols.NextNonEOLSymbol(); Int64? value2 = DecodeNumber(value2Symbol); value2Symbol.Assert(value2.HasValue && (value2.Value >= value1.Value), "Invalid range declaration!"); if (value2.Value == value1.Value) { range = new ValueRange(value1.Value, null); } else { range = new ValueRange(value1.Value, value2.Value); } current = symbols.NextNonEOLSymbol(); } else { // its a single number range = new ValueRange(value1.Value, null); } // validate range if (result.IsSizeDeclaration) { value1Symbol.Assert(range.Start >= 0, "Invalid range declaration! Size must be greater than 0"); } result.Add(range); // check next symbol current.Expect(Symbol.Pipe, Symbol.CloseParentheses); } if (result.IsSizeDeclaration) { current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseParentheses); } // validate ranges in between for (int i=0; i<result.Count; i++) { for (int k=i+1; k<result.Count; k++) { startSymbol.Assert(!result[i].IntersectsWith(result[k]), "Invalid range declaration! Overlapping of ranges!"); } } return result; }
public static ValueMap DecodeEnumerations(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenBracket); ValueMap map = new ValueMap(); do { current = symbols.NextNonEOLSymbol(); string identifier = current.ToString(); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenParentheses); current = symbols.NextNonEOLSymbol(); Int64 enumValue; if (Int64.TryParse(current.ToString(), out enumValue)) { try { // Have to include the number as it seems repeated identifiers are allowed ?? map.Add(enumValue, String.Format("{0}({1})", identifier, enumValue)); } catch (ArgumentException ex) { current.Assert(false, ex.Message); } } else { // Need to get "DefinedValue". } current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseParentheses); current = symbols.NextNonEOLSymbol(); } while (current == Symbol.Comma); current.Expect(Symbol.CloseBracket); return map; }
public static ITypeAssignment ParseBasicTypeDef(IModule module, string name, ISymbolEnumerator symbols, bool isMacroSyntax = false) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.Bits) { return new BitsType(module, name, symbols); } if (IntegerType.IsIntegerType(current)) { return new IntegerType(module, name, current, symbols); } if (UnsignedType.IsUnsignedType(current)) { return new UnsignedType(module, name, current, symbols); } if (current == Symbol.Opaque) { return new OpaqueType(module, name, symbols); } if (current == Symbol.IpAddress) { return new IpAddressType(module, name, symbols); } if (current == Symbol.TextualConvention) { return new TextualConvention(module, name, symbols); } if (current == Symbol.Octet) { Symbol next = symbols.NextNonEOLSymbol(); if (next == Symbol.String) { return new OctetStringType(module, name, symbols); } symbols.PutBack(next); } if (current == Symbol.Object) { Symbol next = symbols.NextNonEOLSymbol(); if (next == Symbol.Identifier) { return new ObjectIdentifierType(module, name, symbols); } symbols.PutBack(next); } if (current == Symbol.Sequence) { Symbol next = symbols.NextNonEOLSymbol(); if (next == Symbol.Of) { return new SequenceOf(module, name, symbols); } else { symbols.PutBack(next); return new Sequence(module, name, symbols); } } if (current == Symbol.Choice) { return new Choice(module, name, symbols); } return new TypeAssignment(module, name, current, symbols, isMacroSyntax); }
public static void ParseOidValue(ISymbolEnumerator symbols, out string parent, out uint value) { parent = null; value = 0; Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenBracket); Symbol previous = null; StringBuilder longParent = new StringBuilder(); current = symbols.NextNonEOLSymbol(); longParent.Append(current); while ((current = symbols.NextNonEOLSymbol()) != null) { bool succeeded; if (current == Symbol.OpenParentheses) { longParent.Append(current); current = symbols.NextNonEOLSymbol(); succeeded = UInt32.TryParse(current.ToString(), out value); current.Assert(succeeded, "not a decimal"); longParent.Append(current); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseParentheses); longParent.Append(current); continue; } if (current == Symbol.CloseBracket) { parent = longParent.ToString(); return; } succeeded = UInt32.TryParse(current.ToString(), out value); if (succeeded) { // numerical way while ((current = symbols.NextNonEOLSymbol()) != Symbol.CloseBracket) { longParent.Append(".").Append(value); succeeded = UInt32.TryParse(current.ToString(), out value); current.Assert(succeeded, "not a decimal"); } current.Expect(Symbol.CloseBracket); parent = longParent.ToString(); return; } longParent.Append("."); longParent.Append(current); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.OpenParentheses); longParent.Append(current); current = symbols.NextNonEOLSymbol(); succeeded = UInt32.TryParse(current.ToString(), out value); current.Assert(succeeded, "not a decimal"); longParent.Append(current); current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.CloseParentheses); longParent.Append(current); previous = current; } throw MibException.Create("end of file reached", previous); }
private static ITypeAssignment ParseSyntax(IModule module, ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.Syntax); return Lexer.ParseBasicTypeDef(module, String.Empty, symbols, isMacroSyntax: true); }
private static string ParseUnits(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.Units) { return symbols.NextNonEOLSymbol().ToString(); } else if (current != null) { symbols.PutBack(current); } return null; }
private static MaxAccess ParseAccess(ISymbolEnumerator symbols) { MaxAccess access = MaxAccess.notAccessible; Symbol current = symbols.NextNonEOLSymbol(); current.Expect(Symbol.MaxAccess, Symbol.Access); current = symbols.NextNonEOLSymbol(); switch (current.ToString()) { case "not-accessible": access = MaxAccess.notAccessible; break; case "accessible-for-notify": access = MaxAccess.accessibleForNotify; break; case "read-only": access = MaxAccess.readOnly; break; case "read-write": access = MaxAccess.readWrite; break; case "read-create": access = MaxAccess.readCreate; break; case "write-only": access = MaxAccess.readWrite; break; default: current.Assert(false, "Invalid/Unknown access"); break; } return access; }
private static string ParseDescription(ISymbolEnumerator symbols) { Symbol current = symbols.NextNonEOLSymbol(); if (current == Symbol.Description) { return symbols.NextNonEOLSymbol().ToString().Trim(new char[] { '"' }); } else if (current != null) { symbols.PutBack(current); } return null; }
public BitsType(IModule module, string name, ISymbolEnumerator symbols) : base(module, name) { _map = Lexer.DecodeEnumerations(symbols); }