示例#1
0
        /// <summary>
        /// Prints tokens to file supplied, if file is not supplied, prints to console.
        /// </summary>
        public override object DoExecute(Interpreter i)
        {
            i.InitPlugins();
            var tokens = i.ToTokens(_filepath, true);
            using (var writer = new StreamWriter(_outpath))
            {
                foreach (TokenData tokendata in tokens)
                {
                    // Option 1: Do not display newlines in the token list
                    if (_excludeNewLines && tokendata.Token == Tokens.NewLine)
                        continue;

                    // Option 2: Just include line #, line char # and text.
                    if (_conciseMode)
                    {
                        // Create only if needed.
                        if (_paddings == null)
                            _paddings = new Dictionary<int, string>();
                        
                        var text = tokendata.Line.ToString() + " - " + tokendata.LineCharPos.ToString();
                        var lineinfo = this.Pad(text, 8);
                        var tokenText = tokendata.Token.Text;
                        if (tokendata.Token.Kind == TokenKind.LiteralString)
                            tokenText = "'" + tokenText + "'";
                        writer.WriteLine("{0} : {1}", lineinfo, tokenText);
                    }
                    else
                        writer.WriteLine(tokendata.ToString());
                }
                writer.Flush();
            }
            return null;
        }
示例#2
0
        /// <summary>
        /// Prints all the meta plugins loaded.
        /// </summary>
        public override object DoExecute(Interpreter i)
        {
            var printer = new Printer();
            printer.WriteHeader("Meta plugins ");
            printer.WriteKeyValue(true, "Folder: ", false, i.Settings.PluginsFolder);
            printer.WriteLines(2);

            i.Context.PluginsMeta.EachPlugin(plugin =>
            {
                printer.WriteKeyValue(true, "Name: ", true, plugin.Name);
                printer.WriteKeyValue(true, "Desc: ", false, plugin.Desc);
                printer.WriteKeyValue(true, "Docs: ", false, plugin.Doc);
                printer.WriteKeyValue(true, "Type: ", false, plugin.PluginType);
                printer.WriteKeyValue(true, "IsOn: ", true, plugin.IsEnabled.ToString().ToLower());
                printer.WriteKeyValue(true, "Gram: ", true, plugin.GetFullGrammar());
                printer.WriteKeyValue(true, "Examples: ", false, string.Empty);
                for (var ndx = 0; ndx < plugin.Examples.Length; ndx++)
                {
                    var count = (ndx + 1).ToString(CultureInfo.InvariantCulture);
                    printer.WriteLine(count + ". " + plugin.Examples[ndx]);
                }
                printer.WriteLines(3);
            });
            return null;
        }
示例#3
0
 /// <summary>
 /// Prints tokens to file supplied, if file is not supplied, prints to console.
 /// </summary>
 public override object DoExecute(Interpreter i)
 {
     foreach (var file in _files)
     {
         i.AppendExecuteFile(file);
     }
     return null;
 }
示例#4
0
 /// <summary>
 /// Prints tokens to file supplied, if file is not supplied, prints to console.
 /// </summary>
 public object Execute(Interpreter i)
 {
     this.DoExecute(i);
     var runResult = i.Result;
         
     if (this.OutputResult)
     {
         WriteScriptStatus(runResult.Success, runResult.Message);
     }
     return runResult;
 }
示例#5
0
 /// <summary>
 /// Prints tokens to file supplied, if file is not supplied, prints to console.
 /// </summary>
 public override object DoExecute(Interpreter i)
 {
     var statements = i.ToStatements(_filepath, true);
     using (var writer = new StreamWriter(_outpath))
     {
         foreach (Expr stmt in statements)
         {
             writer.Write(stmt.AsString());
         }
         writer.Flush();
     }
     return null;
 }
示例#6
0
        /// <summary>
        /// Prints tokens to file supplied, if file is not supplied, prints to console.
        /// </summary>
        public override object DoExecute(Interpreter i)
        {
            i.InitPlugins();

            // 1. read line of code from console.
            var script = Console.ReadLine();
            script = script.Trim();
            if (string.Compare(script, "exit", StringComparison.InvariantCultureIgnoreCase) == 0)
                return string.Empty;

            i.Execute(script);

            // 2. Check success of line
            if (!i.Result.Success)
                return i.Result.Message;

            while (true)
            {
                // Now keep looping
                // 3. Read successive lines of code and append
                script = Console.ReadLine();

                // 4. Check for exit flag.
                if (string.Compare(script, "exit", StringComparison.InvariantCultureIgnoreCase) == 0
                    || string.Compare(script, "Exit", StringComparison.InvariantCultureIgnoreCase) == 0
                    || string.Compare(script, "EXIT", StringComparison.InvariantCultureIgnoreCase) == 0)
                    break;

                // 5. Only process if not empty
                if (!string.IsNullOrEmpty(script))
                {
                    i.AppendExecute(script);

                    // 6. if error break;
                    if (!i.Result.Success)
                        break;
                }
            }
            return null;
        }
示例#7
0
 /// <summary>
 /// Execute code specific to this switch option.
 /// </summary>
 /// <param name="i"></param>
 /// <returns></returns>
 public virtual  object DoExecute(Interpreter i)
 {
     return null;
 }
示例#8
0
 /// <summary>
 /// Prints tokens to file supplied, if file is not supplied, prints to console.
 /// </summary>
 public override object DoExecute(Interpreter i)
 {
     i.LintFile(_filepath);
     return null;
 }
示例#9
0
 /// <summary>
 /// Prints tokens to file supplied, if file is not supplied, prints to console.
 /// </summary>
 public override object DoExecute(Interpreter i)
 {
     i.Context.Directives.RegisterDelimited(_directives);
     return null;
 }