Example #1
0
 public bool Compile(SquirrelVersion sv, string src, ref _CompilerError err)
 {
     /*if (sv == SquirrelVersion.Squirrel2)
      * {
      *  Squirrel.Squirrel2.CompilerError cr = null;
      *  if (!c2.Compile(src, ref cr))
      *  {
      *      err = new _CompilerError();
      *      err.column = cr.column;
      *      err.line = cr.line;
      *      err.error = cr.error;
      *      return false;
      *  }
      *  return true;
      * }*/
     if (sv == SquirrelVersion.Squirrel3)
     {
         Squirrel.Squirrel3.CompilerError cr = null;
         if (!c3.Compile(src, ref cr))
         {
             err        = new _CompilerError();
             err.column = cr.column;
             err.line   = cr.line;
             err.error  = cr.error;
             return(false);
         }
         return(true);
     }
     err       = new _CompilerError();
     err.error = "invalid language version selected";
     return(false);
 }
Example #2
0
 public bool Compile(string src, ref _CompilerError error)
 {
     if (_compiler == null)
     {
         _compiler = new _Compiler();
     }
     return(_compiler.Compile(squirrelVersion, src, ref error));
 }
Example #3
0
        //
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            Debug.Print("ParseSource at ({0}:{1}), reason {2}", req.Line, req.Col, req.Reason);
            //throw new NotImplementedException();
            SquirrelAuthoringScope scope = null;//req.Scope as SquirrelAuthoringScope;

            switch (req.Reason)
            {
            case ParseReason.Check:
            {
                scope     = new SquirrelAuthoringScope(this, squirrelVersion);
                req.Scope = scope;
                Source source = (Source)this.GetSource(req.FileName);

                _CompilerError error = null;
                String         src   = req.Text;

                if (!scope.Compile(src, ref error))
                {
                    TextSpan span = new TextSpan();
                    span.iStartLine = span.iEndLine = error.line - 1;
                    if (error.column > 0)
                    {
                        span.iStartIndex = error.column - 2;
                        span.iEndIndex   = error.column;
                    }
                    else
                    {
                        span.iStartIndex = error.column;
                        span.iEndIndex   = error.column + 2;
                    }

                    req.Sink.AddError(req.FileName, error.error, span, Severity.Error);
                }

                if (req.Sink.HiddenRegions)
                {
                    scope.Parse(_scanner, src);
                    foreach (TextSpan s in scope.HiddenRegions)
                    {
                        req.Sink.ProcessHiddenRegions = true;
                        req.Sink.AddHiddenRegion(s);
                    }
                }
            }

            break;

            case ParseReason.MatchBraces:
            case ParseReason.HighlightBraces:
            case ParseReason.MemberSelectAndHighlightBraces:
            {
                if (scope == null)
                {
                    scope     = new SquirrelAuthoringScope(this, squirrelVersion);
                    req.Scope = scope;
                    Source source = (Source)this.GetSource(req.FileName);
                    String src    = req.Text;
                    scope.Parse(_scanner, src);
                }
                if (scope != null)
                {
                    SquirrelAuthoringScope s = (SquirrelAuthoringScope)req.Scope;
                    //LexPair match = new LexPair();
                    //bool found = false;
                    //bool failed = true;
                    foreach (LexPair p in s.Pairs)
                    {
                        if (p.full.iStartLine <= req.Line + 1 &&
                            p.full.iEndLine >= req.Line - 1)
                        {
                            req.Sink.MatchPair(p.start, p.end, 1);
                        }
                    }
                }

                //Console.WriteLine("asd");
            }
            break;

            case ParseReason.CompleteWord:
            case ParseReason.MemberSelect:
            case ParseReason.DisplayMemberList:
            case ParseReason.MethodTip:
            case ParseReason.QuickInfo:
            {
                Source source = (Source)this.GetSource(req.FileName);
                string text   = source.GetLine(req.Line);
                int    n      = Math.Min(req.Col, text.Length - 1);
                int    pivot  = -1;
                int    offset = 0;

                //if (req.Reason == ParseReason.CompleteWord)
                //{
                //    Console.WriteLine("ParseReason.CompleteWord");
                // }

                StringBuilder sb = new StringBuilder();
                TextSpan      startparameters = new TextSpan();
                bool          hasstartparams  = true;
                if (req.Reason == ParseReason.MethodTip)
                {
                    while (n >= 0)
                    {
                        char c = text[n];
                        if (c == '(')
                        {
                            n--;
                            hasstartparams              = true;
                            startparameters.iEndLine    = startparameters.iStartLine = req.Line;
                            startparameters.iStartIndex = n + 2;
                            startparameters.iEndIndex   = n + 3;

                            break;
                        }
                        n--;
                        offset++;
                    }
                }
                int endparse = req.Col;
                if ((req.Reason == ParseReason.QuickInfo ||
                     req.Reason == ParseReason.CompleteWord) && text.Length > 0)
                {
                    char c = text[n];
                    while (n < (text.Length - 1) && char.IsWhiteSpace(c))
                    {
                        n++;
                        c = text[n];
                    }

                    while (n < (text.Length - 1) && char.IsLetterOrDigit(c) || c == '_')
                    {
                        n++;
                        c = text[n];
                    }
                    if (n > 0 && !char.IsLetterOrDigit(c) && c != '_')
                    {
                        n--;
                        c = text[n];
                    }
                    endparse = n + 1;
                }
                int endid = n;
                while (n >= 0)
                {
                    char c = text[n];
                    if ((!(char.IsLetterOrDigit(c) || c == '_')) && c != '.')
                    {
                        break;
                    }
                    if (c == '.' && pivot == -1)
                    {
                        pivot = n;
                    }
                    n--;

                    offset++;
                    sb.Insert(0, c);
                }

                if (req.Sink.FindNames && req.Reason != ParseReason.QuickInfo)
                {
                    TextSpan namespan = new TextSpan();
                    namespan.iStartLine  = namespan.iEndLine = req.Line;
                    namespan.iStartIndex = n + 1;
                    namespan.iEndIndex   = endid + 1;
                    req.Sink.StartName(namespan, sb.ToString());
                    if (hasstartparams && req.Sink.MethodParameters)
                    {
                        req.Sink.StartParameters(startparameters);
                        int prev = Math.Max(startparameters.iStartIndex - 1, 0);
                        int pos  = prev;
                        while (pos < req.Col)
                        {
                            char c = text[pos];
                            if (c == ',' || c == ')')
                            {
                                TextSpan parspan = new TextSpan();
                                parspan.iStartLine  = parspan.iEndLine = req.Line;
                                parspan.iStartIndex = pos;
                                parspan.iEndIndex   = pos + 1;
                                if (c == ',')
                                {
                                    req.Sink.NextParameter(parspan);
                                }
                                else
                                {
                                    req.Sink.EndParameters(parspan);
                                }
                            }

                            pos++;
                        }
                    }
                }
                String ret        = sb.ToString();
                String rettolower = ret.ToLower();


                //Console.WriteLine(ret);
                int line  = req.Line;
                int start = n + 1;
                if (req.Reason != ParseReason.QuickInfo)
                {
                    start = pivot != -1 ? pivot + 1 : n + 1;
                }
                int end = endparse;
                //string txt = text.Substring(start, end - start);

                if (scope == null)
                {
                    scope     = new SquirrelAuthoringScope(this, squirrelVersion);
                    req.Scope = scope;
                }
                string[] tolowertrgs  = rettolower.Split(new char[] { '.' });
                string[] origcasetrgs = ret.Split(new char[] { '.' });

                scope.SetCompletionInfos(_completiondb, origcasetrgs, tolowertrgs, line, start, end);
                //return new SquirrelAuthoringScope(_completiondb, trgs, line,start,end);
            }
            break;
            }
            return(scope == null ? new SquirrelAuthoringScope(this, squirrelVersion) : scope);
        }