This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
2,501 additions
and
1,550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Neo.ConsoleService | ||
{ | ||
[DebuggerDisplay("Value={Value}, Value={Value}")] | ||
internal class CommandQuoteToken : CommandToken | ||
{ | ||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="offset">Offset</param> | ||
/// <param name="value">Value</param> | ||
public CommandQuoteToken(int offset, char value) : base(CommandTokenType.Quote, offset) | ||
{ | ||
if (value != '\'' && value != '"') | ||
{ | ||
throw new ArgumentException("Not valid quote"); | ||
} | ||
|
||
Value = value.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Parse command line quotes | ||
/// </summary> | ||
/// <param name="commandLine">Command line</param> | ||
/// <param name="index">Index</param> | ||
/// <returns>CommandQuoteToken</returns> | ||
internal static CommandQuoteToken Parse(string commandLine, ref int index) | ||
{ | ||
var c = commandLine[index]; | ||
|
||
if (c == '\'' || c == '"') | ||
{ | ||
index++; | ||
return new CommandQuoteToken(index - 1, c); | ||
} | ||
|
||
throw new ArgumentException("No quote found"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Neo.ConsoleService | ||
{ | ||
[DebuggerDisplay("Value={Value}, Count={Count}")] | ||
internal class CommandSpaceToken : CommandToken | ||
{ | ||
/// <summary> | ||
/// Count | ||
/// </summary> | ||
public int Count { get; } | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="offset">Offset</param> | ||
/// <param name="count">Count</param> | ||
public CommandSpaceToken(int offset, int count) : base(CommandTokenType.Space, offset) | ||
{ | ||
Value = "".PadLeft(count, ' '); | ||
Count = count; | ||
} | ||
|
||
/// <summary> | ||
/// Parse command line spaces | ||
/// </summary> | ||
/// <param name="commandLine">Command line</param> | ||
/// <param name="index">Index</param> | ||
/// <returns>CommandSpaceToken</returns> | ||
internal static CommandSpaceToken Parse(string commandLine, ref int index) | ||
{ | ||
int offset = index; | ||
int count = 0; | ||
|
||
for (int ix = index, max = commandLine.Length; ix < max; ix++) | ||
{ | ||
if (commandLine[ix] == ' ') | ||
{ | ||
count++; | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if (count == 0) throw new ArgumentException("No spaces found"); | ||
|
||
index += count; | ||
return new CommandSpaceToken(offset, count); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Neo.ConsoleService | ||
{ | ||
[DebuggerDisplay("Value={Value}, RequireQuotes={RequireQuotes}")] | ||
internal class CommandStringToken : CommandToken | ||
{ | ||
/// <summary> | ||
/// Require quotes | ||
/// </summary> | ||
public bool RequireQuotes { get; } | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="offset">Offset</param> | ||
/// <param name="value">Value</param> | ||
public CommandStringToken(int offset, string value) : base(CommandTokenType.String, offset) | ||
{ | ||
Value = value; | ||
RequireQuotes = value.IndexOfAny(new char[] { '\'', '"' }) != -1; | ||
} | ||
|
||
/// <summary> | ||
/// Parse command line spaces | ||
/// </summary> | ||
/// <param name="commandLine">Command line</param> | ||
/// <param name="index">Index</param> | ||
/// <param name="quote">Quote (could be null)</param> | ||
/// <returns>CommandSpaceToken</returns> | ||
internal static CommandStringToken Parse(string commandLine, ref int index, CommandQuoteToken quote) | ||
{ | ||
int end; | ||
int offset = index; | ||
|
||
if (quote != null) | ||
{ | ||
var ix = index; | ||
|
||
do | ||
{ | ||
end = commandLine.IndexOf(quote.Value[0], ix + 1); | ||
|
||
if (end == -1) | ||
{ | ||
throw new ArgumentException("String not closed"); | ||
} | ||
|
||
if (IsScaped(commandLine, end - 1)) | ||
{ | ||
ix = end; | ||
end = -1; | ||
} | ||
} | ||
while (end < 0); | ||
} | ||
else | ||
{ | ||
end = commandLine.IndexOf(' ', index + 1); | ||
} | ||
|
||
if (end == -1) | ||
{ | ||
end = commandLine.Length; | ||
} | ||
|
||
var ret = new CommandStringToken(offset, commandLine.Substring(index, end - index)); | ||
index += end - index; | ||
return ret; | ||
} | ||
|
||
private static bool IsScaped(string commandLine, int index) | ||
{ | ||
// TODO: Scape the scape | ||
|
||
return (commandLine[index] == '\\'); | ||
} | ||
} | ||
} |
Oops, something went wrong.