public void GetText_SingleLine() { Babel.Parser.ErrorHandler handler = new Babel.Parser.ErrorHandler(); Babel.Lexer.Scanner scanner = new Babel.Lexer.Scanner(); scanner.Handler = handler; scanner.SetSourceText("CREATE MEASURE t[B]=Random()"); var text = scanner.GetText(new LexLocation(1, 20, 1, 28)); Assert.IsFalse(handler.Errors, "Error happened"); Assert.AreEqual("Random()", text); }
public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req) { Source source = (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.Reason == ParseReason.Check || req.DirtySpan.iStartIndex != req.DirtySpan.iEndIndex || req.DirtySpan.iStartLine != req.DirtySpan.iEndLine) { 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 #if DEBUG parser.Trace = true; #endif parser.scanner = scanner; scanner.Handler = handler; parser.SetHandler(handler); scanner.SetSourceText(req.Text); 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); } } } return(new AuthoringScope(source.ParseResult, source)); }
public BlenXLibraryManager(IServiceProvider provider) { //documents = new Dictionary<uint, TextLineEventListener>(); //library = new Library(new Guid("0925166e-a743-49e2-9224-bbe206545104")); //library.LibraryCapabilities = (_LIB_FLAGS2)_LIB_FLAGS.LF_PROJECT; //files = new Dictionary<ModuleId, LibraryNode>(); this.provider = provider; requests = new Queue<LibraryTask>(); requestPresent = new ManualResetEvent(false); shutDownStarted = new ManualResetEvent(false); parseThread = new Thread(new ThreadStart(ParseThread)); parseThread.Start(); this.handler = new Babel.Parser.ErrorHandler(provider); }
private static Babel.Parser.Parser ParseText(string text, bool trace = false) { Babel.Parser.ErrorHandler handler = new Babel.Parser.ErrorHandler(); Babel.Lexer.Scanner scanner = new Babel.Lexer.Scanner(); Babel.Parser.Parser parser = new Babel.Parser.Parser(); // use noarg constructor parser.Trace = trace; parser.scanner = scanner; scanner.Handler = handler; parser.SetHandler(handler); scanner.SetSourceText(text); var request = new ParseRequest(true); request.Sink = new AuthoringSink(ParseReason.None, 0, 0, Babel.Parser.Parser.MaxErrors); parser.MBWInit(request); var result = parser.Parse(); if (handler.Errors) { throw new Exception(handler.ToString()); } return(parser); }
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); }
public BabelLanguageService(Package package) : base() { this.handler = new Babel.Parser.ErrorHandler(package); }
/// <summary> /// Parses measures from the mdx script text. If there is an error during parsing an exception is thrown. /// </summary> /// <param name="daxScript">mdx script text</param> /// <returns>Enumerable dax measures</returns> public static MeasuresContainer ParseDaxScript(string daxScript) { var handler = new Babel.Parser.ErrorHandler(); var scanner = new Babel.Lexer.Scanner(); var parser = new Babel.Parser.Parser(); // use noarg constructor parser.scanner = scanner; scanner.Handler = handler; parser.SetHandler(handler); scanner.SetSourceText(daxScript); var request = new ParseRequest(true); request.Sink = new AuthoringSink(ParseReason.None, 0, 0, Babel.Parser.Parser.MaxErrors); parser.MBWInit(request); var parseResult = parser.Parse(); if (handler.Errors) { throw DaxParsingException.FromHandler(handler, daxScript); } //Add support measures if measure contains KPIs var measures = parser.AllMeasures; var supportMeasures = new List <DaxMeasure>(); var containsSupportMeasures = measures.GetSupportingMeasures().Count() != 0; if (!containsSupportMeasures) { foreach (var measure in measures) { if (measure.CalcProperty?.KPI == null) { continue; } if (!string.IsNullOrWhiteSpace(measure.CalcProperty.KPI.TargetExpression)) { var newMeasure = new DaxMeasure( "_" + measure.Name + " Goal", measure.TableName, measure.CalcProperty.KPI.TargetExpression ); supportMeasures.Add(newMeasure); } if (!string.IsNullOrWhiteSpace(measure.CalcProperty.KPI.StatusExpression)) { var newMeasure = new DaxMeasure( "_" + measure.Name + " Status", measure.TableName, measure.CalcProperty.KPI.StatusExpression ); supportMeasures.Add(newMeasure); } if (!string.IsNullOrWhiteSpace(measure.CalcProperty.KPI.TrendExpression)) { var newMeasure = new DaxMeasure( "_" + measure.Name + " Trend", measure.TableName, measure.CalcProperty.KPI.TrendExpression ); supportMeasures.Add(newMeasure); } } } return(new MeasuresContainer(measures.Union(supportMeasures).ToList())); }
public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req) { Source source = (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) { 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); 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(source.ParseResult)); }
public override Microsoft.VisualStudio.Package.AuthoringScope ParseSource(ParseRequest req) { Source source = (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) { 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); 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(source.ParseResult); }