Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Ink / InkLibs / InkCompiler / InkParser / InkParser_CommandLineInput.cs
  1. namespace Ink
  2. {
  3. public partial class InkParser
  4. {
  5. // Valid returned objects:
  6. // - "help"
  7. // - int: for choice number
  8. // - Parsed.Divert
  9. // - Variable declaration/assignment
  10. // - Epression
  11. // - Lookup debug source for character offset
  12. // - Lookup debug source for runtime path
  13. public CommandLineInput CommandLineUserInput()
  14. {
  15. CommandLineInput result = new CommandLineInput ();
  16. Whitespace ();
  17. if (ParseString ("help") != null) {
  18. result.isHelp = true;
  19. return result;
  20. }
  21. if (ParseString ("exit") != null || ParseString ("quit") != null) {
  22. result.isExit = true;
  23. return result;
  24. }
  25. return (CommandLineInput) OneOf (
  26. DebugSource,
  27. DebugPathLookup,
  28. UserChoiceNumber,
  29. UserImmediateModeStatement
  30. );
  31. }
  32. CommandLineInput DebugSource ()
  33. {
  34. Whitespace ();
  35. if (ParseString ("DebugSource") == null)
  36. return null;
  37. Whitespace ();
  38. var expectMsg = "character offset in parentheses, e.g. DebugSource(5)";
  39. if (Expect (String ("("), expectMsg) == null)
  40. return null;
  41. Whitespace ();
  42. int? characterOffset = ParseInt ();
  43. if (characterOffset == null) {
  44. Error (expectMsg);
  45. return null;
  46. }
  47. Whitespace ();
  48. Expect (String (")"), "closing parenthesis");
  49. var inputStruct = new CommandLineInput ();
  50. inputStruct.debugSource = characterOffset;
  51. return inputStruct;
  52. }
  53. CommandLineInput DebugPathLookup ()
  54. {
  55. Whitespace ();
  56. if (ParseString ("DebugPath") == null)
  57. return null;
  58. if (Whitespace () == null)
  59. return null;
  60. var pathStr = Expect (RuntimePath, "path") as string;
  61. var inputStruct = new CommandLineInput ();
  62. inputStruct.debugPathLookup = pathStr;
  63. return inputStruct;
  64. }
  65. string RuntimePath ()
  66. {
  67. if (_runtimePathCharacterSet == null) {
  68. _runtimePathCharacterSet = new CharacterSet (identifierCharSet);
  69. _runtimePathCharacterSet.Add ('-'); // for c-0, g-0 etc
  70. _runtimePathCharacterSet.Add ('.');
  71. }
  72. return ParseCharactersFromCharSet (_runtimePathCharacterSet);
  73. }
  74. CommandLineInput UserChoiceNumber()
  75. {
  76. Whitespace ();
  77. int? number = ParseInt ();
  78. if (number == null) {
  79. return null;
  80. }
  81. Whitespace ();
  82. if (Parse(EndOfLine) == null) {
  83. return null;
  84. }
  85. var inputStruct = new CommandLineInput ();
  86. inputStruct.choiceInput = number;
  87. return inputStruct;
  88. }
  89. CommandLineInput UserImmediateModeStatement()
  90. {
  91. var statement = OneOf (SingleDivert, TempDeclarationOrAssignment, Expression);
  92. var inputStruct = new CommandLineInput ();
  93. inputStruct.userImmediateModeStatement = statement;
  94. return inputStruct;
  95. }
  96. CharacterSet _runtimePathCharacterSet;
  97. }
  98. }