Module: Inform::Parser
Overview
Defined Under Namespace
Classes: Ambiguous, AnimateExpected, AskScope, CannotUnderstandSentence, CantSeeError, ExceptedUnnecessarily, InanimateAddressee, IncompleteSentence, ItGone, JunkAfter, MissingAddressee, MultipleMultiples, NoMatchesAvailable, NotHeld, NothingMatched, NothingToRepeat, NumberUnrecognized, ParserError, PartiallyUnderstood, RepeatedOrder, SceneryIsIrrelevant, SpeechImpediment, TooFew, TooLittle, UnexpectedComma, UnexpectedMultiple, Vague, VerbUnrecognized
Constant Summary
collapse
- OTHER_BIT =
These will be used in Adjudicate()
1
- MY_BIT =
2
- THAT_BIT =
4
- PLURAL_BIT =
8
- LIT_BIT =
16
- UNLIT_BIT =
32
- SCORE__CHOOSEOBJ =
1000
- SCORE__IFGOOD =
500
- SCORE__UNCONCEALED =
100
- SCORE__BESTLOC =
60
- SCORE__NEXTBESTLOC =
40
- SCORE__NOTCOMPASS =
20
- SCORE__NOTSCENERY =
10
- SCORE__NOTACTOR =
5
- SCORE__GNA =
1
- SCORE__DIVISOR =
20
- PARSING_REASON =
Searching through scope and parsing "scope=Routine" grammar tokens
:parsing
- TALKING_REASON =
Possible reasons for searching scope
:talking
- EACH_TURN_REASON =
:each_turn
- REACT_BEFORE_REASON =
:react_before
- REACT_AFTER_REASON =
:react_after
- LOOPOVERSCOPE_REASON =
:loop_over_scope
- TESTSCOPE_REASON =
:test_scope
- STUCK_PE =
PARSING_REASON = 0 # Possible reasons for searching scope TALKING_REASON = 1 EACH_TURN_REASON = 2 REACT_BEFORE_REASON = 3 REACT_AFTER_REASON = 4 LOOPOVERSCOPE_REASON = 5 TESTSCOPE_REASON = 6
1
- UPTO_PE =
2
- NUMBER_PE =
3
- CANTSEE_PE =
4
- TOOLIT_PE =
5
- NOTHELD_PE =
6
- MULTI_PE =
7
- MMULTI_PE =
8
- VAGUE_PE =
9
- EXCEPT_PE =
10
- ANIMA_PE =
11
- VERB_PE =
12
- SCENERY_PE =
13
- ITGONE_PE =
14
- JUNKAFTER_PE =
15
- TOOFEW_PE =
16
- NOTHING_PE =
17
- ASKSCOPE_PE =
18
- PowersOfTwo_TB =
[ 0b100000000000,
0b010000000000,
0b001000000000,
0b000100000000,
0b000010000000,
0b000001000000,
0b000000100000,
0b000000010000,
0b000000001000,
0b000000000100,
0b000000000010,
0b000000000001
].freeze
- POSSESS_PK =
Constants, and one variable, needed for the language definition file
0x0100
- DEFART_PK =
0x0101
- INDEFART_PK =
0x0102
- REPARSE_CODE =
Signals “reparse the text” as a reply from NounDomain
10_000
- LanguageCases =
1
- ElementaryTokens =
The definition of the token-numbering system used by Inform.
%i[
noun held multi multiheld multiexcept multiinside creature special number topic end
].freeze
- GPR_FAIL =
Return values from General Parsing
false
- GPR_PREPOSITION =
0
- GPR_NUMBER =
1
- GPR_MULTIPLE =
2
- GPR_REPARSE =
REPARSE_CODE
- GPR_NOUN =
0xff00
- GPR_HELD =
0xff01
- GPR_MULTI =
0xff02
- GPR_MULTIHELD =
0xff03
- GPR_MULTIEXCEPT =
0xff04
- GPR_MULTIINSIDE =
0xff05
- GPR_CREATURE =
0xff06
- GPR_TEXT =
0xff07
- START_MOVE =
Traditionally 0 for Infocom, 1 for Inform
0
- MAX_TIMERS =
Max number timers/daemons active at once
32
- MATCH_LIST_SIZE =
The match list of candidate objects for a given token
Integer::MAX
- Darkness =
“Darkness” is not really a place: but it has to be an object so that the
location-name on the status line can be "Darkness".
Inform::Ephemeral::Object.new "(darkness object)"
- SelfObj =
If you want to use the third-person of the narrative voice, you will need to replace this selfobj with your own.
Object("(self object)") {
with {
def short_name; return L__M(:Miscellany, 18); end
def description; return L__M(:Miscellany, 19); end
def before; nil; end
def after; nil; end
def life; nil; end
def each_turn; nil; end
def time_out; nil; end
def describe; nil; end
def add_to_scope; nil; end
capacity 100
parse_name 0
orders 0
def number; 0; end
def before_implicit; nil; end
}
has :concealed, :animate, :proper, :transparent
}
- InitalState =
Struct.new(:memo).new
- ConversationStarterPattern =
To simplify the picture a little, a rough map of the main routine:
(A) Get the input, do "oops" and "again"
(B) Is it a direction, and so an implicit "go"? If so go to (K)
(C) Is anyone being addressed?
(D) Get the verb: try all the syntax lines for that verb
(E) Break down a syntax line into analysed tokens
(F) Look ahead for advance warning for multiexcept/multiinside
(G) Parse each token in turn (calling ParseToken to do most of the work)
(H) Cheaply parse otherwise unrecognised conversation and return
(I) Print best possible error message
(J) Retry the whole lot
(K) Last thing: check for "then" and further instructions(s), return.
The strategic points (A) to (K) are marked in the commentary.
Note that there are three different places where a return can happen.
%r{\w+, }.freeze
- CommaWordPattern =
ParseToken(type, data):
Parses the given token, from the current word number wn, with exactly
the specification of a general parsing routine.
(Except that for "topic" tokens and prepositions, you need to supply
a position in a valid grammar line as third argument.)
Returns:
GPR_REPARSE for "reconstructed input, please re-parse from scratch"
GPR_PREPOSITION for "token accepted with no result"
$ff00 + x for "please parse ParseToken(ELEMENTARY_TT, x) instead"
0 for "token accepted, result is the multiple object list"
1 for "token accepted, result is the number in parsed_number"
object num for "token accepted with this object as result"
false for "token rejected"
(A) Analyse the token; handle all tokens not involving
object lists and break down others into elementary tokens
(B) Begin parsing an object list
(C) Parse descriptors (articles, pronouns, etc.) in the list
(D) Parse an object name
(E) Parse connectives ("and", "but", etc.) and go back to (C)
(F) Return the conclusion of parsing an object list
%r{,$}.freeze
- DidScopeAction =
defined?(Java) ? java.util.concurrent.ConcurrentHashMap.new : {}
- KnownNumberProperties =
%i[number capacity time_left].freeze
- MethodWriterPattern =
%r{=$}.freeze
- StorageForShortName =
{ buffer: [] }.freeze
- PrefaceByArticle_COUNTER =
Struct.new(:memo).new(0)
Constants included
from Verbs
Verbs::LibraryMessages, Verbs::MAKE__TS, Verbs::TASK_DONE, Verbs::TASK_SCORES
Constants included
from English
English::AGAIN1__WD, English::AGAIN2__WD, English::AGAIN3__WD, English::ALL1__WD, English::ALL2__WD, English::ALL3__WD, English::ALL4__WD, English::ALL5__WD, English::AMBIGUOUS, English::AMUSING__WD, English::AND1__WD, English::AND2__WD, English::AND3__WD, English::AND__TX, English::ANIMATE_EXPECTED, English::ARE2__TX, English::ARE__TX, English::BUT1__WD, English::BUT2__WD, English::BUT3__WD, English::CANNOT_UNDERSTAND, English::CANTGO__TX, English::CANT_SEE, English::CANT_TALK, English::COMMA__TX, English::Compass, English::DARKNESS__TX, English::ENGLISH_DIALECT, English::EXCEPTED_UNECESSARILY, English::FORMER__TX, English::FULLSCORE1__WD, English::FULLSCORE2__WD, English::IS2__TX, English::IS__TX, English::LISTAND2__TX, English::LISTAND__TX, English::LanguageAnimateGender, English::LanguageArticles, English::LanguageContractionForms, English::LanguageDescriptors, English::LanguageGNAsToArticles, English::LanguageInanimateGender, English::LanguageNumbers, English::LanguagePronouns, English::MANUAL_PRONOUNS, English::ME1__WD, English::ME2__WD, English::ME3__WD, English::MOVES__TX, English::NKEY1__KY, English::NKEY2__KY, English::NKEY__TX, English::NO1__WD, English::NO2__WD, English::NO3__WD, English::NONSENSE, English::NOTHING, English::NOTHING_TO_REPEAT, English::NOTHING__TX, English::NOT_HELD, English::NO_MULTIPLES, English::NO_OBJECT, English::NUMBER_UNRECOGNIZED, English::NumbersLanguage, English::OF1__WD, English::OF2__WD, English::OF3__WD, English::OF4__WD, English::OOPS1__WD, English::OOPS2__WD, English::OOPS3__WD, English::OR__TX, English::OTHER1__WD, English::OTHER2__WD, English::OTHER3__WD, English::PARTIALLY_UNDERSTOOD, English::PKEY1__KY, English::PKEY2__KY, English::PKEY__TX, English::Prepositions, English::QKEY1__KY, English::QKEY1__TX, English::QKEY2__KY, English::QKEY2__TX, English::QUIT1__WD, English::QUIT2__WD, English::REPEATED_ORDER, English::RESTART__WD, English::RESTORE__WD, English::RKEY__TX, English::SCENERY_IS_IRRELEVANT, English::SCORE__TX, English::SPEECH_THERAPY, English::THAT__TX, English::THEN1__WD, English::THEN2__WD, English::THEN3__WD, English::THOSET__TX, English::TIME__TX, English::TOOFEW, English::TOOLITTLE, English::TOOMANY, English::TREE_ERROR, English::UNDO1__WD, English::UNDO2__WD, English::UNDO3__WD, English::UNEXPECTED_COMMA, English::UNRECOGNIZED, English::VAGUE, English::WHICH__TX, English::WHOM__TX, English::YES1__WD, English::YES2__WD, English::YES3__WD, English::YOU2__TX, English::YOUR2__TX, English::YOURSELF__TX, English::YOUR__TX, English::YOU__TX
Class Method Summary
collapse
Instance Method Summary
collapse
-
#AddToScope(obj) ⇒ Object
-
#Adjudicate(context) ⇒ Object
—————————————————————————- The Adjudicate routine tries to see if there is an obvious choice, when faced with a list of objects (the match_list) each of which matches the player’s specification equally well.
-
#AdjustLight(flag = false) ⇒ Object
—————————————————————————-.
-
#AnalyseToken(token) ⇒ Object
-
#BestGrammar(grammars) ⇒ Object
—————————————————————————— Grammar selection ——————————————————————————.
-
#BestGuess ⇒ Object
—————————————————————————- BestGuess makes the best guess it can out of the match list, assuming that everything in the match list is textually as good as everything else; however it ignores items marked as -1, and so marks anything it chooses.
-
#CantSee ⇒ Object
—————————————————————————- The CantSee routine returns a good error number for the situation where the last word looked at didn’t seem to refer to any object in context.
-
#Cap(str, nocaps = false) ⇒ Object
-
#CDefart(o) ⇒ Object
-
#Centre(a, b) ⇒ Object
new_line if flag == false && (obj.&prop) == WORDSIZE && metaclass(obj.prop) == String return end.
-
#ChangePlayer(obj) ⇒ Object
-
#CInDefArt(o) ⇒ Object
-
#Conversation ⇒ Object
NextWord nudges the word number wn on by one each time, so we’ve now advanced past a comma.
-
#Conversation2 ⇒ Object
-
#CreatureTest(obj) ⇒ Object
—————————————————————————- CreatureTest: Will this person do for a “creature” token? —————————————————————————-.
-
#DebugAction(a) ⇒ Object
-
#DebugAttribute(a, anames = []) ⇒ Object
rubocop: disable Lint/UnusedMethodArgument.
-
#DebugGrammarLine(line) ⇒ Object
rubocop: enable Lint/UnusedMethodArgument.
-
#DebugToken(token) ⇒ Object
-
#Defart(o) ⇒ Object
-
#Descriptors ⇒ Object
TODO: FIXME 2021-08-01 This appears to be broken and advances the word number when not appropriate.
-
#DontAccept(domain, nosearch = nil, context = nil) ⇒ Object
-
#DoOops ⇒ Object
-
#DoScopeAction(thing, scope_reason = @scope_reason) ⇒ Object
-
#DrawStatusLine ⇒ Object
TODO: Fix, and extend in zmud with full telnet protocol support.
-
#FailToken(desc_wn, prev_indef_wanted) ⇒ Object
-
#FreshInput ⇒ Object
TODO: Port for completeness; likely won’t use.
-
#GetGender(person) ⇒ Object
—————————————————————————- GetGender returns 0 if the given animate object is female, and 1 if male (not all games will want such a simple decision function!) —————————————————————————-.
-
#GetGNAOfObject(obj, gna = 0, gender = nil) ⇒ Object
-
#HasLightSource(i) ⇒ Object
-
#HidesLightSource(obj) ⇒ Object
-
#Identical(o1, o2) ⇒ Object
—————————————————————————- Identical decides whether or not two objects can be distinguished from each other by anything the player can type.
-
#Incomplete(ambiguity = @ambiguity) ⇒ Object
-
#Indefart(o) ⇒ Object
-
#initialize_state ⇒ Object
-
#IsSeeThrough(o) ⇒ Object
—————————————————————————- IsSeeThrough is used at various places: roughly speaking, it determines whether o being in scope means that the contents of o are in scope.
-
#Keyboard ⇒ Object
-
#KeyboardPrimitive ⇒ Object
—————————————————————————- The Keyboard routine actually receives the player’s words, putting the words in “a_buffer” and their dictionary addresses in “a_table”.
-
#KeyCharPrimitive ⇒ Object
-
#KeyDelay ⇒ Object
-
#KeyTimerInterrupt ⇒ Object
-
#LanguageVerb(i) ⇒ Object
-
#LookForMore ⇒ Object
At this point, the return value is all prepared, and we are only looking to see if there is a “then” followed by subsequent instruction(s).
-
#LowerCase(c) ⇒ Object
rubocop: disable Lint/DuplicateMethods.
-
#MakeMatch(obj, quality, scope_reason = @scope_reason) ⇒ Object
—————————————————————————- MakeMatch looks at how good a match is.
-
#MakeMatchByParseName(obj, threshold, scope_reason = @scope_reason) ⇒ Object
-
#MultiAdd(o) ⇒ Object
—————————————————————————- The MultiAdd routine adds object “o” to the multiple-object-list.
-
#MultiFilter(attribute) ⇒ Object
—————————————————————————- The MultiFilter routine goes through the multiple-object-list and throws out anything without the given attribute “attribute” set.
-
#MultiSub(o) ⇒ Object
—————————————————————————- The MultiSub routine deletes object “o” from the multiple-object-list.
-
#NextWord ⇒ Object
—————————————————————————- NextWord (which takes no arguments) returns:.
-
#NextWordStopped ⇒ Object
-
#NounDomain(domain1, domain2 = nil, context = nil, scope_reason = @scope_reason) ⇒ Object
—————————————————————————- NounDomain does the most substantial part of parsing an object name.
-
#NounWord ⇒ Object
—————————————————————————- NounWord (which takes no arguments) returns:.
-
#NoWordsMatch(obj) ⇒ Object
-
#NumberWord(o) ⇒ Object
-
#OffersLight(i) ⇒ Object
-
#Parser__parse ⇒ Object
-
#ParseToken(given_ttype, given_tdata, token_n, token) ⇒ Object
rubocop: disable Layout/EmptyLinesAroundBlockBody.
-
#PassToken(many_flag, single_object, token, desc_wn, prev_indef_wanted) ⇒ Object
rubocop: enable Layout/EmptyLinesAroundBlockBody end of ParseToken.
-
#PlaceInScope(thing, scope_reason = @scope_reason) ⇒ Object
—————————————————————————- PlaceInScope is provided for routines outside the library, and is not called within the parser (except for debugging purposes).
-
#PrefaceByArticle(o, acode, pluralise = false, capitalise = false) ⇒ Object
-
#PrepositionChain(wd, index) ⇒ Object
-
#PrintCapitalised(obj, prop = nil, flag = true, nocaps = false, centred = false) ⇒ Object
rubocop: enable Lint/DuplicateMethods.
-
#PrintCommand(from = 0) ⇒ Object
def PrintInferredCommand(from = nil) singleton_noun = false if from != 0 && from == @pcount-1 && @pattern.object? # && @pattern < REPARSE_CODE singleton_noun = true end if singleton_noun == true BeginActivity(CLARIFYING_PARSERS_CHOICE_ACT, @pattern) if ForActivity(CLARIFYING_PARSERS_CHOICE_ACT, @pattern) == 0 print “(”; PrintCommand(from); print “)^” end EndActivity(CLARIFYING_PARSERS_CHOICE_ACT, @pattern) else print “(”; PrintCommand(from); print “)^” end end.
-
#PrintVerb(i) ⇒ Object
-
#PronounNotice(obj) ⇒ Object
def PronounOldEnglish SetPronoun(‘it’, @itobj) if @itobj != @old_itobj SetPronoun(‘him’, @himobj) if @himobj != @old_himobj SetPronoun(‘her’, @herobj) if @herobj != @old_herobj @old_itobj = @itobj; @old_himobj = @himobj; @old_herobj = @herobj; end.
-
#PronounsSub ⇒ Object
.
-
#PronounValue(dword) ⇒ Object
-
#PSN__(o) ⇒ Object
-
#Refers(obj, wnum) ⇒ Object
—————————————————————————- Refers works out whether the word at number wnum can refer to the object obj, returning true or false.
-
#ResetDescriptors ⇒ Object
OTHER_BIT = 1 # These will be used in Adjudicate() MY_BIT = 2 # to disambiguate choices THAT_BIT = 4 PLURAL_BIT = 8 LIT_BIT = 16 UNLIT_BIT = 32.
-
#ResetVagueWords(obj) ⇒ Object
-
#ReviseMulti(second_p) ⇒ Object
—————————————————————————- ReviseMulti revises the multiple object which already exists, in the light of information which has come along since then (i.e., the second parameter).
-
#ScopeCeiling(person) ⇒ Object
-
#ScopeWithin(domain, nosearch = nil, context = nil, scope_reason = @scope_reason) ⇒ Object
—————————————————————————- ScopeWithin looks for objects in the domain which make textual sense and puts them in the match list.
-
#ScopeWithin_O(domain, nosearch = nil, context = nil, scope_reason = @scope_reason) ⇒ Object
-
#ScoreMatchL(context, match_list = [], match_scores = [], number_matched = 0, threshold = 0) ⇒ Object
—————————————————————————- ScoreMatchL scores the match list for quality in terms of what the player has vaguely asked for.
-
#ScreenWidth ⇒ Object
—————————————————————————- Miscellaneous display routines used by DrawStatusLine and available for user.
-
#SearchScope(domain1, domain2 = nil, context = nil, scope_reason = @scope_reason) ⇒ Object
TODO: 2021-07-21 I think that SearchScope is a little bit broken right now, particularly for reactions, i.e.: in the reacts_to?(action) code path.
-
#selfobj ⇒ Object
-
#selfobj=(o) ⇒ Object
-
#SetPronoun(dword, value) ⇒ Object
-
#ShowobjSub ⇒ Object
-
#ShowVerbSub ⇒ Object
(also: #ShowverbSub)
def DebugGrammarLine(line) print “ * ” print “%s ” % [line.join(‘ ’)] unless line.empty? print “-> #lineline.action” print ‘ reverse’ if line.reverse? end.
-
#SingleBestGuess ⇒ Object
—————————————————————————- SingleBestGuess returns the highest-scoring object in the match list if it is the clear winner, or returns -1 if there is no clear winner —————————————————————————-.
-
#thedark ⇒ Object
-
#TraceAction(source, ar) ⇒ Object
-
#TryGivenObject(obj) ⇒ Object
—————————————————————————- TryGivenObject tries to match as many words as possible in what has been typed to the given object, obj.
-
#TryNumber(wordnum) ⇒ Object
—————————————————————————- Try to get a number out of the word at the given index —————————————————————————-.
-
#UnpackGrammarLine(line) ⇒ Object
-
#UpperCase(c) ⇒ Object
-
#UserFilter(obj) ⇒ Object
—————————————————————————- The UserFilter routine consults the user’s filter (or checks on attribute) to see what already-accepted nouns are acceptable —————————————————————————-.
-
#VerbAccepted ⇒ Object
D: Get the verb: try all the syntax lines for that verb.
-
#WhichOne(ambiguity = @ambiguity) ⇒ Object
-
#WordAddress(wordnum) ⇒ Object
-
#WordCount ⇒ Object
-
#WordInProperty(wd, obj, prop) ⇒ Object
-
#WordLength(wordnum) ⇒ Object
Methods included from Verbs
#AllowPushDir, #AnswerSub, #ArrivalDir, #AskForSub, #AskSub, #AskToSub, #AttackSub, #AttemptToTakeObject, #Banner, #BlowSub, #BurnSub, #BuySub, #ClimbSub, #CloseSub, #CommonAncestor, #ConsultSub, #CutSub, #DigSub, #DisrobeSub, #DrinkSub, #DropSub, #EatSub, #EconomyVersion, #EmptySub, #EmptyTSub, #EnterSub, #ExamineSub, #ExitSub, #FillSub, #FindVisibilityLevels, #GetOffSub, #GiveRSub, #GiveSub, #GoInSub, #GoSub, #GonearSub, #GotoSub, #IndirectlyContains, #InsertSub, #InvSub, #InvTallSub, #InvWideSub, #JumpOverSub, #JumpSub, #KissSub, #LMode1Sub, #LMode2Sub, #LMode3Sub, #ListEqual, #ListenSub, #Locale, #LockSub, #LookSub, #LookUnderSub, #MildSub, #MoveFloatingObjects, #MovePlayer, #NextEntry, #NoSub, #NotSupportingThePlayer, #NoteArrival, #NotifyOffSub, #NotifyOnSub, #ObjectIsUntouchable, #ObjectScopedBySomething, #ObjectsSub, #OpenSub, #Places1Sub, #PlacesSub, #PlayerTo, #PraySub, #Print_ScL, #Print__Spaces, #PullSub, #PushDirSub, #PushSub, #PutOnSub, #QuitSub, #RMaybe, #RemoveSub, #RestartSub, #RestoreSub, #RubSub, #RunTimeError, #SMaybe, #SaveSub, #SayWhatsOn, #ScopeSub, #ScoreArrival, #SearchSub, #SetSub, #SetToSub, #ShowRSub, #ShowSub, #SingSub, #SleepSub, #SmellSub, #SorrySub, #SortOutList, #SortTogether, #SqueezeSub, #StrongSub, #SwimSub, #SwingSub, #SwitchoffSub, #SwitchonSub, #TakeSub, #TasteSub, #TellSub, #ThinkSub, #ThrowAtSub, #TieSub, #TouchSub, #TransferSub, #TurnSub, #UnlockSub, #VagueGoSub, #VerifySub, #VersionSub, #VisibleContents, #Vmaybe, #Vwrong, #WaitSub, #WakeOtherSub, #WakeSub, #WaveHandsSub, #WaveSub, #WearSub, #WillRecurs, #WriteAfterEntry, #WriteBeforeEntry, #WriteListFrom, #WriteListR, #XAbstractSub, #XObj, #XPurloinSub, #XTestMove, #XTreeSub, #YesOrNo, #YesSub, #task_done, #task_scores
Methods included from English
#CThatorThose, #CTheyreorThats, #IsorAre, #ItorThem, #LanguageContraction, #LanguageDirection, #LanguageNumber, #LanguageTimeOfDay, #LanguageToInformese, #LanguageVerbIsDebugging, #LanguageVerbLikesAdverb, #LanguageVerbMayBeName, #ThatorThose, #language_lm, #library_messages
Class Method Details
.initial_state ⇒ Object
549
550
551
552
553
|
# File 'lib/inform/parserm.h.rb', line 549
def self.initial_state
InitalState.memo ||= Inform::Parser.instance_variables.each_with_object({}) do |variable, memo|
memo[variable] = Inform::Parser.instance_variable_get(variable)
end
end
|
Instance Method Details
#AddToScope(obj) ⇒ Object
3751
3752
3753
3754
3755
3756
|
# File 'lib/inform/parserm.h.rb', line 3751
def AddToScope(obj)
ScopeWithin_O(obj, nil, @ats_flag) if @ats_flag
if @ats_flag.nil?
@ats_hls = true if HasLightSource(obj)
end
end
|
#Adjudicate(context) ⇒ Object
The Adjudicate routine tries to see if there is an obvious choice, when
faced with a list of objects (the match_list) each of which matches the
player's specification equally well.
To do this it makes use of the context (the token type being worked on).
It counts up the number of obvious choices for the given context
(all to do with where a candidate is, except for 6 (animate) which is to
do with whether it is animate or not);
if only one obvious choice is found, that is returned;
if we are in indefinite mode (don't care which) one of the obvious choices
is returned, or if there is no obvious choice then an unobvious one is
made;
at this stage, we work out whether the objects are distinguishable from
each other or not: if they are all indistinguishable from each other,
then choose one, it doesn't matter which;
otherwise, 0 (meaning, unable to decide) is returned (but remember that
the equivalence classes we've just worked out will be needed by other
routines to clear up this mess, so we can't economise on working them
out).
Returns -1 if an error occurred
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
|
# File 'lib/inform/parserm.h.rb', line 2835
def Adjudicate(context)
@match_scores ||= []
@match_scores.clear
@match_classes ||= []
@match_classes.clear
if defined?(DEBUG)
if @parser_trace >= 4
print " [Adjudicating match list of size #{@number_matched} in context #{context}\n"
print " "
if @indef_mode
print "indefinite type: "
print "other " if (@indef_type & OTHER_BIT) != 0
print "my " if (@indef_type & MY_BIT) != 0
print "that " if (@indef_type & THAT_BIT) != 0
print "plural " if (@indef_type & PLURAL_BIT) != 0
print "lit " if (@indef_type & LIT_BIT) != 0
print "unlit " if (@indef_type & UNLIT_BIT) != 0
print "owner:" + @indef_owner.name if @indef_owner
new_line
print " number wanted: "
if @indef_wanted == Integer::MAX then print "all" else print @indef_wanted end
new_line
print " most likely GNAs of names: #{@indef_cases}\n";
else print "definite object\n"
end
end
end
j = @number_matched - 1; good_ones = 0; last = @match_list.length;
for n in @match_list
i = @match_list.index n
@match_scores[i] = 0
good_flag = false
case context
when :held, :multiheld
good_flag = true if parent(n) == @actor
when :multiexcept
if @advance_warning == -1
good_flag = true
else
good_flag = true if n != @advance_warning
end
when :multiinside
if @advance_warning == -1
good_flag = true if parent(n) != @actor
else
good_flag = true if @advance_warning.include?(n)
end
when :creature
good_flag = true if CreatureTest(n)
else
good_flag = true
end
if good_flag
@match_scores[i] = SCORE__IFGOOD
good_ones += 1; last = n
end
end
return last if good_ones == 1
return @match_list.first if context == :creature && good_ones == 0
@indef_type = 0 if @indef_mode == false
@match_list, @match_scores, @number_matched = ScoreMatchL(
context, @match_list, @match_scores, @number_matched)
raise NoMatchesAvailable if @number_matched == 0
if @indef_mode == false
i = SingleBestGuess()
unless i.nil?
if defined?(DEBUG)
println " Single best-scoring object returned.]" if @parser_trace >= 4
end return i
end
end
if @indef_mode && (@indef_type & PLURAL_BIT) != 0
unless %i[multi multiheld multiexcept multiinside].include?(context)
@etype = UnexpectedMultiple
return -1
end
loop do
j = BestGuess()
break if j == -1
if defined?(DEBUG) && @scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>In Adjudicate..."
println ">>...Best guess is #{j}"
println ">>...Action to be is #{@action_to_be}"
end
flag = 0
flag = 1 if j.hasnt? :concealed, :worn
flag = 0 if parent(j) != @actor && %i[multiheld multiexcept].include?(context)
if parent(j) == @actor && (@action_to_be == :Take || @action_to_be == :Remove)
flag = 0
end
if defined?(DEBUG) && @scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Choosing objects..."
println ">>...Object is #{j}"
println ">>...Parser preference is to " + (flag == 0 ? "reject" : "accept") + "."
end
k = ChooseObjects(j, flag)
if k == 1
flag = 1
else
flag = 0 if k == 2
end
if flag > 0
@multiple_object << j
if defined?(DEBUG)
println " Accepting it" if @parser_trace >= 4
end else
if defined?(DEBUG)
println " Rejecting it" if @parser_trace >= 4
end end
end
if @multiple_object.length < @indef_wanted && @indef_wanted < Integer::MAX
@etype = TooFew; @multi_wanted = @indef_wanted
@multi_had = @multiple_object.length
raise NoMatchesAvailable
end
@multi_context = context
if defined?(DEBUG)
println " Made multiple object of size #{@multiple_object.length}]" if @parser_trace >= 4
end return 1
end
@match_classes.fill(0, 0...@number_matched)
n = 1
for i in (0...@number_matched)
next unless @match_classes[i] == 0
@match_classes[i] = n; n += 1; flag = 0
for j in ((i + 1)...@number_matched)
next unless @match_classes[j] == 0
next unless Identical(@match_list[i], @match_list[j])
flag = 1
@match_classes[j] = @match_classes[i]
end
@match_classes[i] = 1 - n if flag > 0
end
n -= 1; @number_of_classes = n
if defined?(DEBUG) && @scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>In Adjudicate match classes are #{@match_classes.inspect}"
println ">>...@number_matched is #{@number_matched}"
end
if defined?(DEBUG)
if @parser_trace >= 4
println " Grouped into #{n} possibilities by name:"
for i in (0...@number_matched)
if @match_classes[i] > 0
print " " + The(@match_list[i]) + " (#{@match_list[i].object_id}) --- group #{@match_classes[i]}\n"
end
end
end
end
unless @indef_mode
if n > 1
k = -1
for i in (0...@number_matched)
if @match_scores[i] > k
k = @match_scores[i]
j = @match_classes[i]; j = j * j
flag = 0
elsif @match_scores[i] == k
if @match_classes[i] * @match_classes[i] != j
flag = 1
end
end
end
if flag > 0
if defined?(DEBUG)
println " Unable to choose best group, so ask player.]" if @parser_trace >= 4
end return 0
end
if defined?(DEBUG)
println " Best choices are all from the same group." if @parser_trace >= 4
end end end
@dont_infer = true if n == 1
return BestGuess()
end
|
#AdjustLight(flag = false) ⇒ Object
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
|
# File 'lib/inform/parserm.h.rb', line 4195
def AdjustLight(flag = false)
i = @lightflag
@lightflag = OffersLight(parent(@player))
if (i.nil? || i == false) && @lightflag
@location = @real_location
log.debug "Looking after light adjustment for #{@player}" return _invoke :Look unless flag
end
if !i.nil? && !@lightflag
@real_location = @location; @location = thedark
unless flag
NoteArrival()
return L__M(:Miscellany, 9)
end
end
@location = thedark if !i.nil? && !@lightflag
end
|
#AnalyseToken(token) ⇒ Object
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/inform/parserm.h.rb', line 187
def AnalyseToken(token)
@found_tdata = token
if token.nil? then @found_ttype = :illegal; return; end
if token.is_a?(Symbol) && Inform.attributes.include?(token)
@found_ttype = :attribute_filter
return
end
case token
when /^scope=(.*)$/
@found_ttype = :scope
@found_tdata = $LAST_MATCH_INFO[1]
when /^.*=(.*)$/
@found_ttype = :routine_filter
@found_tdata = $LAST_MATCH_INFO[1]
when /^'.*'$/
@found_ttype = :preposition
@found_tdata = token
when /^(#{ElementaryTokens.join('|')})$/
@found_ttype = token
else
@found_ttype = :general_parse_routine
@found_tdata = token
end
nil
end
|
#BestGrammar(grammars) ⇒ Object
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
|
# File 'lib/inform/parserm.h.rb', line 1221
def BestGrammar(grammars)
@best_grammar = nil
if grammars.first.empty?
if num_words == 1
@results = [grammars.first.action, 0, nil, nil]
@best_grammar = grammars.first
return true
elsif num_words > 1
raise PartiallyUnderstood if grammars.empty?
end
grammars = grammars[1..]
end
for grammar in grammars
line = grammars.index(grammar)
grammar = UnpackGrammarLine(grammar)
if defined?(DEBUG)
if @parser_trace >= 1
new_line if @parser_trace >= 2
print "[line #{line}"; DebugGrammarLine(grammar)
println "]"
end
end
@not_holding = nil
@inferfrom = 0
@parameters = 0
@nsns = 0; @special_word = nil; @special_number = 0
@multiple_object ||= []
@multiple_object.clear
@multi_context = nil
@etype = CannotUnderstandSentence
@wn = @verb_wordnum + 1
@advance_warning = nil; @indef_mode = false
i = 0; m = false; @pcount = 0
while @line_token[@pcount] != :end
@scope_token = nil
i += 1 if @line_ttype[@pcount] != :preposition
if ElementaryTokens.include? @line_token[@pcount]
m = true if @line_token[@pcount] == :multi
cur_line_token = @line_token[@pcount]
if i == 1 && %i[multiexcept multiinside].include?(cur_line_token)
if defined?(DEBUG)
println " [Trying look-ahead]" if @parser_trace >= 2
end
@pcount += 1
if @line_ttype[@pcount] == :preposition
prepositions = @line_token[@pcount].split(/\//).map { |s| s[1..-2] }
@pcount += 1 while @line_ttype[@pcount] == :preposition
if ElementaryTokens.include?(@line_ttype[@pcount]) && @line_tdata[@pcount] == :noun
while @wn < num_words
l = NextWord()
if prepositions.include?(l) next if [ALL1__WD, ALL2__WD, ALL3__WD, ALL4__WD, ALL5__WD].include?(l)
l = Descriptors() @etype = l if l != 0 || l != false l = NounDomain(@actors_location, @actor, :noun)
if defined?(DEBUG)
if @parser_trace >= 2
print " [Advanced to \"noun\" token: "
println "re-parse request]" if l == REPARSE_CODE
println "but multiple found]" if [1, true].include?(l) println "error #{etype}]" if [0, true].include?(l) println the(l) + "]" if l.object?
end
end throw :ReParse if l == REPARSE_CODE
@advance_warning = l if l.object?
end
end
end
end
break
end
end
@pcount += 1
end
if !m.nil? && @params_wanted == 1 && @action_to_be == :Take
@take_all_rule = 1
end
@not_holding = nil
@inferfrom = 0
@parameters = 0
@nsns = 0; @special_word = nil; @special_number = 0
@multiple_object ||= []
@multiple_object.clear
@etype = CannotUnderstandSentence
@wn = @verb_wordnum + 1
@pattern2 ||= []
@pattern2.clear
@pattern2 << @pattern.first
@pcount = 1
loop do
@pattern = @pattern[0...@pcount]
token = grammar[@pcount - 1]
@lookahead = grammar[@pcount]
if defined?(DEBUG)
if @parser_trace >= 2
println " [line #{line} token #{@pcount} word #{@wn + 1} : #{token}]"
end
end
if token != :end
@scope_reason = PARSING_REASON
AnalyseToken(token)
@line_ttype[grammar.index(token)] = @found_ttype
if defined?(DEBUG) && @parser_trace >= 10
new_line
println "Parsing the current word '#{current_word}' as a #{@found_ttype} in this grammar:"
println grammar.to_s
println ">>Before invoking ParseToken(#{@found_ttype})..."
println ">>...The found token data is #{@found_tdata}"
println ">>...The current word number is #{@wn + 1}"
println ">>...The current word is '#{current_word}'"
println ">>...The pattern is #{@pattern}"
println ">>...The pattern count is at #{@pcount}"
end
l = ParseToken(@found_ttype, @found_tdata, @pcount - 1, token)
@scope_reason = PARSING_REASON
if l == GPR_PREPOSITION
if @found_ttype != :preposition
if !ElementaryTokens.include?(@found_ttype) || @found_tdata != :topic
@params_wanted -= 1
end
end
l = true
elsif l == GPR_TEXT
@parameters += 1
@pattern[@pcount] = @consult_words
l = true
elsif l == false
elsif l != GPR_REPARSE
if l == GPR_NUMBER
if @nsns == 0 then @special_number1 = @parsed_number
else @special_number2 = @parsed_number
end
@nsns += 1; l = 1
end
l = 0 if l == GPR_MULTIPLE
@results[@parameters + 2] = l
@parameters += 1
@pattern[@pcount] = l
l = true
end
if defined?(DEBUG) && @parser_trace >= 10
println ">>After invoking ParseToken..."
println ">>...The current word number is #{@wn + 1}"
println ">>...The current word is '#{current_word}'"
println ">>...The found token type is #{@found_ttype}"
println ">>...The result is " + a(l.class) + " called '#{l}'" if l.object?
println ">>...The parsed number is #{@parsed_number}" if @parsed_number
println ">>...The pattern is #{@pattern}"
println ">>...The pattern count is at #{@pcount}"
println ">>...The etype is #{@etype}"
end
if defined?(DEBUG)
if @parser_trace >= 3
print " [token resulted in "
print "re-parse request]\n" if l == REPARSE_CODE
print "failure with error type #{@etype}]\n" unless l
print "success]\n" if l
end
end
next if l == REPARSE_CODE
break if l == false
else
if @wn < num_words
NextWord()
if [THEN1__WD, THEN2__WD, THEN3__WD].include?(current_word)
@held_back_mode = true; @hb_wn = @wn - 1
else
@pattern2 = @pattern.dup
@pcount2 = @pcount
@best_etype = @etype = PartiallyUnderstood
break
end
end
if @parameters >= 1 && @results[2] == 0
l = ReviseMulti(@results[3])
if l then @etype = l; @results[0] = @action_to_be; break; end
end
if @parameters >= 2 && @results[3] == 0
l = ReviseMulti(@results[2])
if l then @etype = l; break; end
end
if @take_all_rule == 2 && @results[3] == @actor
@best_etype = NothingMatched
raise @best_etype
end
if defined?(DEBUG)
println "[Line successfully parsed]" if @parser_trace >= 1
end
@oops_from = 0
if @inferfrom != 0
print "("; PrintCommand(@inferfrom); print ")\n"
end
@results[0] = @action_to_be
@results[1] = @parameters
if @action_reversed && @parameters > 1
@results[2], @results[3] = @results[3], @results[2]
if @nsns == 2
@special_number1, @special_number2 = @special_number2, @special_number1
end
end
PronounNotice(@results[2]) if @parameters > 0 && @results[2].object?
if @not_holding && @actor == @player
@action = :Take
i = RunRoutines(@not_holding, :before_implicit)
if i > 2 then @best_etype = NotHeld; raise @best_etype end
if i < 2 if i != 1 println L__M(:Miscellany, 26, @not_holding)
end
@notheld_mode = true
@kept_results = @results.dup
@results[0] = :Take
@results[1] = 1
@results[2] = @not_holding
end
end
if @held_back_mode
@wn = @hb_wn
return LookForMore()
end
@best_grammar = grammar
return true
end @pcount += 1
end
@best_etype = @etype if @etype > @best_etype
@nextbest_etype = @etype if @etype != AskScope && !@etype.nil? && @etype > @nextbest_etype
break if @take_all_rule == 2 && @etype == NothingMatched
end
if defined?(DEBUG) && @parser_trace >= 10
println ">>@etype is #{@etype}"
println ">>@best_etype is #{@best_etype}"
end @etype = @best_etype
@pronoun_word = @pronoun__word; @pronoun_obj = @pronoun__obj
raise @etype
return true
end
|
#BestGuess ⇒ Object
BestGuess makes the best guess it can out of the match list, assuming that
everything in the match list is textually as good as everything else;
however it ignores items marked as -1, and so marks anything it chooses.
It returns -1 if there are no possible choices.
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
|
# File 'lib/inform/parserm.h.rb', line 3201
def BestGuess
earliest = 0; best = -1
for i in (0...@number_matched)
if @match_list[i]
its_score = @match_scores[i]
if its_score > best then best = its_score; earliest = i; end
end
end
if defined?(DEBUG)
if @parser_trace >= 4
if best < 0 then println " Best guess ran out of choices"
else println " Best guess " + the(@match_list[earliest]) + " (#{@match_list[earliest]})"
end
end
end return -1 if best < 0
i = @match_list[earliest]
@match_list.delete_at earliest
@bestguess_score = best
if !i.object?
println "****"
println "BestGuess i is not an object! #=> #{i}"
println "****"
end
return i
end
|
The CantSee routine returns a good error number for the situation where
the last word looked at didn't seem to refer to any object in context.
The idea is that: if the actor is in a location (but not inside something
like, for instance, a tank which is in that location) then an attempt to
refer to one of the words listed as meaningful-but-irrelevant there
will cause "you don't need to refer to that in this game" rather than
"no such thing" or "what's 'it'?".
(The advantage of not having looked at "irrelevant" local nouns until now
is that it stops them from clogging up the ambiguity-resolving process.
Thus game objects always triumph over scenery.)
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
|
# File 'lib/inform/parserm.h.rb', line 3386
def CantSee
@saved_oops = @oops_from
if @scope_token
@scope_error = @scope_token
return AskScope
end
@wn -= 1; w = NextWord()
e = CantSeeError
if !w.nil? && w == @pronoun_word
@pronoun__word = @pronoun_word; @pronoun__obj = @pronoun_obj
e = ItGone
end
e
end
|
#Cap(str, nocaps = false) ⇒ Object
4652
4653
4654
4655
4656
|
# File 'lib/inform/parserm.h.rb', line 4652
def Cap(str, nocaps = false)
if nocaps then print str.to_s
else PrintCapitalised(str)
end
end
|
#CDefart(o) ⇒ Object
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
|
# File 'lib/inform/parserm.h.rb', line 4802
def CDefart(o)
if defined?(YOU__TX)
if o == @player
print YOU__TX
return true
end
end
i = @indef_mode; @indef_mode = false;
if !o.object? || o.has?(:proper)
@indef_mode = false; print PSN__(o); @indef_mode = i
return true
end
PrefaceByArticle(o, 0); @indef_mode = i;
end
|
#Centre(a, b) ⇒ Object
new_line if flag == false && (obj.&prop) == WORDSIZE && metaclass(obj.prop) == String
return
end
4648
4649
4650
|
# File 'lib/inform/parserm.h.rb', line 4648
def Centre(a, b)
PrintCapitalised(a, b, false, true, true)
end
|
#ChangePlayer(obj) ⇒ Object
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
|
# File 'lib/inform/parserm.h.rb', line 4257
def ChangePlayer(obj)
@actor = obj if @actor == @player
@player = obj
@player.short_name = nil if @player == selfobj
i = @player; i = parent(i) until parent(i).nil?
@location = i; @real_location = @location
return RunTimeError(10) unless parent(@player)
@lightflag = OffersLight(parent(@player))
@location = thedark unless @lightflag
@print_player_flag = flag
end
|
#CInDefArt(o) ⇒ Object
4783
4784
4785
4786
4787
4788
4789
4790
4791
|
# File 'lib/inform/parserm.h.rb', line 4783
def CInDefArt(o)
i = @indef_mode; @indef_mode = true;
if o.has?(:proper) then @indef_mode = false; print PSN__(o); return; end
if o.respond_to? :article
PrintCapitalised(o, :article, true); print " " + PSN__(o); @indef_mode = i
return true
end
PrefaceByArticle(o, 2, false, true); @indef_mode = i
end
|
#Conversation ⇒ Object
NextWord nudges the word number wn on by one each time, so we’ve now advanced past a comma. (A comma is a word all on its own in the table.)
#Conversation2 ⇒ Object
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
|
# File 'lib/inform/parserm.h.rb', line 1170
def Conversation2
if l.hasnt? :animate, :talkable
raise InanimateAddressee
end
if @wn != j
raise SpeechImpediment
end
PronounNotice(l)
@verb_wordnum = j + 1
if l == @player
@wn = @verb_wordnum
if [AGAIN1__WD, AGAIN2__WD, AGAIN3__WD].include?(NextWordStopped())
L__M(:Miscellany, 20)
jump ReType
end
end
@actor = l
@actors_location = ScopeCeiling(l)
if defined?(DEBUG)
if @parser_trace >= 1
println "[Actor is " + the(actor) + " in " + @actors_location + "]"
end
end
BeginCommand()
end
|
#CreatureTest(obj) ⇒ Object
CreatureTest: Will this person do for a "creature" token?
1853
1854
1855
1856
1857
1858
1859
1860
1861
|
# File 'lib/inform/parserm.h.rb', line 1853
def CreatureTest(obj)
if defined?(DEBUG) && @parser_trace >= 10
println ">>Is #{obj} a creature?"
end return true if obj.has?(:animate)
return false if obj.hasnt?(:talkable)
return true if %i[Ask Answer Tell AskFor].include?(@action_to_be)
false
end
|
#DebugAction(a) ⇒ Object
4284
4285
4286
|
# File 'lib/inform/parserm.h.rb', line 4284
def DebugAction(a)
a.to_s
end
|
#DebugAttribute(a, anames = []) ⇒ Object
rubocop: disable Lint/UnusedMethodArgument
4293
4294
4295
4296
4297
4298
4299
4300
4301
|
# File 'lib/inform/parserm.h.rb', line 4293
def DebugAttribute(a, anames = [])
a.to_s
end
|
#DebugGrammarLine(line) ⇒ Object
rubocop: enable Lint/UnusedMethodArgument
4304
4305
4306
4307
4308
4309
4310
4311
4312
|
# File 'lib/inform/parserm.h.rb', line 4304
def DebugGrammarLine(line)
print " * "
for token in line[0..-2]
print DebugToken(token) + " "
end
print "-> " + DebugAction(@action_to_be)
print " reverse" if @action_reversed
end
|
#DebugToken(token) ⇒ Object
4288
4289
4290
|
# File 'lib/inform/parserm.h.rb', line 4288
def DebugToken(token)
token.to_s
end
|
#Defart(o) ⇒ Object
4793
4794
4795
4796
4797
4798
4799
4800
|
# File 'lib/inform/parserm.h.rb', line 4793
def Defart(o)
i = @indef_mode; @indef_mode = false;
if !o.object? || o.has?(:proper)
@indef_mode = false; print PSN__(o); @indef_mode = i
return true
end
PrefaceByArticle(o, 1); @indef_mode = i
end
|
#Descriptors ⇒ Object
TODO: FIXME 2021-08-01 This appears to be broken and advances the word number when not appropriate.
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
|
# File 'lib/inform/parserm.h.rb', line 1761
def Descriptors
ResetDescriptors()
return false if @wn > num_words
flag = true
while flag
o = NextWordStopped(); flag = false
if defined?(DEBUG) && @parser_trace >= 11
println ">>Descriptors next word stopped is '#{o}'"
end
if language_descriptors.keys.include? o
if defined?(DEBUG) && @parser_trace >= 11
println ">>The word '#{o}' is a language descriptor!"
end flag = true
type = language_descriptors[o][1]
@indef_mode = true if type != DEFART_PK
@indef_possambig = true
@indef_cases = @indef_cases & (language_descriptors[o][0])
if type == POSSESS_PK
cto = language_descriptors[o][2]
case cto
when 0 then @indef_type = @indef_type | MY_BIT
when 1 then @indef_type = @indef_type | THAT_BIT
else
@indef_owner = PronounValue(cto)
end
end
@indef_type = @indef_type | LIT_BIT if type == :light
@indef_type = @indef_type | UNLIT_BIT if type == :nolight
end
if [OTHER1__WD, OTHER2__WD, OTHER3__WD].include?(o)
@indef_mode = true
flag = true
@indef_type = @indef_type | OTHER_BIT
end
if [ALL1__WD, ALL2__WD, ALL3__WD, ALL4__WD, ALL5__WD].include?(o)
@indef_mode = true
flag = true
@indef_wanted = Integer::MAX
@take_all_rule = 2 if @take_all_rule == 1
@indef_type = @indef_type | PLURAL_BIT
end
if @allow_plurals
n = TryNumber(@wn - 1)
unless n.nil?
if n == 1
@indef_mode = true
flag = true
end
if n > 1
@indef_guess_p = true
@indef_mode = true
flag = true
@indef_wanted = n
@indef_nspec_at = @wn - 1
@indef_type = @indef_type | PLURAL_BIT
end
end
end
if flag == true && ![OF1__WD, OF2__WD, OF3__WD, OF4__WD].include?(NextWordStopped())
if defined?(DEBUG) && @parser_trace >= 11
println ">>Skipping 'of' after these"
end @wn -= 1 end
if defined?(DEBUG) && @parser_trace >= 11
println format(">>Is the word '#{o}' a descriptor? %s", flag ? 'yes' : 'no')
println ">>The @wn is: #{@wn}"
end end
@wn -= 1
if defined?(DEBUG) && @parser_trace >= 11
println ">>Descriptors returning false"
println ">>The @wn is: #{@wn}"
end
return false
end
|
#DontAccept(domain, nosearch = nil, context = nil) ⇒ Object
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
|
# File 'lib/inform/parserm.h.rb', line 3717
def DontAccept(domain, nosearch = nil, context = nil)
if domain.child && domain != nosearch && IsSeeThrough(domain)
ScopeWithin(domain, nosearch, context)
end
ad = domain.&:add_to_scope
unless ad.nil?
i = !ad.object?
if i == true
@ats_flag = context
RunRoutines(domain, :add_to_scope)
@ats_flag = nil
elsif ad.respond_to?(:each)
for additional in ad
ScopeWithin_O(additional, nil, context) unless additional.nil?
end
end
end
false
end
|
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
|
# File 'lib/inform/parserm.h.rb', line 722
def DoOops
if @oops_from == 0
L__M(:Miscellany, 14)
return FreshInput()
end
if nw == 1
L__M(:Miscellany, 15)
return FreshInput()
end
if nw > 2
L__M(:Miscellany, 16)
return FreshInput()
end
(o..INPUT_BUFFER_LEN).each { |i| buffer2[i] = a_buffer[i] }
if defined? TARGET_ZCODE
x1 = a_table[9] x2 = a_table[8] else x1 = a_table[6] x2 = a_table[5] end
64.times { |i| a_buffer[i] = oops_workspace[i] }
Tokenise__(a_buffer, a_table)
if defined? TARGET_ZCODE
w = a_table[(4 * oops_from) + 1] w2 = a_table[4 * oops_from] else w = a_table[3 * oops_from] w2 = a_table[(3 * oops_from) - 1] end
w2.times { |i| a_buffer[i + w] = ' ' }
if w2 < x2
i = INPUT_BUFFER_LEN - 1
while i >= w + x2
a_buffer[i] = a_buffer[i - x2 + w2]
i -= 1
end
if defined? TARGET_ZCODE
a_buffer[1] = a_buffer[1] + (x2 - w2)
else a_buffer[0] = a_buffer[0] + (x2 - w2)
end end
x2.times { |j| a_buffer[j + w] = @buffer2[j + x1] }
Tokenise__(a_buffer, a_table)
if defined? TARGET_ZCODE
nw = a_table[1]
else nw = a_table.length
end
return nw
end
|
#DoScopeAction(thing, scope_reason = @scope_reason) ⇒ Object
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
|
# File 'lib/inform/parserm.h.rb', line 3586
def DoScopeAction(thing, scope_reason = @scope_reason)
s = scope_reason; p1 = @parser_one
DidScopeAction[thing] ||= {}
DidScopeAction[thing][scope_reason] ||= 0
DidScopeAction[thing][scope_reason] += 1
if defined?(DEBUG)
println "DidScopeAction[#{thing}][#{scope_reason}]: #{DidScopeAction[thing][scope_reason]}"
if @parser_trace >= 6
println "[DSA on " + the(thing) + " with reason = " + scope_reason.to_s +
" p1 = #{@parser_one} p2 = #{@parser_two}]"
if name(thing) == 'Nels'
caller.each { |t| println t }
elsif DidScopeAction[thing][scope_reason] > 1
println "Did DoScopeAction(#{thing}) with reason = #{scope_reason} more than once!"
caller.each { |t| println t }
end
end
end case scope_reason
when REACT_BEFORE_REASON
return unless thing.react_before?(action)
if defined?(DEBUG)
println "[Considering react_before for " + the(thing) + "]" if @parser_trace >= 2
end
@parser_one ||= RunRoutines(thing, :react_before)
when REACT_AFTER_REASON
return unless thing.react_after?(action)
if defined?(DEBUG)
println "[Considering react_after for " + the(thing) + "]" if @parser_trace >= 2
end @parser_one ||= RunRoutines(thing, :react_after)
when EACH_TURN_REASON
return unless thing.respond_to? :each_turn
if defined?(DEBUG)
println "[Considering each_turn for " + the(thing) + "]" if @parser_trace >= 2
end PrintOrRun(thing, :each_turn)
when TESTSCOPE_REASON
@parser_two = 1 if thing == @parser_one
when LOOPOVERSCOPE_REASON
if @parser_one.is_a?(Proc)
@parser_one.call(thing)
elsif self.respond_to?(@parser_one)
self.send(@parser_one, thing)
end
@parser_one = p1
end
@scope_reason = s
end
|
#DrawStatusLine ⇒ Object
TODO: Fix, and extend in zmud with full telnet protocol support
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
|
# File 'lib/inform/parserm.h.rb', line 4483
def DrawStatusLine
end
|
#FailToken(desc_wn, prev_indef_wanted) ⇒ Object
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
|
# File 'lib/inform/parserm.h.rb', line 2443
def FailToken(desc_wn, prev_indef_wanted)
if @allow_plurals && @indef_guess_p
prev_indef_wanted = @indef_wanted
@allow_plurals = false
@wn = desc_wn
throw :TryAgain
end
ResetDescriptors()
@etype = UnexpectedMultiple if (@indef_wanted > 0 || prev_indef_wanted > 0) && !@multiflag
return GPR_FAIL
end
|
TODO: Port for completeness; likely won’t use
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
|
# File 'lib/inform/parserm.h.rb', line 608
def FreshInput
end
|
#GetGender(person) ⇒ Object
GetGender returns 0 if the given animate object is female, and 1 if male
(not all games will want such a simple decision function!)
4093
4094
4095
|
# File 'lib/inform/parserm.h.rb', line 4093
def GetGender(person)
person.hasnt?(:female)
end
|
#GetGNAOfObject(obj, gna = 0, gender = nil) ⇒ Object
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
|
# File 'lib/inform/parserm.h.rb', line 4097
def GetGNAOfObject(obj, gna = 0, gender = nil)
gna = 6 if obj.hasnt?(:animate)
gender = :male if obj.has?(:male)
gender = :female if obj.has?(:female)
gender = :neuter if obj.has?(:neuter)
if gender.nil?
gender = gna == 0 ? LanguageInanimateGender : LanguageAnimateGender
end
gna = gna + 1 if gender == :female
gna = gna + 2 if gender == :neuter
gna = gna + 3 if obj.has? :pluralname
return gna
end
|
#HasLightSource(i) ⇒ Object
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
|
# File 'lib/inform/parserm.h.rb', line 4234
def HasLightSource(i)
return false unless i
return true if i.has? :light
if (i.has?(:enterable) || IsSeeThrough(i)) && !HidesLightSource(i)
return true if i.any? { |j| HasLightSource(j) }
end
return true if i.has?(:animate) && i.any? { |j| HasLightSource(j) }
false
end
|
#HidesLightSource(obj) ⇒ Object
4227
4228
4229
4230
4231
4232
|
# File 'lib/inform/parserm.h.rb', line 4227
def HidesLightSource(obj)
return false if obj == @player
return false if obj.has? :transparent, :supporter
return obj.hasnt? :open if obj.has? :container
return obj.hasnt? :enterable
end
|
#Identical(o1, o2) ⇒ Object
Identical decides whether or not two objects can be distinguished from
each other by anything the player can type. If not, it returns true.
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
|
# File 'lib/inform/parserm.h.rb', line 3249
def Identical(o1, o2) return true if o1 == o2 return false if o1.nil? || o2.nil? return false if parent(o1) == Compass || parent(o2) == Compass
if o1.respond_to?(:parse_name) || o2.respond_to?(:parse_name)
return false if o1.&(:parse_name) != o2.&(:parse_name)
@parser_action = :TheSame; @parser_one = o1; @parser_two = o2
j = @wn; i = RunRoutines(o1, :parse_name); @wn = j;
return true if i == -1
return false if i == -2
end
return false if o1.name != o2.name
true
end
|
#Incomplete(ambiguity = @ambiguity) ⇒ Object
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
|
# File 'lib/inform/parserm.h.rb', line 2712
def Incomplete(ambiguity = @ambiguity)
@ambiguity = ambiguity
unless completing?
if @ambiguity.context == :creature
L__M(:Miscellany, 48)
else
L__M(:Miscellany, 49)
end
return complete
end
return println(L__M(:Miscellany, 10)) if @buffer.empty?
@words = @buffer.split
@verb = @words.first
@verb.downcase!
return completed if Inform::Grammar::Verbs.lookup @verb, @player
if @inferfrom != 0
for j in (@inferfrom...@pattern.length)
next unless @pattern[j]
if defined?(DEBUG)
println "[Gluing in inference with pattern code " + @pattern[j] + "]" if @parser_trace >= 5
end
if @pattern[j] && @pattern[j] != REPARSE_CODE
PronounNotice(@pattern[j])
for k in language_pronouns.keys
if @pattern[j] == language_pronouns[k][1]
@words[0] = language_pronouns[k]
if defined?(DEBUG)
println "[Using pronoun '" + @words.first + "']" if @parser_trace >= 5
end break
end
end
else
if defined?(DEBUG)
println "[Using preposition '" + @words.first + "']" if @parser_trace >= 5
end end
if @words.first
end
end
end
@input = (@pattern << @words).join(' ')
return completed
end
|
#Indefart(o) ⇒ Object
4773
4774
4775
4776
4777
4778
4779
4780
4781
|
# File 'lib/inform/parserm.h.rb', line 4773
def Indefart(o)
i = @indef_mode; @indef_mode = true
if o.has?(:proper) then @indef_mode = false; print PSN__(o); return; end
if o.respond_to? :article
PrintOrRun(o, :article, 1); print " " + PSN__(o); @indef_mode = i
return true
end
PrefaceByArticle(o, 2); @indef_mode = i
end
|
#initialize_state ⇒ Object
555
556
557
558
559
560
|
# File 'lib/inform/parserm.h.rb', line 555
def initialize_state
DidScopeAction.clear Inform::Parser.initial_state.each_pair do |k, v|
self.instance_variable_set(k, v)
end
end
|
#IsSeeThrough(o) ⇒ Object
IsSeeThrough is used at various places: roughly speaking, it determines
whether o being in scope means that the contents of o are in scope.
3564
3565
3566
|
# File 'lib/inform/parserm.h.rb', line 3564
def IsSeeThrough(o)
o.hasany?(:supporter, :transparent) || o.has?(:open, :container)
end
|
601
602
603
604
605
|
# File 'lib/inform/parserm.h.rb', line 601
def Keyboard
DisplayStatus()
FreshInput()
end
|
#KeyboardPrimitive ⇒ Object
The Keyboard routine actually receives the player's words,
putting the words in "a_buffer" and their dictionary addresses in
"a_table". It is assumed that the table is the same one on each
(standard) call.
It can also be used by miscellaneous routines in the game to ask
yes-no questions and the like, without invoking the rest of the parser.
Return the number of words typed
593
|
# File 'lib/inform/parserm.h.rb', line 593
def KeyboardPrimitive; end
|
#KeyCharPrimitive ⇒ Object
595
|
# File 'lib/inform/parserm.h.rb', line 595
def KeyCharPrimitive; end
|
599
|
# File 'lib/inform/parserm.h.rb', line 599
def KeyDelay; end
|
#KeyTimerInterrupt ⇒ Object
597
|
# File 'lib/inform/parserm.h.rb', line 597
def KeyTimerInterrupt; end
|
#LanguageVerb(i) ⇒ Object
3353
3354
3355
3356
3357
3358
3359
3360
3361
|
# File 'lib/inform/parserm.h.rb', line 3353
def LanguageVerb(i)
i = 'look at' if %w[l look].include?(i)
if !i.nil? && i.length > 2
print i
return true
else
return false
end
end
|
At this point, the return value is all prepared, and we are only looking to see if there is a “then” followed by subsequent instruction(s).
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
|
# File 'lib/inform/parserm.h.rb', line 1693
def LookForMore
return true if (@wn + 1) > num_words
i = NextWord()
if [THEN1__WD, THEN2__WD, THEN3__WD].include?(i)
if (@wn + 1) > num_words
@held_back_mode = false
return true
end
i = NextWord()
if [AGAIN1__WD, AGAIN2__WD, AGAIN3__WD].include?(i)
i = @wn - 2
@input = @input.split[0...i].join(' ')
end
@held_back_mode = true
return true
end
@best_etype = PartiallyUnderstood
raise @best_etype
end
|
#LowerCase(c) ⇒ Object
rubocop: disable Lint/DuplicateMethods
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
|
# File 'lib/inform/parserm.h.rb', line 4552
def LowerCase(c)
case c
when 'A'..'Z'
c = c + 32
when 202, 204, 212, 214, 221
c -= 1
when 217, 218
c = c - 2
when 158..160, 167..169, 208..210
c = c - 3
when 186..190, 196..200
c = c - 5
when 175..180
c = c - 6
end
return c
end
|
#MakeMatch(obj, quality, scope_reason = @scope_reason) ⇒ Object
MakeMatch looks at how good a match is. If it's the best so far, then
wipe out all the previous matches and start a new list with this one.
If it's only as good as the best so far, add it to the list.
If it's worse, ignore it altogether.
The idea is that "red panic button" is better than "red button" or "panic".
@number_matched (the number of words matched) is set to the current level
of quality.
We never match anything twice, and keep at most 64 equally good items.
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
|
# File 'lib/inform/parserm.h.rb', line 3772
def MakeMatch(obj, quality, scope_reason = @scope_reason)
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Making match for #{obj} of quality #{quality}"
end if defined?(DEBUG)
println " Match with quality #{quality}" if @parser_trace >= 6
end if !@token_filter.nil? && UserFilter(obj) == false
if defined?(DEBUG)
println " Match filtered out: token filter #{@token_filter}" if @parser_trace >= 6
end return true
end
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Making match..."
unless @match_list.empty?
matches_ = @match_list.map(&:to_s)
object_ids_ = @match_list.map(&:object_id)
println ">>...Matches are [#{matches_}] ([#{object_ids_}])"
end
println ">>...No matches yet" if @match_list.empty?
println ">>...Matched by #{@match_length} word" + (!@match_length.nil? && @match_length == 1 ? 's' : '')
println ">>...Match is #{obj} (#{obj.object_id})"
already_in_list = @match_list.include?(obj) ? 'Yes' : 'No'
println ">>...Is object id #{obj.object_id} already in the match list? #{already_in_list}"
end if quality < @match_length then return true end
if quality > @match_length then @match_length = quality; @number_matched = 0; @match_list.clear
else
return true if @number_matched >= MATCH_LIST_SIZE
return true if @match_list.include?(obj)
end
@number_matched += 1
@match_list << obj
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
unless @match_list.empty?
matches_ = @match_list.map(&:to_s)
object_ids_ = @match_list.map(&:object_id)
println ">>...Matches are [#{matches_}] ([#{object_ids_}])"
end
println ">>...No matches yet" if @match_list.empty?
end @number_matched = @match_list.length
if defined?(DEBUG)
println " Match added to list" if @parser_trace >= 6
end false
end
|
#MakeMatchByParseName(obj, threshold, scope_reason = @scope_reason) ⇒ Object
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
|
# File 'lib/inform/parserm.h.rb', line 3823
def MakeMatchByParseName(obj, threshold, scope_reason = @scope_reason)
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Making match by parseable name for #{obj.name}"
println ">>...The threshold is #{threshold}"
end if @parser_action == :PluralFound
@dict_flags_of_noun = @dict_flags_of_noun | 4
end
if (@dict_flags_of_noun & 4) != 0
if @allow_plurals == false
threshold = 0
else
if @indef_mode == false
@indef_mode = true; @indef_type = 0; @indef_wanted = 0
end
@indef_type = @indef_type | PLURAL_BIT
@indef_wanted = Integer::MAX if @indef_wanted == 0
end
end
if defined?(DEBUG)
println " Matched (#{threshold})" if @parser_trace >= 5
end MakeMatch(obj, threshold)
return threshold
end
|
#MultiAdd(o) ⇒ Object
The MultiAdd routine adds object "o" to the multiple-object-list.
3408
3409
3410
3411
3412
3413
3414
|
# File 'lib/inform/parserm.h.rb', line 3408
def MultiAdd(o)
if @multiple_object.include?(o)
return true
else
@multiple_object << o
end
end
|
#MultiFilter(attribute) ⇒ Object
The MultiFilter routine goes through the multiple-object-list and throws
out anything without the given attribute "attribute" set.
3437
3438
3439
3440
3441
|
# File 'lib/inform/parserm.h.rb', line 3437
def MultiFilter(attribute)
for o in @multiple_object
MultiSub(o) if o.hasnt?(attribute)
end
end
|
#MultiSub(o) ⇒ Object
The MultiSub routine deletes object "o" from the multiple-object-list.
It returns 0 if the object was there in the first place, and 9 (because
this is the appropriate error number in Parser()) if it wasn't.
3423
3424
3425
3426
3427
3428
3429
3430
|
# File 'lib/inform/parserm.h.rb', line 3423
def MultiSub(o)
if @multiple_object.include?(o)
@multiple_object.remove(o)
else
return Vague end
end
|
NextWord (which takes no arguments) returns:
0 if the next word is unrecognised,
comma_word if a comma
THEN1__WD if a full stop
or the dictionary address if it is recognised.
The "current word" marker is moved on.
NextWordStopped does the same, but returns -1 when input has run out
4048
4049
4050
4051
4052
4053
4054
4055
|
# File 'lib/inform/parserm.h.rb', line 4048
def NextWord
if (@wn + 1) > num_words then @wn += 1; return false; end
i = @wn; @wn += 1
j = @words[i]
j = @comma_word if j == ','
j = THEN1__WD if j == '.'
return j
end
|
#NextWordStopped ⇒ Object
4057
4058
4059
4060
4061
|
# File 'lib/inform/parserm.h.rb', line 4057
def NextWordStopped
return nil if @wn < 0
if (@wn + 1) > num_words then @wn += 1; return nil; end
return NextWord()
end
|
#NounDomain(domain1, domain2 = nil, context = nil, scope_reason = @scope_reason) ⇒ Object
NounDomain does the most substantial part of parsing an object name.
It is given two "domains" - usually a location and then the actor who is
looking - and a context (i.e. token type), and returns:
0 if no match at all could be made,
1 if a multiple object was made,
k if object k was the one decided upon,
REPARSE_CODE if it asked a question of the player and consequently rewrote
the player's input, so that the whole parser should start again
on the rewritten input.
In the case when it returns 1<k<REPARSE_CODE, it also sets the variable
length_of_noun to the number of words in the input text matched to the
noun.
In the case k=1, the multiple objects are added to @multiple_object by
hand (not by MultiAdd, because we want to allow duplicates).
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
|
# File 'lib/inform/parserm.h.rb', line 2475
def NounDomain(domain1, domain2 = nil, context = nil, scope_reason = @scope_reason)
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Invoked NounDomain for domain '#{domain1}'"
println ">>Indefinite type is #{@indef_type}"
end
if defined?(DEBUG)
if @parser_trace >= 4
print " [NounDomain called at word #{@wn + 1}\n"
print " "
if @indef_mode
print "seeking indefinite object: "
print "other " if (@indef_type & OTHER_BIT) != 0
print "my " if (@indef_type & MY_BIT) != 0
print "that " if (@indef_type & THAT_BIT) != 0
print "plural " if (@indef_type & PLURAL_BIT) != 0
print "lit " if (@indef_type & LIT_BIT) != 0
print "unlit " if (@indef_type & UNLIT_BIT) != 0
print "owner:" + @indef_owner if @indef_owner
new_line
print " number wanted: "
if @indef_wanted == Integer::MAX then print "all" else print @indef_wanted end
new_line
print " most likely GNAs of names: #{@indef_cases}\n"
else
println "seeking definite object"
end
end
end
@match_length = 0
@number_matched = 0
@match_from = @wn
@placed_in_flag = false
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>About to invoke SearchScope in NounDomain"
println ">>...Current input is '#{@input}'"
println ">>...Current number of words is #{num_words}"
println ">>...The current word number is #{@wn + 1}"
println ">>...The current word is '#{current_word}'"
end
SearchScope(domain1, domain2, context, scope_reason)
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>After invoking SearchScope..."
end
if defined?(DEBUG)
println " [ND made #{@number_matched} matches]" if @parser_trace >= 4
end
@wn = (@match_from || 0) + @match_length
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>The noun domain included #{@number_matched} matches for #{@match_length} words"
println ">>The new match list is [#{@match_list.map(&:to_s)}]"
println ">>...The match scores are [#{@match_scores}]"
println ">>...The current word number is #{@wn + 1}"
println ">>...The current word is '#{current_word}'"
println ">>...The number of words is #{num_words}"
println ">>...The match from index is #{@match_from}"
println ">>...The number of matches is #{@number_matched}"
end
if @number_matched == 0 then @wn += 1; return false; end
if ((@match_from || 0) + 1) <= num_words
if @number_matched == 1
return @match_list.first
end
if (@wn + 1) <= num_words
i = NextWord(); @wn -= 1
unless [AND1__WD, AND2__WD, AND3__WD,
THEN1__WD, THEN2__WD, THEN3__WD,
BUT1__WD, BUT2__WD, BUT3__WD].include?(i)
return false if @lookahead.nil?
end
end
end
@number_of_classes = 0
i = @match_list.first if @number_matched == 1
if @number_matched > 1
begin
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Before invoking Adjudicate..."
end i = Adjudicate(context)
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>After invoking Adjudicate..."
println ">>...Adjudicate returned #{i}"
end rescue NoMatchesAvailable
return false
end
return false if i == -1
return true if i == 1 end
if defined?(DEBUG) && @parser_trace >= 10
println ">>About to return from NounDomain()..."
println ">>...The result is #{i}"
println ">>...The pattern count is at #{@pcount}"
println ">>...The match list is #{@match_list}"
println ">>...The match scores are [#{match_scores}]"
end
if i != 0
return i if @dont_infer
@inferfrom = @pcount if @inferfrom == 0
@pattern[@pcount] = i
return i
end
if ((@match_from || 0) + 1) > num_words
raise IncompleteSentence, context
else
raise Ambiguous, context
end
end
|
NounWord (which takes no arguments) returns:
0 if the next word is unrecognised or does not carry the "noun" bit in
its dictionary entry,
1 if a word meaning "me",
the index in the pronoun table (plus 2) of the value field of a pronoun,
if the word is a pronoun,
the address in the dictionary if it is a recognised noun.
The "current word" marker moves on one.
4027
4028
4029
4030
4031
4032
4033
4034
|
# File 'lib/inform/parserm.h.rb', line 4027
def NounWord
i = NextWord()
return false, i if i.nil? || i == false
return :me, i if [ME1__WD, ME2__WD, ME3__WD].include?(i)
return :pronoun, i if language_pronouns.include?(i)
return false, i unless dictionary.include?(i.to_sym)
return :noun, i
end
|
#NoWordsMatch(obj) ⇒ Object
3851
3852
3853
3854
3855
3856
3857
3858
|
# File 'lib/inform/parserm.h.rb', line 3851
def NoWordsMatch(obj)
if @indef_mode != false
@parser_action = nil
return MakeMatchByParseName(obj, 0)
end
return 0
end
|
#NumberWord(o) ⇒ Object
4817
4818
4819
4820
4821
|
# File 'lib/inform/parserm.h.rb', line 4817
def NumberWord(o)
n = LanguageNumbers.find { |k, _v| k == o }
return n.last if !n.nil? && !n.empty? return 0
end
|
#OffersLight(i) ⇒ Object
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
|
# File 'lib/inform/parserm.h.rb', line 4215
def OffersLight(i)
return false if i.nil?
return true if i.has?(:light)
return true if i.any? { |j| HasLightSource(j) }
if i.has?(:container)
return OffersLight(parent(i)) if i.has?(:open) || i.has?(:transparent)
else
return OffersLight(parent(i)) if i.has?(:enterable) || i.has?(:transparent) || i.has?(:supporter)
end
false
end
|
#Parser__parse ⇒ Object
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
|
# File 'lib/inform/parserm.h.rb', line 821
def Parser__parse
@meta = false
@best_etype = CannotUnderstandSentence
@parser_one = @parser_two = nil
@scope_reason = PARSING_REASON
@match_from = 0
if @notheld_mode
@results = @kept_results.dup
@notheld_mode = false
return true
end
if @held_back_mode
@held_back_mode = false
throw :ReParse
end
@input = "say '#{@input[1..]}'" if @input =~ /^['"]/
@words = @input.split
@parser_inflection = :name
@wn = 0
if defined? LanguageToInformese
LanguageToInformese()
end
BeforeParsing()
@verb_wordnum = 0
@actor = @player
@actors_location = ScopeCeiling(@player)
@location ||= @actors_location @usual_grammar_after = nil
@scope_token = nil
@action_to_be = nil
@wn = @verb_wordnum
@verb_word = @words.first.downcase
@verb_word = AGAIN1__WD if @verb_word == AGAIN2__WD || @verb_word == AGAIN3__WD
if @verb_word == AGAIN1__WD
raise RepeatedOrder if @actor != @player
raise NothingToRepeat if history.empty?
@input = history.last
@words = @input.split
@verb_word = @words.first.downcase
end
record_history @input
if [OOPS1__WD, OOPS2__WD, OOPS3__WD].include?(@words.first)
end
initialize_state
if @match_list then @match_list.clear else @match_list = [] end
if @multiple_object then @multiple_object.clear else @multiple_object = [] end
if @pattern then @pattern.clear else @pattern = [] end
@etype = nil
@noun = nil
@second = nil
@parsed_number = nil
@special_word = nil
@special_number1 = nil
@special_number2 = nil
@consult_words = nil
@query = nil
@search_results = nil
@token_filter = nil
@advance_warning = nil
@inp1 = nil
@inp2 = nil
@lookmode = 1
@verb = Inform::Grammar::Verbs.lookup @verb_word, @player
@pattern << @words.first
@pattern2 = @pattern.dup
if @verb.nil?
if defined?(DEBUG) && @parser_trace >= 10
println ">>About to invoke NounDomain..."
println ">>...on the Compass object"
end @wn = @verb_wordnum; @indef_mode = false; @token_filter = nil
l = NounDomain(Compass)
if l
@results[0] = :Go
@action_to_be = :Go
@results[1] = 1
@results[2] = l
return LookForMore()
end
if @actor == @player
if ConversationStarterPattern.match?(@words.join(' '))
log.debug "jump Conversation"
else
@verb = UnknownVerb(@verb)
if @verb.nil?
@best_etype = VerbUnrecognized
raise @best_etype
else
log.debug "jump VerbAccepted"
end
end
else
@best_etype = VerbUnrecognized
raise @best_etype
end
@actor = l
@actors_location = ScopeCeiling(l)
if defined?(DEBUG)
if @parser_trace >= 1
println "[Actor is " + the(@actor) + " in " + @actors_location + "]"
end
end return true
end
VerbAccepted()
end
|
#ParseToken(given_ttype, given_tdata, token_n, token) ⇒ Object
rubocop: disable Layout/EmptyLinesAroundBlockBody
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
|
# File 'lib/inform/parserm.h.rb', line 1902
def ParseToken(given_ttype, given_tdata, token_n, token)
@token_filter = nil
case given_ttype
when :special
l = Descriptors()
return @special_word = NextWord() if l.nil?
l = TryNumber(@wn)
@special_word = NextWord()
if defined?(DEBUG)
if l.number?
println " [Read special as the number #{l}]" if @parser_trace >= 3
end
end unless l.number?
if defined?(DEBUG)
println " [Read special word at word number #{@wn + 1}]" if @parser_trace >= 3
end l = @special_word
end
@parsed_number = l; return GPR_NUMBER
when :number
l = TryNumber(@wn); @wn += 1
unless l.number?
@etype = NumberUnrecognized
return false
end
if defined?(DEBUG)
println " [Read number as #{l}]" if @parser_trace >= 3
end @parsed_number = l.to_i
return GPR_NUMBER
when :creature
@scope_reason = TALKING_REASON if %i[Answer Ask AskFor Tell].include?(@action_to_be)
when :topic
@consult_from = @wn
return RunTimeError(13) unless %i[preposition end].include?(@line_ttype[token_n + 1])
loop do
o = NextWordStopped()
break if o.nil? || PrepositionChain(o, token_n + 1) != -1
end
@wn -= 1
@consult_words = @words[@consult_from...@wn].join(' ')
if @consult_words.empty?
@consult_words = nil
return false
end
if @action_to_be == :Ask || @action_to_be == :Answer || @action_to_be == :Tell
o = @wn; @wn = @consult_from; @parsed_number = NextWord()
if defined? EnglishNaturalLanguage
@parsed_number = NextWord() if @parsed_number == 'the' && @consult_words.length > 1
end @wn = o; return 1
end
if o.nil? && @line_ttype[token_n + 1] == :preposition
return false end
return GPR_PREPOSITION
when :preposition
s = given_tdata.gsub(/'/, '')
s = s.gsub(/\//, '|')
if @wn > num_words
if @inferfrom == 0 && @parameters < @params_wanted
@inferfrom = @pcount; @inferword = token
@pattern[@pcount] = given_tdata
end
return false if @inferfrom == 0
@pattern[@pcount] = given_tdata
return GPR_PREPOSITION
end
o = NextWord()
@pattern[@pcount] = o
if defined?(DEBUG) && @parser_trace >= 10
println ">>Matched '#{o}' for #{s}" if o && o =~ /^(#{s})$/i
end
return GPR_PREPOSITION if o && o =~ /^(#{s})$/i
if Grammar__Version != 1
return GPR_PREPOSITION if PrepositionChain(o, token_n) != -1
end return false
when :general_parse_routine
l = indirect(given_tdata)
if defined?(DEBUG)
println " [Outside parsing routine returned " + l + "]" if @parser_trace >= 3
end return l
when :scope
@scope_token = given_tdata
@scope_stage = 1
if defined?(DEBUG)
println " [Scope routine called at stage 1]" if @parser_trace >= 3
end l = indirect(@scope_token)
if defined?(DEBUG)
println " [Scope routine returned multiple-flag of " + l + "]" if @parser_trace >= 3
end if l == true then @given_tdata = :multi else @given_tdata = :noun end
when :attribute_filter
@token_filter = given_tdata
@given_tdata = :noun
when :routine_filter
@token_filter = given_tdata
@given_tdata = :noun
end
token = given_ttype
prev_indef_wanted = 0
token_allows_multiple = %i[multi multiheld multiexcept multiinside].include?(token)
many_flag = false; and_parity = true; @dont_infer = false
label :ObjectList do
if defined?(DEBUG)
println " [Object list from word #{@wn + 1}]" if @parser_trace >= 3
end
if defined?(DEBUG) && @parser_trace >= 10
println ">>Taking an advance look at the next word..."
end
o = NextWord(); @wn -= 1
if defined?(DEBUG) && @parser_trace >= 10
println ">>After invoking NextWord() while parsing descriptors..."
println ">>...The current word number is #{@wn + 1}"
println ">>...The current word is '#{current_word}'"
println ">>...And the next word is '#{o}'" if o
println ">>...And there are no more words" unless o
end
@pronoun_word = nil; @pronoun_obj = nil
l = PronounValue(o)
if l != false
@pronoun_word = o; @pronoun_obj = l
if l.nil?
unless language_descriptors.keys.include? o
@pronoun__word = @pronoun_word; @pronoun__obj = @pronoun_obj
@etype = Vague
raise @etype
end
end
end
if [ME1__WD, ME2__WD, ME3__WD].include?(o) then @pronoun_word = o; @pronoun_obj = selfobj; end
@allow_plurals = true; desc_wn = @wn;
label :TryAgain do
if defined?(DEBUG) && @parser_trace >= 10
println ">>Before invoking Descriptors()..."
println ">>...The current word number is #{@wn + 1}"
println ">>...The current word is '#{current_word}'"
end
l = Descriptors()
if defined?(DEBUG) && @parser_trace >= 10
println ">>After invoking Descriptors()..."
println ">>...l is #{l}"
println ">>...The current word number is #{@wn + 1}"
println ">>...The current word is '#{current_word}'"
end
if l then @etype = l; return false; end
label :TryAgain2 do
@oops_from = @wn
if token != :held
i = @multiple_object.length
if defined?(DEBUG)
println " [Calling NounDomain on location and actor]" if @parser_trace >= 3
end
if defined?(DEBUG) && @parser_trace >= 10
println ">>Before invoking NounDomain()..."
println ">>...The token being parsed is :#{token}"
end
l = NounDomain(@actors_location, @actor, token)
if defined?(DEBUG) && @parser_trace >= 10
println ">>After invoking NounDomain()..."
println ">>...For token #{token} l is #{l}"
println ">>...The etype is #{@etype}"
println ">>...The indef_possambig is #{@indef_possambig}"
end
return l if l == REPARSE_CODE if @indef_wanted == Integer::MAX && (l.nil? || l == false) && @number_matched == 0
l = 1 end
if token_allows_multiple && !@multiflag
@best_etype = CannotUnderstandSentence if @best_etype == UnexpectedMultiple
@multiflag = true
end
if l.nil? || l == false
if @indef_possambig
ResetDescriptors()
@wn = desc_wn
throw :TryAgain2
end
@etype = CannotUnderstandSentence if @multiflag && [UnexpectedMultiple, TooFew].include?(@etype)
@etype = CantSee()
return FailToken(desc_wn, prev_indef_wanted)
end
if defined?(DEBUG)
if @parser_trace >= 3
if l == true
println " [ND appended to the multiple object list:"
@multiple_object.each_with_index do |obj, j|
println " Entry " + (j + 1) + ": " + The(obj) +
" (" + obj.object_id + ")"
end
println " List now has size #{@multiple_object.length}]"
else
println " [ND returned " + the(l) + "]"
end
end
end
if l == true
if defined?(DEBUG) && @parser_trace >= 10
println ">>Multiple objects were found: #{@multiple_object}"
end if !many_flag
many_flag = true
else k = @multiple_object.length for j in (i + 1)..k
if and_parity then MultiAdd(@multiple_object[j])
else MultiSub(@multiple_object[j])
end
end
if defined?(DEBUG)
println " [Merging #{k - i} new objects to the #{i} old ones]" if @parser_trace >= 3
end end
else
if defined?(DEBUG) && @parser_trace >= 10
println ">>A single object was found: #{l}"
println ">>...The match length is #{@match_length}"
println ">>...Indefinite possibly ambiguous? " + (@indef_possambig ? "Yes." : "No.")
end if @match_length == 0 && @indef_possambig
if defined?(DEBUG) && @parser_trace >= 10
println ">>...The answer had to be inferred from no textual data"
end
ResetDescriptors()
@wn = desc_wn
if defined?(DEBUG) && @parser_trace >= 10
println ">>Trying to parse the #{token} again..."
end throw :TryAgain2
end
if token == :creature
if defined?(DEBUG) && @parser_trace >= 10
println ">>Expecting creature and found '#{l}'"
end unless CreatureTest(l)
@etype = AnimateExpected
return FailToken(desc_wn, prev_indef_wanted)
end
end
if many_flag
if and_parity then MultiAdd(l); else MultiSub(l); end
else
single_object = l
end
end
else
if defined?(DEBUG) && @parser_trace >= 10
println ">>Before invoking NounDomain()..."
println ">>...The token being parsed is :#{token}"
end
l = NounDomain(@actor, @actors_location, token)
if defined?(DEBUG) && @parser_trace >= 10
println ">>After invoking NounDomain()..."
println ">>...For token :#{token}"
println ">>...The etype is #{@etype}"
println ">>...The indef_possambig is #{@indef_possambig}"
end
return GPR_REPARSE if l == REPARSE_CODE
if l.nil? || l == false
if @indef_possambig
ResetDescriptors()
@wn = desc_wn
throw :TryAgain2
end
@etype = CantSee() return FailToken(desc_wn, prev_indef_wanted)
end
o = parent(l)
if defined?(DEBUG) && @parser_trace >= 10
println ">>Trying to deal with something not held..."
println ">>...l is #{l}"
println ">>...parent of l is #{o}"
println ">>...the not held mode is #{@notheld_mode}"
end
if o != @actor
if @notheld_mode
@saved_oops = @oops_from
@etype = NotHeld
return FailToken(desc_wn, prev_indef_wanted)
end
@not_holding = l
if defined?(DEBUG)
println " [Allowing object " + the(l) + " for now]" if @parser_trace >= 3
end end
single_object = l
end
@wn = @oops_from + @match_length
if defined?(DEBUG) && @parser_trace >= 10
println ">>Found a single held object: #{single_object}" if single_object
println ">>Found multiple object: #{@multiple_object}" unless @multiple_object.empty?
println ">>...The current word number is #{@wn + 1}"
println ">>...The current word is '#{current_word}'"
end
o = NextWord()
if o != false && (CommaWordPattern.match?(o) || [
AND1__WD, AND2__WD, AND3__WD, BUT1__WD, BUT2__WD, BUT3__WD].include?(o))
if defined?(DEBUG)
println " [Read connective '" + o + "']" if @parser_trace >= 3
end
unless token_allows_multiple
return PassToken(many_flag, single_object, token, desc_wn, prev_indef_wanted) if @multiflag
@etype = UnexpectedMultiple
return FailToken(desc_wn, prev_indef_wanted)
end
and_parity = !and_parity if [BUT1__WD, BUT2__WD, BUT3__WD].include?(o)
unless many_flag
@multiple_object = [single_object]
many_flag = true
if defined?(DEBUG)
println " [Making new list from " + the(single_object) + "]" if @parser_trace >= 3
end end
@dont_infer = true; @inferfrom = 0 if defined?(DEBUG) && @parser_trace >= 10
println ">>Looping back around"
end throw :ObjectList end
@wn -= 1
return PassToken(many_flag, single_object, token, desc_wn, prev_indef_wanted)
end
end
end
end
|
#PassToken(many_flag, single_object, token, desc_wn, prev_indef_wanted) ⇒ Object
rubocop: enable Layout/EmptyLinesAroundBlockBody end of ParseToken
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
|
# File 'lib/inform/parserm.h.rb', line 2426
def PassToken(many_flag, single_object, token, desc_wn, prev_indef_wanted)
if many_flag
single_object = GPR_MULTIPLE
@multi_context = token
else
if @indef_mode && (@indef_type & PLURAL_BIT) != 0
if @indef_wanted < Integer::MAX && @indef_wanted > 1
@multi_had = true; @multi_wanted = @indef_wanted
@etype = TooFew
return FailToken(desc_wn, prev_indef_wanted)
end
end
end
return single_object
end
|
#PlaceInScope(thing, scope_reason = @scope_reason) ⇒ Object
PlaceInScope is provided for routines outside the library, and is not
called within the parser (except for debugging purposes).
3573
3574
3575
3576
3577
3578
|
# File 'lib/inform/parserm.h.rb', line 3573
def PlaceInScope(thing, scope_reason = @scope_reason)
if scope_reason != PARSING_REASON && scope_reason != TALKING_REASON
DoScopeAction(thing, scope_reason); return true
end
@wn = @match_from.nil? ? 0 : @match_from; TryGivenObject(thing); @placed_in_flag = true
end
|
#PrefaceByArticle(o, acode, pluralise = false, capitalise = false) ⇒ Object
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
|
# File 'lib/inform/parserm.h.rb', line 4659
def PrefaceByArticle(o, acode, pluralise = false, capitalise = false)
if o.respond_to?(:articles) && o.&(:articles).respond_to?(:[])
artval = (o.&:articles)[(acode + @short_name_case * LanguageCases)]
if capitalise
print Cap(artval) + " "
else
print artval + " "
end
return if pluralise
print PSN__(o); return
end
artform = Inform::English::LanguageArticles[0]
if LanguageContractionForms == 2
findout = true if artform[acode] != artform[(acode + 3)]
end if LanguageContractionForms == 3
findout = true if artform[acode] != artform[(acode + 3)]
findout = true if artform[(acode + 3)] != artform[(acode + 6)]
end if LanguageContractionForms == 4
findout = true if artform[acode] != artform[(acode + 3)]
findout = true if artform[(acode + 3)] != artform[(acode + 6)]
findout = true if artform[(acode + 6)] != artform[(acode + 9)]
end if LanguageContractionForms > 4
findout = true
end
if @standard_interpreter != 0 && findout
StorageForShortName[:buffer][0] = ''
if pluralise then print number(pluralise) else print PSN__(o) end
acode = acode + (3 * LanguageContraction(StorageForShortName[:buffer][0]))
end
Cap(artform[acode], !capitalise) return if pluralise
print PSN__(o)
end
|
#PrepositionChain(wd, index) ⇒ Object
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
|
# File 'lib/inform/parserm.h.rb', line 1863
def PrepositionChain(wd, index)
return wd if @line_tdata[index] == "'#{wd}'"
return -1 if @line_token[index].empty?
loop do
return wd if @line_tdata[index] == "'#{wd}'"
index += 1
break if @line_token[index] == :end || @line_token[index].empty?
end
return -1
end
|
#PrintCapitalised(obj, prop = nil, flag = true, nocaps = false, centred = false) ⇒ Object
rubocop: enable Lint/DuplicateMethods
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
|
# File 'lib/inform/parserm.h.rb', line 4593
def PrintCapitalised(obj, prop = nil, flag = true, nocaps = false, centred = false)
if obj.is_a?(String) || prop.nil?
s = obj
flag = true
else
if obj.respond_to?(prop) || (obj.&prop).is_a?(String)
s = obj.&prop
else
if (obj.&prop).nil? then return false
else return RunTimeError(2, obj, prop)
end
end
end
width = ScreenWidth()
spaces((width - length) / 2) if centred && length < width
s = UpperCase(s) if nocaps == false
if s.nil?
s = if obj.object? then obj.to_s else obj end
end
print s.sentence_case
new_line if flag == false
return
end
|
#PrintCommand(from = 0) ⇒ Object
def PrintInferredCommand(from = nil)
singleton_noun = false
if from != 0 && from == @pcount-1 && @pattern[from].object? singleton_noun = true
end
if singleton_noun == true
BeginActivity(CLARIFYING_PARSERS_CHOICE_ACT, @pattern[from])
if ForActivity(CLARIFYING_PARSERS_CHOICE_ACT, @pattern[from]) == 0
print "("; PrintCommand(from); print ")^"
end
EndActivity(CLARIFYING_PARSERS_CHOICE_ACT, @pattern[from])
else
print "("; PrintCommand(from); print ")^"
end
end
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
|
# File 'lib/inform/parserm.h.rb', line 3327
def PrintCommand(from = 0)
if from == 0
i = @verb_word
unless LanguageVerb(i)
print i unless PrintVerb(i)
end
from += 1; spacing_flag = true
end
for i in @pattern[from..]
next if i.nil?
print ' ' if spacing_flag
if i == 0 then print THOSET__TX; spacing_flag = true; next; end
if i == 1 then print THAT__TX; spacing_flag = true; next; end
if !i.object? then print i; spacing_flag = true; next; end
if i.in?(Compass) && LanguageVerbLikesAdverb(@verb)
LanguageDirection(i.door_dir) elsif i == @player
print YOURSELF__TX
else
print the(i)
end
spacing_flag = true
end
end
|
#PrintVerb(i) ⇒ Object
3363
3364
3365
3366
3367
3368
3369
3370
|
# File 'lib/inform/parserm.h.rb', line 3363
def PrintVerb(i)
if @verb.include?(i)
print @verb.verb
return true
else
return false
end
end
|
#PronounNotice(obj) ⇒ Object
def PronounOldEnglish
SetPronoun('it', @itobj) if @itobj != @old_itobj
SetPronoun('him', @himobj) if @himobj != @old_himobj
SetPronoun('her', @herobj) if @herobj != @old_herobj
@old_itobj = @itobj; @old_himobj = @himobj; @old_herobj = @herobj;
end
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
|
# File 'lib/inform/parserm.h.rb', line 4166
def PronounNotice(obj)
return if obj == @player
bm = PowersOfTwo_TB[GetGNAOfObject(obj)]
for x in language_pronouns.keys
a = bm & language_pronouns[x][0]
language_pronouns[x][1] = obj if a > 0
end
end
|
#PronounsSub ⇒ Object
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
|
# File 'lib/inform/parserm.h.rb', line 4113
def PronounsSub
L__M(:Pronouns, 1)
c = language_pronouns.length
c += 1 if @player != selfobj
return L__M(:Pronouns, 4) if c == 0
d = 0
for x in language_pronouns.keys
print '"' + x + '" '
y = language_pronouns[x][1]
if y
L__M(:Pronouns, 2)
print the(y)
else
L__M(:Pronouns, 3)
end
d += 1
print COMMA__TX if d < c - 1
print AND__TX if d == c - 1
end
if @player != selfobj
print '"' + ME1__WD + '" '; L__M(:Pronouns, 2)
c = @player; @player = selfobj
print the(c); @player = c
end
L__M(:Pronouns, 5)
end
|
#PronounValue(dword) ⇒ Object
4148
4149
4150
4151
4152
4153
|
# File 'lib/inform/parserm.h.rb', line 4148
def PronounValue(dword)
if language_pronouns.include? dword
return language_pronouns[dword][1]
end
return false
end
|
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
|
# File 'lib/inform/parserm.h.rb', line 4755
def PSN__(o)
if o.nil? then print NOTHING__TX; return true; end
if respond_to?(o.to_s.to_sym) print "<routine " + o + ">"; return true
end
case o
when String then print "<string ~#{o}~>"; return true
when NilClass then print "<illegal object number " + o + ">"; return true
end
if o == player then print YOURSELF__TX; return true; end
if defined? LanguagePrintShortName
return true if LanguagePrintShortName(o)
end return true if @indef_mode && o.respond_to?(:short_name_indef) && PrintOrRun(o, :short_name_indef, 1) != false
return true if !o.&(:short_name).nil? && PrintOrRun(o, :short_name, 1) != false
print o
end
|
#Refers(obj, wnum) ⇒ Object
Refers works out whether the word at number wnum can refer to the object
obj, returning true or false. The standard method is to see if the
word is listed under "name" for the object, but this is more complex
in languages other than English.
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
|
# File 'lib/inform/parserm.h.rb', line 3983
def Refers(obj, wnum)
return false unless obj
if defined? LanguageRefers
k = LanguageRefers.call(obj, wnum); return k.is_a?(String) && k.split.include?(wd)
end
k = @wn; @wn = wnum; wd = NextWordStopped(); @wn = k
if @parser_inflection != :name
k = indirect(@parser_inflection, obj, wd)
return k if !k.nil? || !k.respond_to?(:intern)
m = k.intern
else
m = @parser_inflection
end
k = obj.&m
k = k.split if k.respond_to?(:split)
return true if k.include?(wd)
k = k.last if k.respond_to?(:last)
return true if pluralize(k) == wd return false
end
|
#ResetDescriptors ⇒ Object
OTHER_BIT = 1 # These will be used in Adjudicate() MY_BIT = 2 # to disambiguate choices THAT_BIT = 4 PLURAL_BIT = 8 LIT_BIT = 16 UNLIT_BIT = 32
1751
1752
1753
1754
1755
1756
1757
|
# File 'lib/inform/parserm.h.rb', line 1751
def ResetDescriptors
@indef_mode = false; @indef_type = 0; @indef_wanted = 0; @indef_guess_p = false
@indef_possambig = false
@indef_owner = nil
@indef_cases = 0b111111111111
@indef_nspec_at = 0
end
|
#ResetVagueWords(obj) ⇒ Object
4155
|
# File 'lib/inform/parserm.h.rb', line 4155
def ResetVagueWords(obj); PronounNotice(obj); end
|
#ReviseMulti(second_p) ⇒ Object
ReviseMulti revises the multiple object which already exists, in the
light of information which has come along since then (i.e., the second
parameter). It returns a parser error number, or else 0 if all is well.
This only ever throws things out, never adds new ones.
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
|
# File 'lib/inform/parserm.h.rb', line 3060
def ReviseMulti(second_p)
if defined?(DEBUG)
if @parser_trace >= 4
print " Revising multiple object list of size #{@multiple_object.length}" \
" with 2nd #{second_p}\n"
end
end
if @multi_context == :multiexcept || @multi_context == :multiinside
@multiple_object.keep_if do |i|
(@multi_context == :multiexcept && i != second_p) ||
(@multi_context == :multiinside && i.in?(second_p))
end
end
if @multi_context == :multi && @action_to_be == :Take
low = @multiple_object.count { |i| ScopeCeiling(i) == ScopeCeiling(@actor) }
if defined?(DEBUG)
println " Token 2 plural case: number with actor #{low}" if @parser_trace >= 4
end if @take_all_rule == 2 || low > 0
@multiple_object.delete_if { |i| ScopeCeiling(i) != ScopeCeiling(@actor) }
end
end
i = @multiple_object.length
if defined?(DEBUG)
println " Done: new size #{i}" if @parser_trace >= 4
end return NothingMatched if i == 0
return false
end
|
#ScopeCeiling(person) ⇒ Object
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
|
# File 'lib/inform/parserm.h.rb', line 1717
def ScopeCeiling(person)
act = parent(person)
return person if act.nil?
return thedark if person == @player && @location == thedark
i = 0
while parent(act) && (act.hasany?(:transparent, :supporter) || act.has?(:container, :open))
act = parent(act)
if defined?(DEBUG) && @scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>ScopeCeiling for #{person}, (act) #{act}, (iteration) #{i += 1}"
end end
return act
end
|
#ScopeWithin(domain, nosearch = nil, context = nil, scope_reason = @scope_reason) ⇒ Object
ScopeWithin looks for objects in the domain which make textual sense
and puts them in the match list. (However, it does not recurse through
the second argument.)
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
|
# File 'lib/inform/parserm.h.rb', line 3643
def ScopeWithin(domain, nosearch = nil, context = nil, scope_reason = @scope_reason)
start = Time.ns
return true if domain.nil?
if @indef_mode == false && domain == @actors_location &&
scope_reason == PARSING_REASON && context != :creature
ScopeWithin(Compass)
end
for x in domain
ScopeWithin_O(x, nosearch, context, scope_reason)
end
return true
ensure
elapsed = ((Time.ns - start) / 100_000.to_f).round(6)
log.debug "ScopeWithin elapsed time: #{elapsed} milliseconds" if defined?(DEBUG)
end
|
#ScopeWithin_O(domain, nosearch = nil, context = nil, scope_reason = @scope_reason) ⇒ Object
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
|
# File 'lib/inform/parserm.h.rb', line 3669
def ScopeWithin_O(domain, nosearch = nil, context = nil, scope_reason = @scope_reason)
if scope_reason != PARSING_REASON && scope_reason != TALKING_REASON
DoScopeAction(domain, scope_reason)
return DontAccept(domain, nosearch, context)
end
if (@match_from || 0) <= num_words @wn = (@match_from || 0)
i, w = NounWord()
MakeMatch(domain, 1) if i == :me && @player == domain
MakeMatch(domain, 1) if i == :pronoun && language_pronouns[w][1] == domain
end
@wn = (@match_from || 0)
if TryGivenObject(domain) > 0
if (@indef_nspec_at || 0) > 0 && (@match_from || 0) != @indef_nspec_at
@wn = @indef_nspec_at
if TryGivenObject(domain) > 0
@match_from = @indef_nspec_at
ResetDescriptors()
end
@wn = (@match_from || 0)
end
end
DontAccept(domain, nosearch, context)
end
|
#ScoreMatchL(context, match_list = [], match_scores = [], number_matched = 0, threshold = 0) ⇒ Object
ScoreMatchL scores the match list for quality in terms of what the
player has vaguely asked for. Points are awarded for conforming with
requirements like "my", and so on. Remove from the match list any
entries which fail the basic requirements of the descriptors.
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
|
# File 'lib/inform/parserm.h.rb', line 3100
def ScoreMatchL(context, match_list = [], match_scores = [], number_matched = 0, threshold = 0)
threshold += 1 if (@indef_type & OTHER_BIT) != 0
threshold += 1 if (@indef_type & MY_BIT) != 0
threshold += 1 if (@indef_type & THAT_BIT) != 0
threshold += 1 if (@indef_type & LIT_BIT) != 0
threshold += 1 if (@indef_type & UNLIT_BIT) != 0
threshold += 1 if @indef_owner
if defined?(DEBUG)
if @parser_trace >= 4
print " Scoring match list: indef mode #{@indef_mode}, type #{@indef_type}" \
", satisfying #{threshold} requirements:\n"
end
end
if defined? PREFER_HELD
else a_s = SCORE__NEXTBESTLOC; l_s = SCORE__BESTLOC
if %i[held multiheld multiexcept].include?(context)
a_s = SCORE__BESTLOC; l_s = SCORE__NEXTBESTLOC
end
end
for i in (0...number_matched)
obj = match_list[i]; its_owner = parent(obj); its_score = 0; met = 0
met += 1 if (@indef_type & MY_BIT) != 0 && (its_owner == @actor)
met += 1 if (@indef_type & THAT_BIT) != 0 && (its_owner == @actors_location)
met += 1 if (@indef_type & LIT_BIT) != 0 && obj.has?(:light)
met += 1 if (@indef_type & UNLIT_BIT) != 0 && obj.hasnt?(:light)
met += 1 if !@indef_owner.nil? && its_owner == @indef_owner
if met < threshold
if defined?(DEBUG)
if @parser_trace >= 4
print " " + The(match_list[i]) + " (" + match_list[i] + ") in " +
the(its_owner) + " is rejected (doesn't match descriptors)\n"
end
end match_list[i] = nil
else
its_score = 0
its_score = SCORE__UNCONCEALED if obj.hasnt? :concealed
if its_owner == @actor then its_score += a_s
else
if its_owner == @actors_location then its_score += l_s
else
if its_owner != Compass then its_score += SCORE__NOTCOMPASS end
end
end
its_score += (SCORE__CHOOSEOBJ * ChooseObjects(obj, 2))
its_score += SCORE__NOTSCENERY if obj.hasnt? :scenery
its_score += SCORE__NOTACTOR if obj != @actor
if @indef_cases & PowersOfTwo_TB[GetGNAOfObject(obj)]
its_score += SCORE__GNA
end
begin
match_scores[i] = match_scores[i] + its_score
rescue StandardError
match_scores[i] = 0
end
if defined?(DEBUG)
if @parser_trace >= 4
print " " + The(match_list[i]) + " (#{match_list[i].object_id}) in " +
the(its_owner) + " : #{match_scores[i]} points\n"
end
end end
end
while (i = match_list.index(nil))
match_list.delete_at i
match_scores.delete_at i
number_matched = match_list.length
end
[match_list, match_scores, number_matched]
end
|
#ScreenWidth ⇒ Object
Miscellaneous display routines used by DrawStatusLine and available for
user. Most of these vary according to which machine is being compiled to
4468
4469
4470
4471
4472
4473
|
# File 'lib/inform/parserm.h.rb', line 4468
def ScreenWidth
width = get_wind_prop(1, 3)
charw = get_wind_prop(1, 13)
charw = charw & 0xFF
return ((width + (charw - 1)) / charw.to_f).to_i
end
|
#SearchScope(domain1, domain2 = nil, context = nil, scope_reason = @scope_reason) ⇒ Object
TODO: 2021-07-21 I think that SearchScope is a little bit broken right now, particularly for reactions, i.e.: in the reacts_to?(action) code path. The bug symptom is that some reactions are invoked on particular objects more than once for a single action source. FIXME
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
|
# File 'lib/inform/parserm.h.rb', line 3468
def SearchScope(domain1, domain2 = nil, context = nil, scope_reason = @scope_reason)
start = Time.ns
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Invoked SearchScope"
println ">>...domain1 is #{domain1}" if domain1
println ">>...domain2 is #{domain2}" if domain2
end @match_list ||= []
@match_list.clear
if !@scope_token.nil?
@scope_stage = 2
if defined?(DEBUG)
println " [Scope routine called at stage 2]" if @parser_trace >= 3
end return true if indirect(@scope_token)
end
if (@actor == domain1 || @actor == domain2) && InScope(@actor) != false
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Skipping standard scope"
end return true
end
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Before invoking ScopeWithin..."
println ">>...The context is #{context}"
end if context == :multiinside && !@advance_warning.nil?
if IsSeeThrough(@advance_warning)
ScopeWithin(@advance_warning, nil, context, scope_reason)
end
else
if !domain1.nil? && domain1.hasany?(:supporter, :container)
ScopeWithin_O(domain1, domain1, context, scope_reason)
end
ScopeWithin(domain1, domain2, context, scope_reason)
if !domain2.nil? && domain2.hasany?(:supporter, :container)
if defined?(DEBUG)
println "SearchScope domain2 = " + the(domain2) + ", context = " + the(context)
end
ScopeWithin_O(domain2, domain2, context, scope_reason)
end
ScopeWithin(domain2, nil, context, scope_reason)
end
if [domain1, domain2].include?(thedark)
ScopeWithin_O(@actor, @actor, context)
if @actor.parent.has?(:supporter) || @actor.parent.has?(:container)
ScopeWithin_O(@actor.parent, @actor.parent, context)
end
end
if defined?(DEBUG) && scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>After invoking ScopeWithin..."
unless @match_list.empty?
println ">>...The match list is [#{@match_list.map(&:to_s)}]"
println ">>...Matched by #{@match_length} word" + (@match_length > 1 ? 's' : '')
end
end ensure
elapsed = ((Time.ns - start) * 1000).round(6)
log.debug "SearchScope elapsed time: #{elapsed} milliseconds"
println "SearchScope elapsed time: #{elapsed} milliseconds" if defined?(DEBUG)
end
|
539
540
541
|
# File 'lib/inform/parserm.h.rb', line 539
def selfobj
@selfobj ||= SelfObj
end
|
#selfobj=(o) ⇒ Object
543
544
545
|
# File 'lib/inform/parserm.h.rb', line 543
def selfobj=(o)
@selfobj = o
end
|
#SetPronoun(dword, value) ⇒ Object
4143
4144
4145
4146
|
# File 'lib/inform/parserm.h.rb', line 4143
def SetPronoun(dword, value)
raise NoSuchPronoun unless language_pronouns.include? dword
return language_pronouns[dword][1] = value
end
|
#ShowobjSub ⇒ Object
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
|
# File 'lib/inform/parserm.h.rb', line 4363
def ShowobjSub
f = 0
obj = @noun || location
obj = getobject(@special_number1.to_i) unless @special_number1.nil?
class_ancestry = obj.class.ancestors.compact
class_ancestry[(class_ancestry.index(Inform::Object) + 1)..] = []
l = obj.class
f += 1
if f == 1
print l.name + " \""
else
print "Object \""
end
print "#{obj}\" (#{obj.id})";
print " in \"#{parent(obj)}\"" unless parent(obj).nil?
new_line
if class_ancestry.length > 1
print " class "
class_ancestry.each do |c|
if c.name.nil? then print "#{c} " else print "#{c.name} " end
end
new_line
end
if !obj.attributes.empty?
print " has "
obj.attributes.each do |attribute|
print DebugAttribute(attribute) + " " if obj.has? attribute
end
new_line
end
return if obj.is_a? Class
f = 0
properties = obj.properties.keys
properties.unshift :name, :description
values = obj.values.keys
values.unshift :name, :description
routines = obj.routines
l = Set.new
l += properties
l += routines
l.each_with_index do |prop, i|
if obj.respond_to?(prop) || obj.&(prop)
if f == 0
print " with "
f = 1
end
next if MethodWriterPattern.match?(prop)
n = []
if values.include?(prop)
n = obj.values[prop]
elsif properties.include?(prop)
n = obj.&(prop)
elsif routines.include?(prop)
n = obj.method(prop)
end
next if n.nil? || (n.respond_to?(:empty?) && n.empty?)
print prop
n = n.split if prop == :name && n.respond_to?(:split)
for x in [n].flatten
print " "
if prop == :name
print "'#{x}'"
elsif KnownNumberProperties.include?(prop)
print x
else
case x
when nil then print "nil"
when false then print "false"
when true then print "true"
when 0 then print "0"
when 1 then print "1"
when Method then print '{...}'
when Class then print x.name
else
if x.respond_to? :name
print x.name
elsif x.respond_to? :keys
print x.inspect
else
print "\"#{x}\""
end
print " (#{x.object_id})"
end
end
end
print ",\n " if (i + 1) < l.length
end
end
true
rescue StandardError => e
log.error "Unexpected error: #{e.message}"
e.backtrace.each { |t| log.error t }
end
|
#ShowVerbSub ⇒ Object
Also known as:
ShowverbSub
def DebugGrammarLine(line)
print " * "
print "%s " % [line.join(' ')] unless line.empty?
print "-> #{line.action}"
print ' reverse' if line.reverse?
end
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
|
# File 'lib/inform/parserm.h.rb', line 4337
def ShowVerbSub
return "Try typing \"showverb\" and then the name of a verb." unless special
verb = Inform::Grammar::Verbs.lookup special.to_s, @player
if verb
print "\e[51m"
print "Verb "
print "meta " if verb.meta?
print verb.map { |word| "'#{word}'" }.join(' ')
lines = verb.grammars
new_line
return "has no grammar lines." if lines.empty?
for line in lines
line = UnpackGrammarLine(line)
print " "; DebugGrammarLine(line); new_line
end
print "\e[56m"
true
else
"No such verb."
end
end
|
#SingleBestGuess ⇒ Object
SingleBestGuess returns the highest-scoring object in the match list
if it is the clear winner, or returns -1 if there is no clear winner
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
|
# File 'lib/inform/parserm.h.rb', line 3233
def SingleBestGuess
earliest = nil; best = -1000;
for i in (0...@number_matched)
its_score = @match_scores[i]
earliest = nil if its_score == best
if its_score > best then best = its_score; earliest = @match_list[i]; end
end
@bestguess_score = best
return earliest
end
|
513
514
515
|
# File 'lib/inform/parserm.h.rb', line 513
def thedark
Darkness
end
|
#TraceAction(source, ar) ⇒ Object
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
|
# File 'lib/inform/parserm.h.rb', line 4314
def TraceAction(source, ar)
if source < 2 then print "[ Action " + @action
else
if ar == :Order
print "[ Order to " + @actor + ": " + @action
else
print "[ Life rule " + ar
end
end
if @noun then print " with noun " + @noun end
if @second then print " and second " + @second end
if source == 0 then print " " end
if source == 1 then print " (from < > statement) " end
println "]"
end
|
#TryGivenObject(obj) ⇒ Object
TryGivenObject tries to match as many words as possible in what has been
typed to the given object, obj. If it manages any words matched at all,
it calls MakeMatch to say so, then returns the number of words (or 1
if it was a match because of inadequate input).
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
|
# File 'lib/inform/parserm.h.rb', line 3867
def TryGivenObject(obj)
if defined?(DEBUG)
println " Trying " + the(obj) + " (#{obj.object_id}) at word #{@wn + 1}" if @parser_trace >= 5
end
@dict_flags_of_noun = 0
if defined?(DEBUG) && @scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Trying given object..."
println ">>...The word number is #{@wn + 1}"
println ">>...The number of words is #{num_words}"
println ">>...Is @wn > num_words ? #{(@wn + 1) > num_words}"
println ">>...The indefinite mode is #{@indef_mode}"
end
if (@wn + 1) > num_words
if @indef_mode != false
@dict_flags_of_noun = 0b01110000 end
MakeMatch(obj, 0)
if defined?(DEBUG)
print " Matched (0)\n" if @parser_trace >= 5
end return 1
end
if defined?(DEBUG) && @scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>Still trying given object..."
println ">>...The word number is #{@wn + 1}"
println ">>...The number of words is #{num_words}"
println ">>...Is @wn > num_words ? #{(@wn + 1) > num_words}"
end
if obj.respond_to?(:parse_name)
@parser_action = nil; j = @wn
k = RunRoutines(obj, :parse_name)
if defined?(DEBUG) && @scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>...No words match" if k == 0
end
return NoWordsMatch(obj) if k == 0
if k > 0
@wn = j + k
if defined?(DEBUG) && @scope_reason == PARSING_REASON && @parser_trace >= 10
println ">>When trying the given object"
println ">>...The number of words is #{num_words}"
println ">>...The word number is #{@wn + 1}"
println ">>...The threshold is #{k}"
println ">>...Making match by parseable name"
end return MakeMatchByParseName(obj, k)
end
end
@parser_action = nil
i, w = NounWord()
return MakeMatchByParseName(obj, 1) if i == :me && @player == obj
return MakeMatchByParseName(obj, 1) if i == :pronoun && language_pronouns[w] == obj
@wn -= 1
threshold = ParseNoun(obj)
if defined?(DEBUG)
if threshold >= 0 && @parser_trace >= 5 then println " ParseNoun returned #{threshold}" end
end @wn += 1 if threshold < 0
return MakeMatchByParseName(obj, threshold) if threshold > 0
if threshold == 0 || Refers(obj, @wn - 1) == false
return NoWordsMatch(obj)
end
if threshold < 0
threshold = 1
if w.matches_any_exactly?(obj)
@dict_flags_of_noun = dict_par1(w) & @dict_flags_of_noun
else
@dict_flags_of_noun = dict_par1(w) & 0b01110100
end
w = NextWord()
while Refers(obj, @wn - 1)
threshold += 1
if !w.nil?
@dict_flags_of_noun = @dict_flags_of_noun | (dict_par1(w) & 0b01110100)
end
w = NextWord()
end
end
return MakeMatchByParseName(obj, threshold)
end
|
#TryNumber(wordnum) ⇒ Object
Try to get a number out of the word at the given index
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
|
# File 'lib/inform/parserm.h.rb', line 4073
def TryNumber(wordnum)
i = @wn; @wn = wordnum; j = NextWord(); @wn = i
j = NumberWord(j)
return j if j >= 1
if !@words[i].nil? && @words[i].number?
begin
Float(@words[i]).to_i rescue ArgumentError
false
end
else
false end
end
|
#UnpackGrammarLine(line) ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/inform/parserm.h.rb', line 213
def UnpackGrammarLine(line)
@line_token = []
@line_ttype = []
@line_tdata = []
i = 0
line.each do |token|
@line_token[i] = @line_ttype[i] = @line_tdata[i] = token
break if token == :end
AnalyseToken(token)
@params_wanted += 1 if @found_ttype != :preposition
@line_ttype[i] = @found_ttype
@line_tdata[i] = @found_tdata
i += 1
end
@action_to_be = line.action
@action_reversed = line.reversed?
@params_wanted = line.length
line
end
|
#UpperCase(c) ⇒ Object
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
|
# File 'lib/inform/parserm.h.rb', line 4570
def UpperCase(c)
case c
when 'a'..'z'
c = c - 32
when 201, 203, 211, 213, 220
c += 1
when 215, 216
c = c + 2
when 155..157, 164..166, 205..207
c = c + 3
when 181..185, 191..195
c = c + 5
when 169..174
c = c + 6
end
return c
end
|
#UserFilter(obj) ⇒ Object
The UserFilter routine consults the user's filter (or checks on attribute)
to see what already-accepted nouns are acceptable
3448
3449
3450
3451
3452
3453
3454
3455
|
# File 'lib/inform/parserm.h.rb', line 3448
def UserFilter(obj)
if !@token_filter.nil? && !self.respond_to?(@token_filter)
return true if obj.has?(@token_filter)
return false
end
@noun = obj
return indirect(@token_filter)
end
|
#VerbAccepted ⇒ Object
D: Get the verb: try all the syntax lines for that verb
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
|
# File 'lib/inform/parserm.h.rb', line 1076
def VerbAccepted
@meta = @verb.meta?
if @meta && @actor != @player
@best_etype = VerbUnrecognized
@meta = false
raise @best_etype
end
@pronoun_word = nil; @pronoun_obj = nil
if defined?(DEBUG)
if @parser_trace >= 1
println "[Parsing for the verb '#{@verb_word}' (#{@verb.grammars.length} lines)]"
end
end
@nextbest_etype = @best_etype = CannotUnderstandSentence
@multiflag = false
BestGrammar(@verb.grammars)
grammar = @best_grammar
raise CannotUnderstandSentence if grammar.nil?
verb_routine = VerbRoutine(grammar.action).nil?
raise NotImplemented if verb_routine.nil?
if defined?(DEBUG) && @parser_trace >= 10
println ">>Parsed grammar:"
println ">> #{grammar}"
println ">>Expected parameters:"
println ">> #{grammar.expected_parameters}"
println ">>Encountered parameters:"
println ">> #{@parameters}"
println ">>Pattern:"
println ">> #{@pattern}"
println ">>Results:"
println ">> action: #{@results[0]}"
println ">> params: #{@results[1]}"
println ">> entries:"
println ">> - #{@results[2]}"
println ">> - #{@results[3]}"
println ">> multiple_object: #{@multiple_object}"
end
return true
end
|
#WhichOne(ambiguity = @ambiguity) ⇒ Object
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
|
# File 'lib/inform/parserm.h.rb', line 2630
def WhichOne(ambiguity = @ambiguity)
@ambiguity = ambiguity
unless disambiguating?
if @ambiguity.context == :creature
L__M(:Miscellany, 45)
else
L__M(:Miscellany, 46)
end
@match_classes ||= []
@number_of_classes ||= @match_classes.length
j = @number_of_classes
for i in (1..@number_of_classes)
marker = @match_classes.index { |a| a.abs == i }
k = @match_list[marker]
if @match_classes[marker] > 0 then print the(k) else print a(k) end
print COMMA__TX if i < j - 1
print OR__TX if i == j - 1
end
L__M(:Miscellany, 57)
return disambiguate
end
return println(L__M(:Miscellany, 10)) if @buffer.empty?
@words2 = @buffer.split
@verb_word = @words2.first
@verb_word.downcase!
if [ALL1__WD, ALL2__WD, ALL3__WD, ALL4__WD, ALL5__WD].include?(@words2.first)
unless %i[multi multiheld multiexcept multiinside].include?(@ambiguity.context)
@multiple_object.concat @match_list
return true
end
println L__M(:Miscellany, 47)
return WhichOne()
end
if Inform::Grammar::Verbs.lookup @words2.first, @player
@input = @buffer.dup
return disambiguated
end
@input = @words.insert((@match_from || 0), @words2).join(' ')
disambiguated
end
|
#WordAddress(wordnum) ⇒ Object
4063
|
# File 'lib/inform/parserm.h.rb', line 4063
def WordAddress(wordnum); @words[wordnum]; end
|
#WordCount ⇒ Object
4067
|
# File 'lib/inform/parserm.h.rb', line 4067
def WordCount; @words ? @words.length : 0; end
|
#WordInProperty(wd, obj, prop) ⇒ Object
4007
4008
4009
4010
4011
4012
|
# File 'lib/inform/parserm.h.rb', line 4007
def WordInProperty(wd, obj, prop)
k = obj.&prop
return true if k.is_a?(String) && k.split.include?(wd)
return true if k.is_a?(Array) && k.include?(wd)
return false
end
|
#WordLength(wordnum) ⇒ Object
4065
|
# File 'lib/inform/parserm.h.rb', line 4065
def WordLength(wordnum); @words[wordnum] ? @words[wordnum].length : 0; end
|