コード例 #1
0
        public void SimpleOutcome_RunWithWords()
        {
            var src     = @"a nifty rule
displayAs 
tunafish rep 
conditions    
a is b
dialogs
:player 1        
speaking line text
multi line
outcomes
run a 
    with b as 5 
    with c as 2
";
            var program = new WordLangResults(src);

            Assert.AreEqual(false, program.ParserErrors.AnyErrors);


            var v      = new ProgramToTree();
            var result = v.Visit(program.ProgramContext.rule(0).outcomes().singleOutcome(0));

            Assert.AreEqual("(run target=[a] args=[(arg name=[b] expr=[5]),(arg name=[c] expr=[2])])", result);
        }
コード例 #2
0
        public void ConditionalMath_SubtractRight()
        {
            var src     = @"A Nifty Rule
 dispLaYaS 
conditions
x - 5 is y
dialogs
:plr
hello world
outcomes
set a to b
";
            var program = new WordLangResults(src);

            Assert.AreEqual(false, program.ParserErrors.AnyErrors);
            var v         = new ProgramToTree();
            var firstExpr = program.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(- x 5)", output);
        }
コード例 #3
0
        public void ConditionalMath_AddLotsOfSpaces()
        {
            var src     = @"A Nifty Rule
 dispLaYaS 
conditions
x  + 25  + z +  1205 is y   +  12
dialogs
:plr
hello world
outcomes
set a to b
";
            var program = new WordLangResults(src);

            Assert.AreEqual(false, program.ParserErrors.AnyErrors);
            var v         = new ProgramToTree();
            var firstExpr = program.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(+ x (+ 25 (+ z 1205)))", output);
        }
コード例 #4
0
        public void ConditionalMath_PEMDAS_ParensNested()
        {
            var srcA = @"A Nifty Rule
 dispLaYaS 
conditions
2 * (  ((3 + 4) - (5 - 2)) + 4) is y 
dialogs
:plr
hello world
outcomes
set a to b
";

            var progA = new WordLangResults(srcA);

            Assert.AreEqual(false, progA.ParserErrors.AnyErrors);
            var firstExpr = progA.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var v         = new ProgramToTree();
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(* 2 (+ (- (+ 3 4) (- 5 2)) 4))", output);
        }
コード例 #5
0
        public void ConditionalMath_PEMDAS_MultDivide()
        {
            var srcA = @"A Nifty Rule
 dispLaYaS 
conditions
a / b * c is y 
dialogs
:plr
hello world
outcomes
set a to b
";

            var progA = new WordLangResults(srcA);

            Assert.AreEqual(false, progA.ParserErrors.AnyErrors);
            var firstExpr = progA.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var v         = new ProgramToTree();
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(/ a (* b c))", output);
        }
コード例 #6
0
        public void ConditionalMath_Complicated()
        {
            var srcA = @"A Nifty Rule
 dispLaYaS 
conditions
x * y + z * w * a + 1 is y 
dialogs
:plr
hello world
outcomes
set a to b
";

            var progA = new WordLangResults(srcA);

            Assert.AreEqual(false, progA.ParserErrors.AnyErrors);
            var firstExpr = progA.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var v         = new ProgramToTree();
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(+ (* x y) (+ (* z (* w a)) 1))", output);
        }
コード例 #7
0
        public void TemplateDialog()
        {
            var src     = @"A Nifty Rule
 dispLaYaS 
conditions
x is y
dialogs
:plr
hello world, my name is {'Mr. ' + actor.name}
outcomes
set a to b
";
            var program = new WordLangResults(src);

            Assert.AreEqual(false, program.LexerErrors.AnyErrors);
            Assert.AreEqual(false, program.ParserErrors.AnyErrors);
            var v = new ProgramToTree();

            //var line = v.Visit(program.ProgramContext.rule(0).dialogs().dialogLine(0));

            //Assert.AreEqual("(dialog speaker=[plr] parts=[(freetext line=[hello world, my name is ]),(templ expr=[(+ 'Mr. ' actor.name)])])", line);
        }
コード例 #8
0
        public void SimpleOutcome_SetWithExpr()
        {
            var src     = @"a nifty rule
displayAs 
tunafish rep 
conditions    
a is b
dialogs
:player 1        
speaking line text
multi line
outcomes
a = b
";
            var program = new WordLangResults(src);

            Assert.AreEqual(false, program.ParserErrors.AnyErrors);

            var v      = new ProgramToTree();
            var result = v.Visit(program.ProgramContext.rule(0).outcomes().singleOutcome(0));

            Assert.AreEqual("(set target=[a] expr=[b])", result);
        }
コード例 #9
0
        public void ConditionalMath_PEMDAS_MultThenAdd()
        {
            var srcB  = @"A Nifty Rule
 dispLaYaS 
conditions
x * a + 5 is y
dialogs
:plr
hello world
outcomes
set a to b
";
            var progB = new WordLangResults(srcB);

            Assert.AreEqual(false, progB.ParserErrors.AnyErrors);

            var v = new ProgramToTree();

            var firstExpr = progB.ProgramContext.rule(0).conditions().booleanExpr(0).expression(0);
            var output    = v.VisitExpression(firstExpr);

            Assert.AreEqual("(+ (* x a) 5)", output);
        }