! this code looks messy but it tests all return values from the 
! grammar property. -1, 0, 'verb' and -'verb'. See test-grammarproperty.cmd
! for example inputs.

#Iftrue (#version_number == 8);
Constant USEINFORM;
#Endif;

Constant Story      "Parser test";
Constant Headline   "^A parser test suite for PunyInform.^";
Serial "200827";
Constant INITIAL_LOCATION_VALUE = Library;

! Uncomment to show time instead of score/turns
!Statusline time;

!Constant DEBUG;
!Constant DEBUG_PARSEANDPERFORM;
!Constant DEBUG_PARSEPATTERN;
!Constant DEBUG_PARSETOKEN;
!Constant DEBUG_PARSENOUNPHRASE;
!Constant DEBUG_GETNEXTNOUN;
!Constant DEBUG_SCOPE;

! Uncomment to add optional features to PunyLib
!Constant DEBUG;
!Constant CUSTOM_ABBREVIATIONS;
!Constant OPTIONAL_ALLOW_WRITTEN_NUMBERS;
Constant OPTIONAL_EXTENDED_METAVERBS;
Constant OPTIONAL_EXTENDED_VERBSET;
!Constant OPTIONAL_GRAMMAR_PROPERTY;
!Constant OPTIONAL_NO_DARKNESS;
!Constant OPTIONAL_FULL_SCORE;
!Constant OPTIONAL_FULL_DIRECTIONS;
!Constant OPTIONAL_GUESS_MISSING_NOUN;
!Constant OPTIONAL_MANUAL_SCOPE;
!Constant RUNTIME_ERRORS = 0;

#Ifdef USEINFORM;
Include "Parser";
Include "VerbLib";
#IfNot;
Include "globals.h";
#EndIf;

#Ifndef USEINFORM;
Include "puny.h";
#EndIf;

! Uncomment to add PunyLib extensions
!Include "ext_menu.h";
!Include "ext_flags.h";
!Include "ext_quote_box.h";
!Include "ext_cheap_scenery.h";


#Ifdef USEINFORM;
Include "Grammar";
#Endif;

[ TakeAimSub;
    ! Only BattleBot can be ordered to take aim, and this is handled in its
    ! orders property, so this routine should never be executed.
    "No.";
];

Verb 'bot,' * 'take' 'aim' -> TakeAim;

Object Library "The Library"
	with
	    description "You are in a library.",
	has light;

Object -> John "John"
	with name 'john',
	life [;
	Answer:  print "answer words ", consult_words, " from ", consult_from, "^";
	Ask: print "ask^";
	Order: print "order ", action, ": inv ", ##Inv, " take ", ##Take, "^";
	],
	before [;
	Consult: print "consult^";
	],
	orders [;
    Open: "Why do you want me to open ", (the) noun, ".";
    Close: "Why do you want me to close ", (the) noun, ".";
    Eat: "I eat";
    Jump: "I jump";
    Unlock: "I unlock ", (the) noun, ".";
    SwitchOff: "I switch off ", (the) noun, ".";
    Inv: "I have nothing";
    TakeAim: "~Okay, I'm aiming.~";
	],
	grammar [;
	    print "grammar ", verb_wordnum, " ", verb_word == 'jump', "^";
	    if(verb_word == 'drink') {
	        return 'eat';
        }
	    if(verb_word == 'open') {
	        return 'close';
        }
	    if(verb_word == 'close') {
            parser_one = true;
	        return -'eat';
        }
	    if(verb_word == 'jump') {
	        action = ##Inv;
	        rtrue;
        }
        if(verb_word == 'take') {
            parser_one = true;
            return -'bot,';
        }
        rfalse;
    ],
	has animate proper;

Object -> apple "apple"
	with name 'apple',
	has edible;

[ Initialise;
#IfDef USEINFORM;
    location=INITIAL_LOCATION_VALUE;
#EndIf;
];

