示例#1
0
        public void Process(string tableName)
        {
            _tableName = tableName;
            _tables.Clear();

            var procOutput = new StringOutput();
            var proc = new ProcessRunner();

            proc.CaptureOutput = true;
            proc.CaptureError = false;
            var ret = proc.CaptureProcess("pst", "/v " + tableName, ProbeEnvironment.ExeDir, procOutput);
            if (ret != 0) throw new ProbeException(string.Concat("PST returned error code ", ret, "."));

            _parser = new TokenParser.Parser(StripImplicitComments(procOutput.Text));
            while (_parser.Read())
            {
                if (_parser.TokenText == "create")
                {
                    if (ReadCreateTable()) { }
                    else if (ReadCreateIndex()) { }
                    else if (ReadCreateRelationship()) { }
                    else if (ReadCreateTimeRelationship()) { }
                    else
                    {
                        ProbeNppPlugin.Instance.Output.WriteLine(OutputStyle.Warning, "Unknown token '{0}' in PST output for table '{1}'.", _parser.TokenText, tableName);
                    }
                }
            }
        }
示例#2
0
 public void Append(Parser parser)
 {
     Append(parser.TokenType, parser.TokenText);
 }
示例#3
0
        public IEnumerable<Function> Parse(string source)
        {
            _funcs = new List<Function>();

            _parser = new TokenParser.Parser(source);
            _parser.ReturnWhiteSpace = false;
            _parser.ReturnComments = false;

            while (!_parser.EndOfFile)
            {
                var startPos = _parser.Position;
                var checkForFunctionDef = true;

                if (!_parser.Peek()) break;
                if (_parser.TokenType == TokenParser.TokenType.Word)
                {
                    switch (_parser.TokenText)
                    {
                        case "for":
                        case "if":
                        case "select":
                        case "switch":
                        case "while":
                            // Functions will never be defined inside the conditions for these control statements.
                            while (_parser.Read())
                            {
                                if (_parser.TokenType == TokenParser.TokenType.Operator &&
                                    (_parser.TokenText == "{" || _parser.TokenText == ";" || _parser.TokenText == ":"))
                                {
                                    break;
                                }
                            }
                            checkForFunctionDef = false;
                            break;
                    }
                }

                if (checkForFunctionDef)
                {
                    if (!ProcessDefine() && !ProcessFunction())
                    {
                        // Unable to find any recognizable pattern, so just skip the next token.
                        _parser.Read();
                    }
                }
            }

            // Expand the function line ranges to fill in the function bodies.
            Function lastFunc = null;
            foreach (var func in _funcs)
            {
                if (lastFunc != null)
                {
                    lastFunc.EndLine = func.StartLine > lastFunc.StartLine ? func.StartLine - 1 : lastFunc.StartLine;
                }
                lastFunc = func;
            }

            if (lastFunc != null) lastFunc.EndLine = source.Count(c => c == '\n') + 1;

            return _funcs;
        }