Skip to content

StatementParser

public static class StatementParser

Inherits: None
Namespace: FractalPike.PikeConsole.Core.RuntimeExecution

Description

Takes unparsed input of any kind and parses it to valid command statements. All valid command statements are not necessarily valid commands, just statements that will be accepted by the StatementExecutor.

The parsing is done in a single pass and only allocates when necessary.

Please note!

The StatementParser is mostly for internal use. Most users can simply rely on the StatementExecutor instead!

No execution happens in the StatementParser. Only parsing!

The parser allows:

  • Multiple statements separated by semicolon ;.
  • Arguments encapsulated within double quotes ".
    Arguments within double qoutes are passed as one argument, even if it contains spaces
  • Breakout logic using backslash \
    • Example: "\"Hello world!\"" will result in "Hello world!".
    • Example 2: "Remember that you can use the escape \\ character" will result in Remember that you can use the escape \ character.
    • Note: Statement separators can be escaped. "Hello \; world!" will result in Hello ; world!.

Properties

No public properties to showcase for this class.

Methods

Scope Return Name
public ParsedStatement ParseLine

Method Descriptions

ParseLine

Signature: public static ParsedStatement[] ParseLine(string input)

Parameter details

string : input
The input string to parse into a list of statements.
This could come from a console line, a weak-link system or a config file.

Description:
Takes a raw input and parses it into valid statement profiles.
These statement profiles are returned as an array.

Example(s):
echo Hello World!; echo "Hello back at you!"; ; ; ; count "one argument" two "three and not four"

Results in:

[
    {command: "echo",   args: ["Hello", "world!"]},
    {command: "echo",   args: ["Hello back at you!"]},
    {command: "count",  args: ["one argument", "two", "three and not four"]}
]

Handling Separators

The parser is designed to be resilient. Multiple consecutive semicolons (; ; ;) or leading/trailing whitespace are automatically ignored and do not produce empty commands or arguments!