public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req) { Babel.Source source = (Babel.Source)this.GetSource(req.FileName); bool yyparseResult = false; // req.DirtySpan seems to be set even though no changes have occurred // source.IsDirty also behaves strangely // might be possible to use source.ChangeCount to sync instead if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex || req.DirtySpan.iStartLine != req.DirtySpan.iEndLine) { ErrorHandler handler = new ErrorHandler(); Scanner scanner = new Scanner(); // string interface Parser parser = new Parser(); // use noarg constructor parser.scanner = scanner; scanner.Handler = handler; parser.SetHandler(handler); scanner.SetSource(req.Text, 0); parser.MBWInit(req); yyparseResult = parser.Parse(); // store the parse results // source.ParseResult = aast; source.ParseResult = null; source.Braces = parser.Braces; // for the time being, just pull errors back from the error handler if (handler.ErrNum > 0) { foreach (Babel.Parser.Error error in handler.SortedErrorList()) { TextSpan span = new TextSpan(); span.iStartLine = span.iEndLine = error.line - 1; span.iStartIndex = error.column; span.iEndIndex = error.column + error.length; req.Sink.AddError(req.FileName, error.message, span, Severity.Error); } } } switch (req.Reason) { case ParseReason.Check: case ParseReason.HighlightBraces: case ParseReason.MatchBraces: case ParseReason.MemberSelectAndHighlightBraces: // send matches to sink // this should (probably?) be filtered on req.Line / col if (source.Braces != null) { foreach (TextSpan[] brace in source.Braces) { if (brace.Length == 2) req.Sink.MatchPair(brace[0], brace[1], 1); else if (brace.Length >= 3) req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1); } } break; default: break; } return new AuthoringScope(req.Text); }
public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource (ParseRequest request) { var wrapper = new ParseRequestWrapper(request); wrapper.Scanning(); return new AuthoringScopeWrapper(); }
}//OnIdle public override AuthoringScope ParseSource( ParseRequest req ) { var dirty = (req.DirtySpan.iStartLine != req.DirtySpan.iEndLine) || (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex); BeeSource src = null; if( (dirty || (req.Reason == ParseReason.None)) || (req.Reason == ParseReason.Check) ) { src = ((BeeSource)GetSource( req.FileName )); try { } catch( ParseError err ) { req.Sink.AddError( req.FileName, err.Message, new TextSpan() { iStartLine = err.Lnum, iStartIndex = err.At, iEndLine = err.Lnum, iEndIndex = err.End }, Severity.Fatal ); } catch { } } return new BeeScope( src ); }//ParseSource
public BooScope(CompiledProject compiledProject, BooSource source, ParseRequest parseRequest, ParseRequestProcessor parseRequestProcessor) { this.source = source; declarations = new DeclarationFinder(compiledProject, source, parseRequest.FileName); this.parseRequest = parseRequest; this.parseRequestProcessor = parseRequestProcessor; }
public NSAuthoringScope(ParseRequest req, string dirtyFile, string project) : base() { m_sink = req.Sink; m_projectfile = project; m_dirtyname = dirtyFile; m_filename = req.FileName; }
public override AuthoringScope ParseSource(ParseRequest req) { SassParser parser = new SassParser(); Source source = (Source)this.GetSource(req.FileName); if (req.Sink.BraceMatching) { if (req.Reason == ParseReason.MatchBraces) { foreach (TextSpan[] brace in parser.Braces) { req.Sink.MatchPair(brace[0], brace[1], 1); } } } return new SassParserAuthoringScope(); }
public override AuthoringScope ParseSource(ParseRequest req) { if (req == null) { return null; } var scope = new CQLAuthoringScope(); req.Scope = scope; if (req.Reason == ParseReason.Check) { } if (m_scanner != null && req.Reason == ParseReason.MemberSelect || req.Reason == ParseReason.MemberSelectAndHighlightBraces && req.TokenInfo != null) { var token = m_scanner.GetToken(req.TokenInfo.Token); if (token != null) { if (token.Type == 4) // [ { scope.AddDeclaration(new CQLDeclaration("Encounter", 0, "An encounter with the patient")); scope.AddDeclaration(new CQLDeclaration("Procedure", 0, "A procedure")); scope.AddDeclaration(new CQLDeclaration("Medication", 0, "A medication")); } if (token.Type == 3) // , { scope.AddDeclaration(new CQLDeclaration("Performed", 0, "An action performed")); scope.AddDeclaration(new CQLDeclaration("Proposed", 0, "An action performed")); scope.AddDeclaration(new CQLDeclaration("Ordered", 0, "An action performed")); } if (token.Type == 5) // : { scope.AddDeclaration(new CQLDeclaration("\"Inpatient\"", 0, "Inpatient encounter")); scope.AddDeclaration(new CQLDeclaration("\"Outpatient\"", 0, "Outpatient encounter")); scope.AddDeclaration(new CQLDeclaration("\"Face-to-face Interaction\"", 0, "Face-to-face interaction")); } } } return scope; }
public void CreateScopeTest() { Assert.IsNull(ConsoleAuthoringScope.CreateScope(null)); ParseRequest request = new ParseRequest(false); request.Reason = ParseReason.None; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.MemberSelect; Assert.IsNotNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.HighlightBraces; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.MemberSelectAndHighlightBraces; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.MatchBraces; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.Check; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.CompleteWord; Assert.IsNotNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.DisplayMemberList; Assert.IsNotNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.QuickInfo; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.MethodTip; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.Autos; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.CodeSpan; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); request.Reason = ParseReason.Goto; Assert.IsNull(ConsoleAuthoringScope.CreateScope(request)); }
public override AuthoringScope ParseSource(ParseRequest req) { XSharpAuthoringScope scope = new XSharpAuthoringScope(); if (req.Reason == ParseReason.Check || req.Reason == ParseReason.None) { // Parse the entire source as given in req.Text. Store results in the XSharpAuthoringScope object. } else if (req.Reason == ParseReason.DisplayMemberList) { // Parse the line specified in req.Line for the two tokens just before req.Col to get the identifier and the member connector symbol. // Find members of the identifer in the parse tree and store the list of members in the Declarations class. } else if (req.Reason == ParseReason.MethodTip) { // Parse the line specified in req.Line for the token just before req.Col to obtain the name of the method. // Find all method signatures with the same name in the existing parse tree and store the list of signatures in the Methods class. } // continue for the rest of the supported ParseReason values. return scope; }
public override AuthoringScope ParseSource(ParseRequest req) { Core.FStarParser parser = new Core.FStarParser(); var result = new TestAuthoringScope(); var tokens = new List<TokenInfo>(); if (req.Sink.BraceMatching || ParseReason.MatchBraces == req.Reason || ParseReason.HighlightBraces == req.Reason) { var scanner = GetScanner(null); scanner.SetSource(req.Text, 0); var line = 0; var col = 0; req.View.GetCaretPos(out line, out col); (scanner as VisualFStar.Core.FStarScanner).MatchPair(req.Sink, req.Text, line, col); } else parser.Parse(req); if (ParseReason.Check == req.Reason) { Console.WriteLine("!!!!"); } return result; }
/// <summary> /// Triggers the parse. /// </summary> /// <param name="request">The request.</param> /// <param name="yyresult">if set to <c>true</c> [yyresult].</param> /// <returns></returns> private static LuaParser TriggerParse(ParseRequest request, out bool yyresult) { LuaParser parser = CreateParser(request); yyresult = parser.Parse(); return parser; }
/// <summary> /// Gets the last word. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> private static string GetLastWord(ParseRequest request) { string line; request.View.GetTextStream(request.Line, 0, request.Line, request.TokenInfo.EndIndex, out line); if (line != null) { // Find the delimiter before the last word int lastDelimiterIndex = line.LastIndexOfAny(lastWordDelimiters); // Get the last word before the caret return lastDelimiterIndex != -1 ? line.Substring(lastDelimiterIndex + 1) : line; } return String.Empty; }
/// <summary> /// Creates the parser. /// </summary> /// <param name="request">The request.</param> /// <returns></returns> private static LuaParser CreateParser(ParseRequest request) { // Create ErrorHandler for scanner var handler = new ParaEngine.Tools.Lua.Parser.ErrorHandler(); // Create scanner and parser LuaScanner scanner = new ParaEngine.Tools.Lua.Lexer.Scanner(); LuaParser parser = new LuaParser(); // Set the error handler for the scanner scanner.Handler = handler; // Associate the scanner with the parser parser.scanner = scanner; // Initialize with the request (can be null) parser.Request = request; // If the parser is created for a request, automatically set the source from the request if (request != null) scanner.SetSource(request.Text, 0); // Return the parser return parser; }
/// <summary> /// Processes a Parse request. /// </summary> /// <param name="request">The request to process.</param> /// <returns>An AuthoringScope containing the declarations and other information.</returns> public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest request) { Trace.WriteLine(request.Reason); authoringScope.Clear(); if (request.ShouldParse()) { // Make sure we are processing hidden regions request.Sink.ProcessHiddenRegions = true; // Create a parser for the request, and execute parsing... bool successfulParse; LuaParser parser = TriggerParse(request, out successfulParse); InitializeFileCodeModel(parser.Chunk); if (successfulParse) { RefreshDeclarationsForRequest(request, parser, true); } if (request.NeedsDeclarations()) { AddDeclarationProvidersToScope(request); if (request.NeedsQualifiedName()) { authoringScope.SetQualifiedName(GetLastWord(request)); } } } else { if(request.Reason == ParseReason.QuickInfo) { // TODO: mouse over a text to display some info. } } // Return authoring scope return authoringScope; }
public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req) { Source source = (Source) this.GetSource(req.FileName); bool yyparseResult = false; #if GARRETT System.IO.StreamWriter myStream = null; if (req.View != null) { myStream = new System.IO.StreamWriter("E:/Users/Garrett/Documents/Projects/ShaderSense/myOutput.txt"); Console.SetError(myStream); } #endif // req.DirtySpan seems to be set even though no changes have occurred // source.IsDirty also behaves strangely // might be possible to use source.ChangeCount to sync instead if (req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex || req.DirtySpan.iStartLine != req.DirtySpan.iEndLine || source.IsDirty) { Babel.Parser.ErrorHandler handler = new Babel.Parser.ErrorHandler(); Babel.Lexer.Scanner scanner = new Babel.Lexer.Scanner(); // string interface Parser.Parser parser = new Parser.Parser(); // use noarg constructor parser.scanner = scanner; scanner.Handler = handler; parser.SetHandler(handler); scanner.SetSource(req.Text, 0); parser.MBWInit(req); if (parser.shouldAddDeclarations()) Parser.Parser.clearDeclarations(); // Hack to purge old parser declarations //Parser.Parser.PrepareParse(source.GetDocumentSpan(), source); parser.PrepareParse(source.GetDocumentSpan(), source); yyparseResult = parser.Parse(); ((HLSLSource)source).GatherIncludes(); // store the parse results // source.ParseResult = aast; source.ParseResult = null; source.Braces = parser.Braces; // for the time being, just pull errors back from the error handler if (handler.ErrNum > 0) { foreach (Babel.Parser.Error error in handler.SortedErrorList()) { TextSpan span = new TextSpan(); span.iStartLine = span.iEndLine = error.line - 1; span.iStartIndex = error.column; span.iEndIndex = error.column + error.length; req.Sink.AddError(req.FileName, error.message, span, Severity.Error); } } } switch (req.Reason) { case ParseReason.Check: case ParseReason.HighlightBraces: case ParseReason.MatchBraces: case ParseReason.MemberSelectAndHighlightBraces: // send matches to sink // this should (probably?) be filtered on req.Line / col if (source.Braces != null) { foreach (TextSpan[] brace in source.Braces) { if (brace.Length == 2) req.Sink.MatchPair(brace[0], brace[1], 1); else if (brace.Length >= 3) req.Sink.MatchTriple(brace[0], brace[1], brace[2], 1); } } break; default: break; } #if GARRETT if(myStream != null) myStream.Close(); #endif // return new AuthoringScope(source.ParseResult); return new HLSLAuthoringScope(source); }
internal void HandleParseResponse(ParseRequest req) { try { ReportErrors(req.Sink.Errors); } catch (Exception e) { CCITracing.Trace("HandleParseResponse exception: " + e.Message); } }
internal void HandleMethodTipResponse(ParseRequest req) { try { CallInfo call = req.Sink.MethodCalls.GetCurrentMethodCall(); if (call == null) goto fail; IdentifierList names = call.names; if (names.Length == 0) goto fail; Identifier name = names[names.Length-1]; SourceContext ctx = name.SourceContext; Methods methods = req.Scope.GetMethods(ctx.StartLine-1, ctx.StartColumn-1, name); if (methods == null) goto fail; TextSpan span = new TextSpan(); span.iStartLine = ctx.StartLine-1; span.iStartIndex = ctx.StartColumn-1; span.iEndLine = ctx.EndLine-1; span.iEndIndex = ctx.EndColumn-1; int currentParameter = call.currentParameter; this.methodData.Refresh(req.View, methods, currentParameter, span ); return; fail: DismissMethodTip(); } catch (Exception e) { CCITracing.Trace("HandleMethodTipResponse exception: " + e.Message); } }
/// <summary> /// This method parses the source code based on the specified ParseRequest object. /// We don't need implement any logic here. /// </summary> /// <param name="req">The <see cref="ParseRequest"/> describes how to parse the source file.</param> /// <returns>If successful, returns an <see cref="AuthoringScope"/> object; otherwise, returns a null value.</returns> public override AuthoringScope ParseSource(ParseRequest req) { throw new NotImplementedException(); }
/// <summary> /// Adds the static declaration providers to scope. /// </summary> /// <param name="request">The request.</param> private void AddStaticDeclarationProvidersToScope(ParseRequest request) { if (request.Reason == ParseReason.CompleteWord) { authoringScope.AddProvider(keywordDeclarationProvider); authoringScope.AddProvider(snippetDeclarationProvider); } authoringScope.AddProvider(xmlDeclarationProvider); }
/// <summary> /// Adds the declaration providers to scope. /// </summary> /// <param name="request">The request.</param> private void AddDeclarationProvidersToScope(ParseRequest request) { AddStaticDeclarationProvidersToScope(request); AddDynamicDeclarationProvidersToScope(request); }
public BooScope(CompiledProject compiledProject, BooSource source, ParseRequest parseRequest, Methods methods, ParseRequestProcessor parseRequestProcessor) : this(compiledProject, source, parseRequest, parseRequestProcessor) { this.methods = methods; }
/// <summary> /// Adds the dynamic declaration providers to scope. /// </summary> /// <param name="request">The request.</param> private void AddDynamicDeclarationProvidersToScope(ParseRequest request) { AddTableProvidersFromDictionary(luaFileDeclarationProviders); AddTableProvidersFromDictionary(frameXmlDeclarationProviders); }
private void CheckParseRequest(ParseRequest req) { try { var lexer = new AphidLexer(req.Text); var parser = new AphidParser(lexer.GetTokens()); parser.Parse(); } catch (AphidParserException e) { var lineCol = TokenHelper.GetLineCol(req.Text, e.UnexpectedToken.Index); var span = new TextSpan() { iStartLine = lineCol.Item1, iEndLine = lineCol.Item1, iStartIndex = lineCol.Item2, iEndIndex = lineCol.Item2 + (e.UnexpectedToken.Lexeme != null ? e.UnexpectedToken.Lexeme.Length : 0) }; var msg = string.Format( "Unexpected {0}: {1}, expected {2}", e.UnexpectedToken.TokenType.ToString(), e.UnexpectedToken.Lexeme, e.ExpectedToken); req.Sink.AddError(req.FileName, msg, span, Severity.Error); } }
private void RefreshDeclarationsForRequest(ParseRequest request, LuaParser parser, bool addLocals) { luaFileDeclarationProviders[request.FileName] = new TableDeclarationProvider(); // Create an AST declaration parser to add the declarations from the parsed chunk var declarationParser = new AstDeclarationParser(luaFileDeclarationProviders[request.FileName]); // Parse the AST and add the declaarations if(addLocals) declarationParser.AddChunk(parser.Chunk, request.Line, request.Col); else declarationParser.AddChunk(parser.Chunk); }
public override AuthoringScope ParseSource(ParseRequest req) { Debug.WriteLine("Parse reason: {0}", req.Reason); var scope = new AphidAuthoringScope(); //scope.Identifiers = GetTokens(req.Text) // .Where(x => x.TokenType == AphidTokenType.Identifier) // .Select(x => x.Lexeme) // .Distinct() // .ToArray(); switch (req.Reason) { case ParseReason.QuickInfo: break; case ParseReason.MemberSelect: break; case ParseReason.DisplayMemberList: break; case ParseReason.CompleteWord: break; case ParseReason.MatchBraces: case ParseReason.MemberSelectAndHighlightBraces: case ParseReason.HighlightBraces: var braces = TokenHelper.GetBraces( req.Text, req.Line, req.Col - 1); if (braces != null) { req.Sink.MatchPair(CreateSpan(braces[0][0], braces[0][1]), CreateSpan(braces[1][0], braces[1][1]), 1); } var index = TokenHelper.GetIndex(req.Text, req.Line, req.Col - 1); var str = req.Text.Substring(index); var tokens = new AphidLexer(str).GetAllTokens(); var depth = 1; var rightBraceIndex = -1; for (int i = 1; i < tokens.Count; i++) { switch (tokens[i].TokenType) { case AphidTokenType.LeftBrace: depth++; break; case AphidTokenType.RightBrace: depth--; break; } if (depth == 0) { rightBraceIndex = index + tokens[i].Index; break; } } if (rightBraceIndex != -1) { var rightLineCol = TokenHelper.GetLineCol(req.Text, rightBraceIndex); req.Sink.MatchPair(CreateSpan(req.Line, req.Col - 1), CreateSpan(rightLineCol.Item1, rightLineCol.Item2), 1); } break; case ParseReason.Check: CheckParseRequest(req); break; default: break; } return scope; }
internal void HandleCompletionResponse(ParseRequest req) { try { CCITracing.Trace("Source::HandleCompletionResponse"); Declarations decls = req.Scope.GetDeclarations(req.View, req.Line, req.Col, req.TokenInfo); if (decls.GetCount()>0) { this.completionSet.Init(req.View, decls, completeWord ); } } catch (Exception e) { CCITracing.Trace("HandleCompletionResponse exception: " + e.Message); } }
public override AuthoringScope ParseSource(ParseRequest req) { return null; }
internal void HandleMatchBracesResponse(ParseRequest req) { try { CCITracing.Trace("HandleMatchBracesResponse"); if (req.Sink.Spans.Count == 0) return; //transform spanList into an array of spans TextSpan[] spans = (TextSpan[])req.Sink.Spans.ToArray(typeof(TextSpan)); for( int index = 0, n = spans.Length; index < n; index++) { TextSpanHelper.TextSpanNormalize(ref spans[index], this.textLines); } //highlight req.View.HighlightMatchingBrace( (uint)0, (uint)spans.Length, spans ); //try to show the matching line in the statusbar if (this.statusBar != null && this.service.Preferences.EnableShowMatchingBrace) { TextSpan span = spans[spans.Length-1]; //the matching brace string text; this.textLines.GetLineText( span.iEndLine, 0, span.iEndLine, span.iEndIndex, out text ); int start; int len = text.Length; for (start = 0 ; start < span.iEndIndex && start < len && Char.IsWhiteSpace(text[start]); start++) ; if (start < span.iEndIndex) { if (text.Length>80) text = text.Substring(0,80)+"..."; text = String.Format(UIStrings.GetString(UIStringNames.BraceMatchStatus), text); this.statusBar.SetText(text); } } } catch (Exception e) { CCITracing.Trace("HandleMatchBracesResponse exception: " + e.Message); } }
internal void HandleQuickInfoResponse(ParseRequest req) { if (req.Line == this.quickInfoLine && req.Col == this.quickInfoIdx) { this.quickInfoText = req.Scope.GetDataTipText(req.Line, req.Col, out this.quickInfoSpan); } }
/// <summary> /// Factory function for the scope. /// </summary> public static ConsoleAuthoringScope CreateScope(ParseRequest request) { if (null == request) { return null; } ConsoleAuthoringScope scope = null; if (request.Reason == ParseReason.MemberSelect || request.Reason == ParseReason.DisplayMemberList || request.Reason == ParseReason.CompleteWord) { scope = new ConsoleAuthoringScope(); } return scope; }
public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(Microsoft.VisualStudio.Package.ParseRequest req) { return(new CocoAuthoringScope(GetSource(req.View) as CocoSource, req)); }