~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/VBNetBinding/Parser/Parser.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//  Parser.cs
2
 
//
3
 
//  This file was derived from a file from #Develop. 
4
 
//
5
 
//  Copyright (C) 2001-2007 Andrea Paatz <andrea@icsharpcode.net>
6
 
// 
7
 
//  This program is free software; you can redistribute it and/or modify
8
 
//  it under the terms of the GNU General Public License as published by
9
 
//  the Free Software Foundation; either version 2 of the License, or
10
 
//  (at your option) any later version.
11
 
// 
12
 
//  This program is distributed in the hope that it will be useful,
13
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 
//  GNU General Public License for more details.
16
 
//  
17
 
//  You should have received a copy of the GNU General Public License
18
 
//  along with this program; if not, write to the Free Software
19
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
 
using System;
21
 
using System.Drawing;
22
 
using System.Collections.Generic;
23
 
using System.IO;
24
 
using MonoDevelop.Core;
25
 
using MonoDevelop.Projects.Parser;
26
 
using MonoDevelop.Projects;
27
 
using VBBinding.Parser.SharpDevelopTree;
28
 
 
29
 
using ICSharpCode.NRefactory;
30
 
using ICSharpCode.NRefactory.Parser;
31
 
 
32
 
 
33
 
namespace VBBinding.Parser
34
 
{
35
 
        public class TParser : MonoDevelop.Projects.Parser.IParser
36
 
        {
37
 
        
38
 
                public TParser() : base(){
39
 
                        //Console.WriteLine("Entering VB.NET parser");
40
 
                }//constructor
41
 
        
42
 
                ///<summary>IParser Interface</summary> 
43
 
                string[] lexerTags;
44
 
                public string[] LexerTags {
45
 
//// Alex: get accessor needed
46
 
                        get {
47
 
                                return lexerTags;
48
 
                        }
49
 
                        set {
50
 
                                lexerTags = value;
51
 
                        }
52
 
                }
53
 
                
54
 
                public IExpressionFinder CreateExpressionFinder (string file)
55
 
                {
56
 
                        return new ExpressionFinder ();
57
 
                }
58
 
 
59
 
                public bool CanParse (string fileName)
60
 
                {
61
 
                        return System.IO.Path.GetExtension (fileName).ToLower () == ".vb";
62
 
                }
63
 
 
64
 
                void RetrieveRegions(CompilationUnit cu, SpecialTracker tracker)
65
 
                {
66
 
                        for (int i = 0; i < tracker.CurrentSpecials.Count; ++i) {
67
 
                                PreprocessingDirective directive = tracker.CurrentSpecials[i] as PreprocessingDirective;
68
 
                                if (directive != null) {
69
 
                                        if (directive.Cmd.ToLower() == "#region") {
70
 
                                                int deep = 1; 
71
 
                                                for (int j = i + 1; j < tracker.CurrentSpecials.Count; ++j) {
72
 
                                                        PreprocessingDirective nextDirective = tracker.CurrentSpecials[j] as PreprocessingDirective;
73
 
                                                        if(nextDirective != null) {
74
 
                                                                switch (nextDirective.Cmd.ToLower()) {
75
 
                                                                        case "#region":
76
 
                                                                                ++deep;
77
 
                                                                                break;
78
 
                                                                        case "#end":
79
 
                                                                                if (nextDirective.Arg.ToLower() == "region") {
80
 
                                                                                        --deep;
81
 
                                                                                        if (deep == 0) {
82
 
                                                                                                cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim('"'), new DefaultRegion(new Point (directive.StartPosition.X, directive.StartPosition.Y) , new Point (nextDirective.EndPosition.X, nextDirective.EndPosition.Y))));
83
 
                                                                                                goto end;
84
 
                                                                                        }
85
 
                                                                                }
86
 
                                                                                break;
87
 
                                                                }
88
 
                                                        }
89
 
                                                }
90
 
                                                end: ;
91
 
                                        }
92
 
                                }
93
 
                        }
94
 
                }
95
 
                
96
 
                public ICompilationUnitBase Parse(string fileName)
97
 
                {
98
 
                        using (ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser (SupportedLanguage.VBNet, new StreamReader(fileName))) {
99
 
                                return Parse (p, fileName);
100
 
                        }
101
 
                }
102
 
                
103
 
                public ICompilationUnitBase Parse(string fileName, string fileContent)
104
 
                {
105
 
                        using (ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser (SupportedLanguage.VBNet, new StringReader(fileContent))) {
106
 
                                return Parse (p, fileName);
107
 
                        }
108
 
                }
109
 
                
110
 
                ICompilationUnit Parse (ICSharpCode.NRefactory.IParser p, string fileName)
111
 
                {
112
 
                        p.Parse();
113
 
                        
114
 
                        VBNetVisitor visitor = new VBNetVisitor();
115
 
                        visitor.VisitCompilationUnit(p.CompilationUnit, null);
116
 
                        visitor.Cu.ErrorsDuringCompile = p.Errors.Count > 0;
117
 
                        visitor.Cu.Tag = p.CompilationUnit;
118
 
                        RetrieveRegions(visitor.Cu, p.Lexer.SpecialTracker);
119
 
                        foreach (IClass c in visitor.Cu.Classes)
120
 
                                c.Region.FileName = fileName;
121
 
                        AddCommentTags(visitor.Cu, p.Lexer.TagComments);
122
 
                        return visitor.Cu;
123
 
                }
124
 
                
125
 
                void AddCommentTags(ICompilationUnit cu, List<TagComment> tagComments)
126
 
                {
127
 
                        foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments) {
128
 
                                DefaultRegion tagRegion = new DefaultRegion(tagComment.StartPosition.Y, tagComment.StartPosition.X);
129
 
                                MonoDevelop.Projects.Parser.Tag tag = new MonoDevelop.Projects.Parser.Tag(tagComment.Tag, tagRegion);
130
 
                                tag.CommentString = tagComment.CommentText;
131
 
                                cu.TagComments.Add(tag);
132
 
                        }
133
 
                }
134
 
                
135
 
                
136
 
                
137
 
                public LanguageItemCollection CtrlSpace (IParserContext parserContext, int caretLine, int caretColumn, string fileName)
138
 
                {
139
 
                        return new Resolver(parserContext).CtrlSpace (caretLine, caretColumn, fileName);
140
 
                }
141
 
                
142
 
                public ResolveResult Resolve (IParserContext parserContext, string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent)
143
 
                {
144
 
                        return new Resolver(parserContext).Resolve (expression, caretLineNumber, caretColumn, fileName, fileContent);
145
 
                }
146
 
                
147
 
                public LanguageItemCollection IsAsResolve (IParserContext parserContext, string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent)
148
 
                {
149
 
                        return new Resolver (parserContext).IsAsResolve (expression, caretLineNumber, caretColumn, fileName, fileContent);
150
 
                }
151
 
                
152
 
                public ILanguageItem ResolveIdentifier (IParserContext parserContext, string id, int caretLineNumber, int caretColumn, string fileName, string fileContent)
153
 
                {
154
 
                        return null;
155
 
                }
156
 
                
157
 
                ///////// IParser Interface END
158
 
        }
159
 
}