Esempio n. 1
0
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            if (req == null)
            {
                throw new ArgumentNullException("req");
            }

            Trace.WriteLine(string.Format("NVelocityLanguage.ParseSource(). Reason:{0}", req.Reason));

            // Parse the input if required
            if (req.Reason == ParseReason.Check ||
                req.Reason == ParseReason.DisplayMemberList ||
                req.Reason == ParseReason.MemberSelect ||
                req.Reason == ParseReason.MethodTip)
            {
                ErrorHandler errors = new ErrorHandler();

                try
                {
                    Scanner scanner = new Scanner(errors);
                    scanner.Options.EnableIntelliSenseTriggerTokens = true;
                    scanner.SetSource(req.Text);

                    Parser parser = new Parser(scanner, errors);

                    _templateNode = parser.ParseTemplate();

                    // Prepare the template node so that all the helpers are available
                    PrepareTemplateNode(req.FileName);

                    _templateNode.DoSemanticChecks(errors);
                }
                catch (ScannerError se)
                {
                    req.Sink.AddError(req.FileName, "Scanner Error: " + se.Message, new TextSpan(),
                                      Severity.Error);
                }
                catch (Exception ex)
                {
                    req.Sink.AddError(req.FileName, "FATAL: " + ex, new TextSpan(), Severity.Error);
                }
                finally
                {
                    for (int i = 0; i < errors.Count; i++)
                    {
                        Error error = errors[i];

                        TextSpan textSpan = new TextSpan();
                        textSpan.iStartLine  = error.Position.StartLine - 1;
                        textSpan.iStartIndex = error.Position.StartPos - 1;
                        textSpan.iEndLine    = error.Position.EndLine - 1;
                        textSpan.iEndIndex   = error.Position.EndPos - 1;

                        Severity severity = Severity.Fatal;
                        if (error.Severity == ErrorSeverity.Error)
                        {
                            severity = Severity.Error;
                        }
                        else if (error.Severity == ErrorSeverity.Warning)
                        {
                            severity = Severity.Warning;
                        }
                        else if (error.Severity == ErrorSeverity.Message)
                        {
                            severity = Severity.Hint;
                        }

                        req.Sink.AddError(req.FileName, error.Description, textSpan, severity);
                    }
                }

#if DEBUG
                int line;
                int column;
                req.View.GetCaretPos(out line, out column);
                _debugForm.UpdateUI(line + 1, column + 1, _templateNode);
#endif
            }
            else
            {
                //MessageBox.Show("Unparsed ParseReason: " + req.Reason);
            }

            // Perform other operations
            if (req.Reason == ParseReason.MethodTip)
            {
                TextSpan textSpan = new TextSpan();
                textSpan.iStartLine  = req.Line;
                textSpan.iStartIndex = req.Col - 1;
                textSpan.iEndLine    = req.Line;
                textSpan.iEndIndex   = req.Col;

                req.Sink.StartName(textSpan, "");
                req.Sink.StartParameters(textSpan);

                Trace.WriteLine("MethodTip at line " + req.Line + " col " + req.Col);
            }

            if (req.Sink.HiddenRegions)
            {
                AddHiddenRegions(req.Sink, _templateNode.Content);

                req.Sink.ProcessHiddenRegions = true;
            }

            NVelocityAuthoringScope scope = new NVelocityAuthoringScope(_templateNode, req.FileName);

            //if (req.Sink.BraceMatching && req.Col > 30)
            //{
            //    TextSpan startBrace = new TextSpan();
            //    startBrace.iStartLine = req.Line;
            //    startBrace.iStartIndex = 20;
            //    startBrace.iEndLine = req.Line;
            //    startBrace.iEndIndex = 21;

            //    TextSpan endBrace = new TextSpan();
            //    endBrace.iStartLine = req.Line;
            //    endBrace.iStartIndex = req.Col - 1;
            //    endBrace.iEndLine = req.Line;
            //    endBrace.iEndIndex = req.Col;

            //    req.Sink.MatchPair(startBrace, endBrace, 0);
            //}

            return(scope);
        }
