Exemple #1
0
        public void DeleteVariable()
        {
            var test = @"
0:0 when the script starts,
    5:100 set variable %hi to {hi}.
    5:107 delete variable %hi.
    1:100 and variable %hi is defined,
        5:102 print {@var %hi does exist} to the console.
    1:101 and variable %hi is not defined,
        5:102 print {@var %hi does not exist} to the console.
";

            var engine = new Monkeyspeak.MonkeyspeakEngine
            {
                Options = { TriggerLimit = int.MaxValue, Debug = true }
            };

            var page = engine.LoadFromString(test);

            page.AddTriggerHandler(TriggerCategory.Cause, 0, UnitTest1.HandleScriptStartCause);

            page.LoadAllLibraries();

            page.Execute();
            foreach (var var in page.Scope)
            {
                Logger.Debug(var);
            }

            Console.WriteLine("Page Trigger Count: " + page.Size);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Lexer"/> class.
 /// </summary>
 /// <param name="engine">The engine.</param>
 /// <param name="reader">The reader.</param>
 public Lexer(MonkeyspeakEngine engine, SStreamReader reader)
     : base(engine, reader)
 {
     varDeclSym     = engine.Options.VariableDeclarationSymbol;
     stringBeginSym = engine.Options.StringBeginSymbol;
     stringEndSym   = engine.Options.StringEndSymbol;
     lineCommentSym = engine.Options.LineCommentSymbol;
 }
 public Page(MonkeyspeakEngine engine)
 {
     this.engine   = engine;
     parser        = new Parser(engine);
     triggerBlocks = new List <TriggerBlock>();
     scope         = new Dictionary <string, IVariable>();
     libraries     = new HashSet <BaseLibrary>();
     Initiate();
 }
 /// <summary>
 /// A Reader that is used to get Variables, Strings, and Numbers from Triggers
 /// </summary>
 /// <param name="page"></param>
 /// <param name="trigger"></param>
 public TriggerReader(Page page, TriggerBlock currentBlock)
 {
     this.page = page;
     engine    = page.Engine;
     if (currentBlock != null)
     {
         this.currentBlock = new TriggerBlock(currentBlock);
     }
 }
Exemple #5
0
        public void TestParallelExecute()
        {
            var ioTestString = @"
(0:0) when the script starts,
    (5:100) set variable %file to {test.txt}.
	(1:200) and the file {%file} exist,
		(5:202) delete file {%file}.
		(5:203) create file {%file}.

(0:0) when the script starts,
		(5:102) print {%file} to the console.
		(5:150) take variable %increment and add 1 to it.
		(5:102) print {Execution increment %increment} to the console.

(0:0) when the script starts,
	(1:200) and the file {%file} exists,
	(1:203) and the file {%file} can be written to,
		(5:200) append {Hello World from Monkeyspeak %VERSION!} to file {%file}.

(0:0) when the script starts,
	(5:150) take variable %test and add 2 to it.
	(5:102) print {%test} to the console.
";

            var engine = new Monkeyspeak.MonkeyspeakEngine
            {
                Options = { TriggerLimit = int.MaxValue }
            };

            engine.Options.Debug = false;
            var page = engine.LoadFromString(UnitTest1.tableScript);

            page.AddTriggerHandler(TriggerCategory.Cause, 0, UnitTest1.HandleScriptStartCause);

            page.LoadAllLibraries();

            var tasks = new Task[5];

            for (int i = 0; i <= tasks.Length - 1; i++)
            {
                tasks[i] = Task.Run(async() => await page.ExecuteAsync(0));
            }

            Console.WriteLine("Page Trigger Count: " + page.Size);
            Task.WaitAll(tasks);
            foreach (var variable in page.Scope)
            {
                Console.WriteLine(variable.ToString());
            }
        }
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance.
 /// </summary>
 /// <param name="engine">The engine.</param>
 /// <param name="includeSourcePos">if set to <c>true</c> [include source position].</param>
 /// <returns>
 /// A <see cref="System.String" /> that represents this instance.
 /// </returns>
 public string ToString(MonkeyspeakEngine engine, bool includeSourcePos = false)
 {
     return(RebuildToString(engine.Options, includeSourcePos));
 }
 protected AbstractLexer(MonkeyspeakEngine engine, SStreamReader reader)
 {
     this.reader = reader;
     Engine      = engine;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Parser"/> class.
 /// </summary>
 /// <param name="engine">The engine.</param>
 public Parser(MonkeyspeakEngine engine) :
     base(engine)
 {
 }