Skip to content

Commit

Permalink
Ability to query internal paths using inklecate using “DebugPath hell…
Browse files Browse the repository at this point in the history
…o.world.0.1” etc. (For Inky)
  • Loading branch information
joethephish committed Apr 26, 2018
1 parent 2b652ce commit 23ed274
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
1 change: 1 addition & 0 deletions compiler/CommandLineInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class CommandLineInput
public bool isExit;
public int? choiceInput;
public int? debugSource;
public string debugPathLookup;
public object userImmediateModeStatement;
}
}
11 changes: 11 additions & 0 deletions compiler/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ public CommandLineInputResult ReadCommandLineInput (string userInput)
result.output = "DebugSource: " + dm.ToString ();
else
result.output = "DebugSource: Unknown source";
}

// Request for runtime path lookup (to line number)
else if (inputResult.debugPathLookup != null) {
var pathStr = inputResult.debugPathLookup;
var contentResult = _runtimeStory.ContentAtPath (new Runtime.Path (pathStr));
var dm = contentResult.obj.debugMetadata;
if( dm != null )
result.output = "DebugSource: " + dm.ToString ();
else
result.output = "DebugSource: Unknown source";
}

// User entered some ink
Expand Down
40 changes: 39 additions & 1 deletion compiler/InkParser/InkParser_CommandLineInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal partial class InkParser
// - Parsed.Divert
// - Variable declaration/assignment
// - Epression
// - Lookup debug source for character offset
// - Lookup debug source for runtime path
public CommandLineInput CommandLineUserInput()
{
CommandLineInput result = new CommandLineInput ();
Expand All @@ -25,7 +27,12 @@ public CommandLineInput CommandLineUserInput()
return result;
}

return (CommandLineInput) OneOf (DebugSource, UserChoiceNumber, UserImmediateModeStatement);
return (CommandLineInput) OneOf (
DebugSource,
DebugPathLookup,
UserChoiceNumber,
UserImmediateModeStatement
);
}

CommandLineInput DebugSource ()
Expand Down Expand Up @@ -58,6 +65,35 @@ CommandLineInput DebugSource ()
return inputStruct;
}

CommandLineInput DebugPathLookup ()
{
Whitespace ();

if (ParseString ("DebugPath") == null)
return null;

if (Whitespace () == null)
return null;

var pathStr = Expect (RuntimePath, "path") as string;

var inputStruct = new CommandLineInput ();
inputStruct.debugPathLookup = pathStr;
return inputStruct;
}

string RuntimePath ()
{
if (_runtimePathCharacterSet == null) {
_runtimePathCharacterSet = new CharacterSet (identifierCharSet);
_runtimePathCharacterSet.Add ('-'); // for c-0, g-0 etc
_runtimePathCharacterSet.Add ('.');

}

return ParseCharactersFromCharSet (_runtimePathCharacterSet);
}

CommandLineInput UserChoiceNumber()
{
Whitespace ();
Expand Down Expand Up @@ -86,6 +122,8 @@ CommandLineInput UserImmediateModeStatement()
inputStruct.userImmediateModeStatement = statement;
return inputStruct;
}

CharacterSet _runtimePathCharacterSet;
}
}

27 changes: 16 additions & 11 deletions compiler/InkParser/InkParser_Logic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,8 @@ protected Parsed.Object InnerExpression()
// but not if they *only* comprise numbers
protected string Identifier()
{
if (_identifierCharSet == null) {
(_identifierCharSet = new CharacterSet ())
.AddRange ('A', 'Z')
.AddRange ('a', 'z')
.AddRange ('0', '9')
.Add ('_');
// Enable non-ASCII characters for story identifiers.
ExtendIdentifierCharacterRanges(_identifierCharSet);
}

// Parse remaining characters (if any)
var name = ParseCharactersFromCharSet (_identifierCharSet);
var name = ParseCharactersFromCharSet (identifierCharSet);
if (name == null)
return null;

Expand All @@ -395,6 +385,21 @@ protected string Identifier()

return name;
}

CharacterSet identifierCharSet {
get {
if (_identifierCharSet == null) {
(_identifierCharSet = new CharacterSet ())
.AddRange ('A', 'Z')
.AddRange ('a', 'z')
.AddRange ('0', '9')
.Add ('_');
// Enable non-ASCII characters for story identifiers.
ExtendIdentifierCharacterRanges (_identifierCharSet);
}
return _identifierCharSet;
}
}

private CharacterSet _identifierCharSet;
}
Expand Down

0 comments on commit 23ed274

Please sign in to comment.