Esempio n. 2
0
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            if (req == null)
            {
                throw new ArgumentNullException("req");
            }

            Trace.WriteLine(string.Format("NVelocityLanguage.ParseSource(). Reason:{0}", req.Reason));

            // Parse the input if required
            if (req.Reason == ParseReason.Check ||
                req.Reason == ParseReason.DisplayMemberList ||
                req.Reason == ParseReason.MemberSelect ||
                req.Reason == ParseReason.MethodTip)
            {
                ErrorHandler errors = new ErrorHandler();

                try
                {
                    Scanner scanner = new Scanner(errors);
                    scanner.Options.EnableIntelliSenseTriggerTokens = true;
                    scanner.SetSource(req.Text);

                    Parser parser = new Parser(scanner, errors);

                    _templateNode = parser.ParseTemplate();

                    // Prepare the template node so that all the helpers are available
                    PrepareTemplateNode(req.FileName);

                    _templateNode.DoSemanticChecks(errors);
                }
                catch (ScannerError se)
                {
                    req.Sink.AddError(req.FileName, "Scanner Error: " + se.Message, new TextSpan(),
                        Severity.Error);
                }
                catch (Exception ex)
                {
                    req.Sink.AddError(req.FileName, "FATAL: " + ex, new TextSpan(), Severity.Error);
                }
                finally
                {
                    for (int i = 0; i < errors.Count; i++)
                    {
                        Error error = errors[i];

                        TextSpan textSpan = new TextSpan();
                        textSpan.iStartLine = error.Position.StartLine - 1;
                        textSpan.iStartIndex = error.Position.StartPos - 1;
                        textSpan.iEndLine = error.Position.EndLine - 1;
                        textSpan.iEndIndex = error.Position.EndPos - 1;

                        Severity severity = Severity.Fatal;
                        if (error.Severity == ErrorSeverity.Error)
                            severity = Severity.Error;
                        else if (error.Severity == ErrorSeverity.Warning)
                            severity = Severity.Warning;
                        else if (error.Severity == ErrorSeverity.Message)
                            severity = Severity.Hint;

                        req.Sink.AddError(req.FileName, error.Description, textSpan, severity);
                    }
                }

            #if DEBUG
                int line;
                int column;
                req.View.GetCaretPos(out line, out column);
                _debugForm.UpdateUI(line + 1, column + 1, _templateNode);
            #endif
            }
            else
            {
                //MessageBox.Show("Unparsed ParseReason: " + req.Reason);
            }

            // Perform other operations
            if (req.Reason == ParseReason.MethodTip)
            {
                TextSpan textSpan = new TextSpan();
                textSpan.iStartLine = req.Line;
                textSpan.iStartIndex = req.Col - 1;
                textSpan.iEndLine = req.Line;
                textSpan.iEndIndex = req.Col;

                req.Sink.StartName(textSpan, "");
                req.Sink.StartParameters(textSpan);

                Trace.WriteLine("MethodTip at line " + req.Line + " col " + req.Col);
            }

            if (req.Sink.HiddenRegions)
            {
                AddHiddenRegions(req.Sink, _templateNode.Content);

                req.Sink.ProcessHiddenRegions = true;
            }

            NVelocityAuthoringScope scope = new NVelocityAuthoringScope(_templateNode, req.FileName);

            //if (req.Sink.BraceMatching && req.Col > 30)
            //{
            //    TextSpan startBrace = new TextSpan();
            //    startBrace.iStartLine = req.Line;
            //    startBrace.iStartIndex = 20;
            //    startBrace.iEndLine = req.Line;
            //    startBrace.iEndIndex = 21;

            //    TextSpan endBrace = new TextSpan();
            //    endBrace.iStartLine = req.Line;
            //    endBrace.iStartIndex = req.Col - 1;
            //    endBrace.iEndLine = req.Line;
            //    endBrace.iEndIndex = req.Col;

            //    req.Sink.MatchPair(startBrace, endBrace, 0);
            //}

            return scope;
        }