public EnumType(DEnum Enum, ISyntaxRegion td) : base(Enum, new PrimitiveType(DTokens.Int, 0), null, td) { }
public void EnumValue(DEnum mye) { var ev = new DEnumValue() { Location = la.Location, Description = GetComments(), Parent = mye }; if (laKind == Identifier && ( Lexer.CurrentPeekToken.Kind == Assign || Lexer.CurrentPeekToken.Kind == Comma || Lexer.CurrentPeekToken.Kind == CloseCurlyBrace)) { Step(); ev.Name = t.Value; ev.NameLocation = t.Location; } else { ev.Type = Type(); if (Expect(Identifier)) { ev.Name = t.Value; ev.NameLocation = t.Location; } else if (IsEOF) ev.NameHash = DTokens.IncompleteIdHash; } if (laKind == (Assign)) { Step(); ev.Initializer = AssignExpression(mye); } ev.EndLocation = t.EndLocation; ev.Description += CheckForPostSemicolonComment(); mye.Add(ev); }
public EnumType(DEnum Enum, AbstractType BaseType, ISyntaxRegion td) : base(Enum, BaseType, null, td) { }
private DEnum EnumDeclaration(INode Parent) { var mye = new DEnum() { Location = t.Location, Description = GetComments(), Parent=Parent }; ApplyAttributes(mye); if (laKind == (Identifier)) { Step (); mye.Name = t.Value; mye.NameLocation = t.Location; } else if (IsEOF) mye.NameHash = DTokens.IncompleteIdHash; // Enum inhertance type if (laKind == (Colon)) { Step(); mye.Type = Type(); } if (laKind == OpenCurlyBrace) EnumBody(mye); else Expect(Semicolon); mye.Description += CheckForPostSemicolonComment(); return mye; }
public void EnumBody(DEnum mye) { var OldPreviousComment = PreviousComment; PreviousComment = new StringBuilder(); mye.BlockStartLocation = la.Location; // While there are commas, loop through do { Step(); if (laKind == CloseCurlyBrace) break; EnumValue(mye); } while (laKind == Comma); Expect(CloseCurlyBrace); PreviousComment = OldPreviousComment; mye.EndLocation = t.EndLocation; }
public void EnumBody(DEnum mye) { var OldPreviousComment = PreviousComment; PreviousComment = new StringBuilder(); mye.BlockStartLocation = la.Location; // While there are commas, loop through do { Step(); if (laKind == CloseCurlyBrace) break; var ev = new DEnumValue() { Location = la.Location, Description = GetComments(), Parent = mye }; LastParsedObject = ev; if (laKind == Identifier && ( Lexer.CurrentPeekToken.Kind == Assign || Lexer.CurrentPeekToken.Kind == Comma || Lexer.CurrentPeekToken.Kind == CloseCurlyBrace)) { Step(); ev.Name = t.Value; ev.NameLocation = t.Location; } else { ev.Type = Type(); if (Expect(Identifier)) { ev.Name = t.Value; ev.NameLocation = t.Location; } else if (IsEOF) ExpectingNodeName = true; } if (laKind == (Assign)) { Step(); ev.Initializer = AssignExpression(); } ev.EndLocation = t.EndLocation; ev.Description += CheckForPostSemicolonComment(); mye.Add(ev); } while (laKind == Comma); Expect(CloseCurlyBrace); PreviousComment = OldPreviousComment; mye.EndLocation = t.EndLocation; }
public virtual void Visit(DEnum n) { VisitBlock(n); }
private INode[] EnumDeclaration(INode Parent) { Expect(Enum); var ret = new List<INode>(); var mye = new DEnum() { Location = t.Location, Description = GetComments(), Parent=Parent }; LastParsedObject = mye; ApplyAttributes(mye); if (laKind != Identifier && IsBasicType()) mye.Type = Type(); else if (laKind == Auto) { Step(); mye.Attributes.Add(new Modifier(Auto)); } if (laKind == (Identifier)) { // Normal enum identifier if (Lexer.CurrentPeekToken.Kind == (Assign) || // enum e = 1234; Lexer.CurrentPeekToken.Kind == (OpenCurlyBrace) || // enum e { A,B,C, } Lexer.CurrentPeekToken.Kind == (Semicolon) || // enum e; Lexer.CurrentPeekToken.Kind == Colon) { // enum e : uint {..} Step (); mye.Name = t.Value; mye.NameLocation = t.Location; } else { if (mye.Type == null) mye.Type = Type(); if (Expect(Identifier)) { mye.Name = t.Value; mye.NameLocation = t.Location; } } } else if (IsEOF) ExpectingNodeName = true; if (IsDeclaratorSuffix) { DeclaratorSuffixes(mye); } // Enum inhertance type if (laKind == (Colon)) { Step(); mye.Type = Type(); } // Variables with 'enum' as base type if (laKind == (Assign) || laKind == (Semicolon)) { do { var enumVar = new DVariable(); LastParsedObject = enumVar; enumVar.AssignFrom(mye); enumVar.Attributes.Add(new Modifier(Enum)); if (mye.Type != null) enumVar.Type = mye.Type; else enumVar.Type = new DTokenDeclaration(Enum); if (laKind == (Comma)) { Step(); Expect(Identifier); enumVar.Name = t.Value; enumVar.NameLocation = t.Location; } if (laKind == (Assign)) { //Step(); -- expected by initializer enumVar.Initializer = Initializer(); // Seems to be specified wrongly - theoretically there must be an AssignExpression(); } enumVar.EndLocation = t.Location; ret.Add(enumVar); } while (laKind == Comma); Expect(Semicolon); } else if (laKind == OpenCurlyBrace) // Normal enum block { EnumBody(mye); ret.Add(mye); } mye.Description += CheckForPostSemicolonComment(); return ret.ToArray(); }
private INode[] EnumDeclaration() { Expect(Enum); var ret = new List<INode>(); var mye = new DEnum() { StartLocation = t.Location, Description = GetComments() }; LastParsedObject = mye; ApplyAttributes(mye); if (IsBasicType() && laKind != Identifier) mye.Type = Type(); else if (laKind == Auto) { Step(); mye.Attributes.Add(new DAttribute(Auto)); } if (laKind == (Identifier)) { // Normal enum identifier if (Lexer.CurrentPeekToken.Kind == (Assign) || Lexer.CurrentPeekToken.Kind == (OpenCurlyBrace) || Lexer.CurrentPeekToken.Kind == (Semicolon) || Lexer.CurrentPeekToken.Kind == Colon) { Step(); mye.Name = t.Value; } else { mye.Type = Type(); Expect(Identifier); mye.Name = t.Value; } } // Enum inhertance type if (laKind == (Colon)) { Step(); mye.Type = Type(); } // Variables with 'enum' as base type if (laKind == (Assign) || laKind == (Semicolon)) { another_enumvalue: var enumVar = new DVariable(); LastParsedObject = enumVar; enumVar.AssignFrom(mye); enumVar.Attributes.Add(new DAttribute(Enum)); if (mye.Type != null) enumVar.Type = mye.Type; else enumVar.Type = new DTokenDeclaration(Enum); if (laKind == (Comma)) { Step(); Expect(Identifier); enumVar.Name = t.Value; } if (laKind == (Assign)) { Step(); enumVar.Initializer = AssignExpression(); } enumVar.EndLocation = t.Location; ret.Add(enumVar); // If there are more than one definitions, loop back if (laKind == (Comma)) goto another_enumvalue; Expect(Semicolon); } else { // Normal enum block Expect(OpenCurlyBrace); var OldPreviousComment = PreviousComment; PreviousComment = ""; mye.BlockStartLocation = t.Location; bool init = true; // While there are commas, loop through while ((init && laKind != (Comma)) || laKind == (Comma)) { if (!init) Step(); init = false; if (laKind == (CloseCurlyBrace)) break; var ev = new DEnumValue() { StartLocation = t.Location, Description = GetComments() }; LastParsedObject = ev; if (laKind == (Identifier) && (Lexer.CurrentPeekToken.Kind == (Assign) || Lexer.CurrentPeekToken.Kind == (Comma) || Lexer.CurrentPeekToken.Kind == (CloseCurlyBrace))) { Step(); ev.Name = t.Value; } else { ev.Type = Type(); Expect(Identifier); ev.Name = t.Value; } if (laKind == (Assign)) { Step(); ev.Initializer = AssignExpression(); } ev.EndLocation = t.EndLocation; ev.Description += CheckForPostSemicolonComment(); mye.Add(ev); } Expect(CloseCurlyBrace); PreviousComment = OldPreviousComment; mye.EndLocation = t.EndLocation; // Important: Add the enum block, whereas it CAN be unnamed, to the return array ret.Add(mye); } mye.Description += CheckForPostSemicolonComment(); return ret.ToArray(); }
private INode[] EnumDeclaration(INode Parent) { Expect(Enum); var ret = new List<INode>(); var mye = new DEnum() { Location = t.Location, Description = GetComments(), Parent=Parent }; LastParsedObject = mye; ApplyAttributes(mye); if (IsBasicType() && laKind != Identifier) mye.Type = Type(); else if (laKind == Auto) { Step(); mye.Attributes.Add(new DAttribute(Auto)); } if (laKind == (Identifier)) { // Normal enum identifier if (Lexer.CurrentPeekToken.Kind == (Assign) || // enum e = 1234; Lexer.CurrentPeekToken.Kind == (OpenCurlyBrace) || // enum e { A,B,C, } Lexer.CurrentPeekToken.Kind == (Semicolon) || // enum e; Lexer.CurrentPeekToken.Kind == Colon) // enum e : uint {..} { Step(); mye.Name = t.Value; mye.NameLocation = t.Location; } else { if(mye.Type == null) mye.Type = Type(); if (Expect(Identifier)) { mye.Name = t.Value; mye.NameLocation = t.Location; } } } if (IsDeclaratorSuffix) { var _unused = new List<INode>(); var bt2=DeclaratorSuffixes(out mye.TemplateParameters, out _unused, mye.Attributes); if (bt2 != null) { bt2.InnerDeclaration = mye.Type; mye.Type = bt2; } } // Enum inhertance type if (laKind == (Colon)) { Step(); mye.Type = Type(); } // Variables with 'enum' as base type if (laKind == (Assign) || laKind == (Semicolon)) { do { var enumVar = new DVariable(); LastParsedObject = enumVar; enumVar.AssignFrom(mye); enumVar.Attributes.Add(new DAttribute(Enum)); if (mye.Type != null) enumVar.Type = mye.Type; else enumVar.Type = new DTokenDeclaration(Enum); if (laKind == (Comma)) { Step(); Expect(Identifier); enumVar.Name = t.Value; enumVar.NameLocation = t.Location; } if (laKind == (Assign)) { //Step(); -- expected by initializer enumVar.Initializer = Initializer(); // Seems to be specified wrongly - theoretically there must be an AssignExpression(); } enumVar.EndLocation = t.Location; ret.Add(enumVar); } while (laKind == Comma); Expect(Semicolon); } else { // Normal enum block Expect(OpenCurlyBrace); var OldPreviousComment = PreviousComment; PreviousComment = ""; mye.BlockStartLocation = t.Location; bool init = true; // While there are commas, loop through while ((init && laKind != (Comma)) || laKind == (Comma)) { if (!init) Step(); init = false; if (laKind == CloseCurlyBrace) break; var ev = new DEnumValue() { Location = la.Location, Description = GetComments(), Parent = mye }; LastParsedObject = ev; if (laKind == Identifier && ( Lexer.CurrentPeekToken.Kind == Assign || Lexer.CurrentPeekToken.Kind == Comma || Lexer.CurrentPeekToken.Kind == CloseCurlyBrace)) { Step(); ev.Name = t.Value; ev.NameLocation = t.Location; } else { ev.Type = Type(); Expect(Identifier); ev.Name = t.Value; ev.NameLocation = t.Location; } if (laKind == (Assign)) { Step(); ev.Initializer = AssignExpression(); } ev.EndLocation = t.EndLocation; ev.Description += CheckForPostSemicolonComment(); mye.Add(ev); } Expect(CloseCurlyBrace); PreviousComment = OldPreviousComment; mye.EndLocation = t.EndLocation; // Important: Add the enum block, whereas it CAN be unnamed, to the return array ret.Add(mye); } mye.Description += CheckForPostSemicolonComment(); return ret.ToArray(); }
/*public override void VisitAttributeMetaDeclaration(AttributeMetaDeclaration md) { base.Visit(md); } public override void VisitMetaDeclarationBlock(MetaDeclarationBlock metaDeclarationBlock) { base.Visit(metaDeclarationBlock); } public override void VisitAttributeMetaDeclarationBlock(AttributeMetaDeclarationBlock attributeMetaDeclarationBlock) { base.Visit(attributeMetaDeclarationBlock); } public override void VisitAttributeMetaDeclarationSection(AttributeMetaDeclarationSection attributeMetaDeclarationSection) { base.Visit(attributeMetaDeclarationSection); } public override void Visit(ElseMetaDeclaration elseMetaDeclaration) { base.Visit(elseMetaDeclaration); } public override void Visit(ElseMetaDeclarationBlock elseMetaDeclarationBlock) { base.Visit(elseMetaDeclarationBlock); }*/ #endregion public override void Visit(DEnum n) { base.Visit(n); }
public override void Visit(DEnum n) { PushBlock(n); }
public override void Visit(DEnum n) { l.Add(new FoldingRegion(GetBlockBodyRegion(n), FoldType.Type)); base.Visit(n); }
/// <returns>Either CurrentScope, a BlockStatement object that is associated with the parent method or a complete new DModule object</returns> public static object FindCurrentCaretContext(string code, IBlockNode CurrentScope, int caretOffset, CodeLocation caretLocation, out ParserTrackerVariables TrackerVariables) { bool ParseDecl = false; int blockStart = 0; var blockStartLocation = CurrentScope.BlockStartLocation; if (CurrentScope is DMethod) { var block = (CurrentScope as DMethod).GetSubBlockAt(caretLocation); if (block != null) blockStart = DocumentHelper.LocationToOffset(code, blockStartLocation = block.Location); else return FindCurrentCaretContext(code, CurrentScope.Parent as IBlockNode, caretOffset, caretLocation, out TrackerVariables); } else if (CurrentScope != null) { if (CurrentScope.BlockStartLocation.IsEmpty || caretLocation < CurrentScope.BlockStartLocation && caretLocation > CurrentScope.Location) { ParseDecl = true; blockStart = DocumentHelper.LocationToOffset(code, blockStartLocation = CurrentScope.Location); } else blockStart = DocumentHelper.LocationToOffset(code, CurrentScope.BlockStartLocation); } if (blockStart >= 0 && caretOffset - blockStart > 0) { var codeToParse = code.Substring(blockStart, caretOffset - blockStart); var sr = new StringReader(codeToParse); var psr = DParser.Create(sr); /* Deadly important! For correct resolution behaviour, * it is required to set the parser virtually to the blockStart position, * so that everything using the returned object is always related to * the original code file, not our code extraction! */ psr.Lexer.SetInitialLocation(blockStartLocation); object ret = null; if (CurrentScope == null || CurrentScope is IAbstractSyntaxTree) ret = psr.Parse(); else if (CurrentScope is DMethod) { psr.Step(); ret = psr.BlockStatement(CurrentScope); } else if (CurrentScope is DModule) ret = psr.Root(); else { psr.Step(); if (ParseDecl) { var ret2 = psr.Declaration(CurrentScope); if (ret2 != null && ret2.Length > 0) ret = ret2[0]; } else { DBlockNode bn = null; if (CurrentScope is DClassLike) { var t = new DClassLike((CurrentScope as DClassLike).ClassType); t.AssignFrom(CurrentScope); bn = t; } else if (CurrentScope is DEnum) { var t = new DEnum(); t.AssignFrom(CurrentScope); bn = t; } bn.Clear(); psr.ClassBody(bn); ret = bn; } } TrackerVariables = psr.TrackerVariables; sr.Close(); return ret; } TrackerVariables = null; return null; }
public static ISyntaxRegion FindCurrentCaretContext(IEditorData editor, out ParserTrackerVariables trackerVariables, ref IBlockNode currentScope, out IStatement currentStatement) { if(currentScope == null) currentScope = DResolver.SearchBlockAt (editor.SyntaxTree, editor.CaretLocation, out currentStatement); if (currentScope == null) { trackerVariables = null; currentStatement = null; return null; } bool ParseDecl = false; int blockStart = 0; var blockStartLocation = currentScope != null ? currentScope.BlockStartLocation : editor.CaretLocation; if (currentScope is DMethod) { var block = (currentScope as DMethod).GetSubBlockAt(editor.CaretLocation); if (block != null) blockStart = DocumentHelper.GetOffsetByRelativeLocation (editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, blockStartLocation = block.Location); else { currentScope = currentScope.Parent as IBlockNode; return FindCurrentCaretContext (editor, out trackerVariables, ref currentScope, out currentStatement); } } else if (currentScope != null) { if (currentScope.BlockStartLocation.IsEmpty || (editor.CaretLocation < currentScope.BlockStartLocation && editor.CaretLocation > currentScope.Location)) { ParseDecl = true; blockStart = DocumentHelper.GetOffsetByRelativeLocation(editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, blockStartLocation = currentScope.Location); } else blockStart = DocumentHelper.GetOffsetByRelativeLocation(editor.ModuleCode, editor.CaretLocation, editor.CaretOffset, currentScope.BlockStartLocation); } if (blockStart >= 0 && editor.CaretOffset - blockStart > 0) using (var sr = new Misc.StringView(editor.ModuleCode, blockStart, editor.CaretOffset - blockStart)) { var psr = DParser.Create(sr); /* Deadly important! For correct resolution behaviour, * it is required to set the parser virtually to the blockStart position, * so that everything using the returned object is always related to * the original code file, not our code extraction! */ psr.Lexer.SetInitialLocation(blockStartLocation); ISyntaxRegion ret = null; if (currentScope == null) ret = psr.Parse(); else if (currentScope is DMethod) { psr.Step(); var dm = currentScope as DMethod; dm.Clear(); if ((dm.SpecialType & DMethod.MethodType.Lambda) != 0 && psr.Lexer.LookAhead.Kind != DTokens.OpenCurlyBrace) { psr.LambdaSingleStatementBody (dm); ret = dm.Body; } else { var methodRegion = DTokens.Body; if (dm.In != null && blockStartLocation == dm.In.Location) methodRegion = DTokens.In; if (dm.Out != null && blockStartLocation == dm.Out.Location) methodRegion = DTokens.Out; var newBlock = psr.BlockStatement (currentScope); ret = newBlock; switch (methodRegion) { case DTokens.Body: newBlock.EndLocation = dm.Body.EndLocation; dm.Body = newBlock; break; case DTokens.In: newBlock.EndLocation = dm.In.EndLocation; dm.In = newBlock; break; case DTokens.Out: newBlock.EndLocation = dm.Out.EndLocation; dm.Out = newBlock; break; } } } else if (currentScope is DModule) ret = psr.Root(); else { psr.Step(); if (ParseDecl) { var ret2 = psr.Declaration(currentScope); if (ret2 != null && ret2.Length > 0) ret = ret2[0]; } else if (currentScope is DClassLike) { var t = new DClassLike((currentScope as DClassLike).ClassType); t.AssignFrom(currentScope); t.Clear(); psr.ClassBody(t); ret = t; } else if (currentScope is DEnum) { var t = new DEnum(); t.AssignFrom(currentScope); t.Clear(); psr.EnumBody(t); ret = t; } } currentScope = DResolver.SearchBlockAt (currentScope, psr.Lexer.CurrentToken != null ? psr.Lexer.CurrentToken.EndLocation : editor.CaretLocation, out currentStatement); trackerVariables = psr.TrackerVariables; return ret; } trackerVariables = null; currentStatement = null; return null; }