Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
f3b0413
Merge pull request #1 from PowerShell/master
vexx32 Aug 12, 2018
41e64d2
Merge pull request #2 from PowerShell/master
vexx32 Aug 16, 2018
8d4e16c
Merge branch 'master' of git://github.com/PowerShell/PowerShell
vexx32 Aug 20, 2018
a636dca
Add typesuffix traits to u and s
vexx32 Aug 20, 2018
4330f28
Add type accelerators for uint, ulong, ushort, and short
vexx32 Aug 20, 2018
03739e1
Add support for parsing uint, ulong, ushort, and short values
vexx32 Aug 20, 2018
377f7b2
Add tests for parsing the new literals
vexx32 Aug 20, 2018
6f84b5a
Add tests for new type accelerators
vexx32 Aug 20, 2018
1730a45
Overlooked a suffix reference I need to change the type of.
vexx32 Aug 20, 2018
74c9c1a
Remove weird copy paste error
vexx32 Aug 20, 2018
dd4c6c2
Address review comments
vexx32 Aug 21, 2018
6d73617
Add More Tests for new literal types.
vexx32 Aug 21, 2018
c37e531
Add comments for decimal weirdness & some tests
vexx32 Aug 21, 2018
3b058d7
Add test for `ud` suffix that should fail
vexx32 Aug 21, 2018
a347629
Fix short parsing
vexx32 Aug 21, 2018
c628341
Forgot the decimal case. Fixed that short parsing.
vexx32 Aug 21, 2018
971d488
Add clarifying comment to uint parsing cases
vexx32 Aug 22, 2018
e4e10a6
Reorder parsing cases for unsigned ints
vexx32 Aug 22, 2018
c09b2f4
Revise parser notation tests
vexx32 Aug 22, 2018
2e498df
Fix Hexadecimal tests
vexx32 Aug 22, 2018
02a2aac
Fix typo in test
vexx32 Aug 22, 2018
40c1751
Pull double conversions into full switch
vexx32 Aug 23, 2018
e0eb299
Remove unnecessary parentheses.
vexx32 Aug 23, 2018
0c802fb
Expand numeric parsing test cases
vexx32 Aug 23, 2018
2626dc0
Add explicit multiplier value tests
vexx32 Aug 23, 2018
13e6a60
Fix Tests' expected values.
vexx32 Aug 23, 2018
fbff8bc
Cover *all* the test cases!
vexx32 Aug 24, 2018
dbfcbac
Fix testcases reference
vexx32 Aug 24, 2018
2a2b6d8
Fix typos in tests
vexx32 Aug 24, 2018
00f1371
Add test cases for numbers beginning with +
vexx32 Aug 27, 2018
9c54f80
Merge branch 'master' of git://github.com/PowerShell/PowerShell
vexx32 Aug 29, 2018
804f1dd
Merge branch 'master' of git://github.com/PowerShell/PowerShell
vexx32 Aug 31, 2018
dc0a9ba
Duplicate NamedAttributeArgumentAst class
vexx32 Aug 31, 2018
e289aad
Build framework for accepting and recognising named arguments for met…
vexx32 Sep 1, 2018
8d39603
Merge branch 'master' of git://github.com/PowerShell/PowerShell
vexx32 Sep 6, 2018
d30e21c
Merge branch 'master' of git://github.com/PowerShell/PowerShell
vexx32 Sep 18, 2018
d0a3b94
Add typesuffix traits to u and s
vexx32 Aug 20, 2018
3fa4ebd
Add type accelerators for uint, ulong, ushort, and short
vexx32 Aug 20, 2018
c387a44
Add support for parsing uint, ulong, ushort, and short values
vexx32 Aug 20, 2018
0c3f2f7
Add tests for parsing the new literals
vexx32 Aug 20, 2018
87cdf3d
Add tests for new type accelerators
vexx32 Aug 20, 2018
bacd4f3
Overlooked a suffix reference I need to change the type of.
vexx32 Aug 20, 2018
f7a730b
Remove weird copy paste error
vexx32 Aug 20, 2018
9479691
Address review comments
vexx32 Aug 21, 2018
240c9e5
Add More Tests for new literal types.
vexx32 Aug 21, 2018
a813e05
Add comments for decimal weirdness & some tests
vexx32 Aug 21, 2018
5e390bd
Add test for `ud` suffix that should fail
vexx32 Aug 21, 2018
49da113
Fix short parsing
vexx32 Aug 21, 2018
d0572e5
Forgot the decimal case. Fixed that short parsing.
vexx32 Aug 21, 2018
0e051ce
Add clarifying comment to uint parsing cases
vexx32 Aug 22, 2018
cf337ea
Reorder parsing cases for unsigned ints
vexx32 Aug 22, 2018
b07ddb9
Revise parser notation tests
vexx32 Aug 22, 2018
1d901a7
Fix Hexadecimal tests
vexx32 Aug 22, 2018
7c784d3
Fix typo in test
vexx32 Aug 22, 2018
19fa1d9
Pull double conversions into full switch
vexx32 Aug 23, 2018
2fc6236
Remove unnecessary parentheses.
vexx32 Aug 23, 2018
5d58a54
Expand numeric parsing test cases
vexx32 Aug 23, 2018
dfc06c0
Add explicit multiplier value tests
vexx32 Aug 23, 2018
40fd2f1
Fix Tests' expected values.
vexx32 Aug 23, 2018
ffc72f4
Cover *all* the test cases!
vexx32 Aug 24, 2018
0aedf7b
Fix testcases reference
vexx32 Aug 24, 2018
5e6f926
Fix typos in tests
vexx32 Aug 24, 2018
f57ddef
Add test cases for numbers beginning with +
vexx32 Aug 27, 2018
9facd21
Merge branch 'Tokenizer/TypeSuffixes' of https://github.com/vexx32/Po…
vexx32 Sep 18, 2018
14e1cd0
Revert changes to AST that crept in from another branch
vexx32 Sep 18, 2018
6dc00c2
Manual revert ast.cs to original
vexx32 Sep 18, 2018
3c470b0
Add typesuffix traits to u and s
vexx32 Aug 20, 2018
c6b7489
Add type accelerators for uint, ulong, ushort, and short
vexx32 Aug 20, 2018
a353bfc
Add support for parsing uint, ulong, ushort, and short values
vexx32 Aug 20, 2018
58f954a
Add tests for parsing the new literals
vexx32 Aug 20, 2018
2d054c9
Add tests for new type accelerators
vexx32 Aug 20, 2018
23557ff
Overlooked a suffix reference I need to change the type of.
vexx32 Aug 20, 2018
5351ec4
Remove weird copy paste error
vexx32 Aug 20, 2018
0bc3974
Address review comments
vexx32 Aug 21, 2018
8303d19
Add More Tests for new literal types.
vexx32 Aug 21, 2018
906df9c
Add comments for decimal weirdness & some tests
vexx32 Aug 21, 2018
d04a940
Add test for `ud` suffix that should fail
vexx32 Aug 21, 2018
26f3183
Fix short parsing
vexx32 Aug 21, 2018
de76b0a
Forgot the decimal case. Fixed that short parsing.
vexx32 Aug 21, 2018
2fade37
Add clarifying comment to uint parsing cases
vexx32 Aug 22, 2018
af9d1eb
Reorder parsing cases for unsigned ints
vexx32 Aug 22, 2018
54946df
Revise parser notation tests
vexx32 Aug 22, 2018
b3b5e88
Fix Hexadecimal tests
vexx32 Aug 22, 2018
38d3398
Fix typo in test
vexx32 Aug 22, 2018
3ea9863
Pull double conversions into full switch
vexx32 Aug 23, 2018
3ff066c
Remove unnecessary parentheses.
vexx32 Aug 23, 2018
b88b6b8
Expand numeric parsing test cases
vexx32 Aug 23, 2018
0852415
Add explicit multiplier value tests
vexx32 Aug 23, 2018
2e1a9c2
Fix Tests' expected values.
vexx32 Aug 23, 2018
f942104
Cover *all* the test cases!
vexx32 Aug 24, 2018
3ac4ae9
Fix testcases reference
vexx32 Aug 24, 2018
b87e4b6
Fix typos in tests
vexx32 Aug 24, 2018
50e6dce
Add test cases for numbers beginning with +
vexx32 Aug 27, 2018
bee225b
Duplicate NamedAttributeArgumentAst class
vexx32 Aug 31, 2018
4ffe824
Build framework for accepting and recognising named arguments for met…
vexx32 Sep 1, 2018
f59cc1e
Add support for parsing uint, ulong, ushort, and short values
vexx32 Aug 20, 2018
cf2e419
Add tests for parsing the new literals
vexx32 Aug 20, 2018
01ad913
Remove weird copy paste error
vexx32 Aug 20, 2018
8135b27
Address review comments
vexx32 Aug 21, 2018
7417725
Add More Tests for new literal types.
vexx32 Aug 21, 2018
49212ac
Add comments for decimal weirdness & some tests
vexx32 Aug 21, 2018
e677fbb
Add test for `ud` suffix that should fail
vexx32 Aug 21, 2018
7c2722c
Fix short parsing
vexx32 Aug 21, 2018
583287a
Add clarifying comment to uint parsing cases
vexx32 Aug 22, 2018
8acc402
Reorder parsing cases for unsigned ints
vexx32 Aug 22, 2018
4736c18
Revise parser notation tests
vexx32 Aug 22, 2018
d8cb6be
Fix typo in test
vexx32 Aug 22, 2018
920faca
Expand numeric parsing test cases
vexx32 Aug 23, 2018
fb1f216
Add explicit multiplier value tests
vexx32 Aug 23, 2018
581c0dc
Fix Tests' expected values.
vexx32 Aug 23, 2018
b711eb4
Cover *all* the test cases!
vexx32 Aug 24, 2018
fec8ef2
Fix testcases reference
vexx32 Aug 24, 2018
bffa60d
Fix typos in tests
vexx32 Aug 24, 2018
bb818d9
Add test cases for numbers beginning with +
vexx32 Aug 27, 2018
5ceba6e
Revert changes to AST that crept in from another branch
vexx32 Sep 18, 2018
cd2bc8e
Manual revert ast.cs to original
vexx32 Sep 18, 2018
a6eb532
Merge branch 'Tokenizer/TypeSuffixes' of https://github.com/vexx32/Po…
vexx32 Sep 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ static CharExtensions()
/* P */ CharTraits.IdentifierStart | CharTraits.VarNameFirst | CharTraits.MultiplierStart,
/* Q */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* R */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* S */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* S */ CharTraits.IdentifierStart | CharTraits.VarNameFirst | CharTraits.TypeSuffix,
/* T */ CharTraits.IdentifierStart | CharTraits.VarNameFirst | CharTraits.MultiplierStart,
/* U */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* U */ CharTraits.IdentifierStart | CharTraits.VarNameFirst | CharTraits.TypeSuffix,
/* V */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* W */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* X */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
Expand Down Expand Up @@ -187,9 +187,9 @@ static CharExtensions()
/* p */ CharTraits.IdentifierStart | CharTraits.VarNameFirst | CharTraits.MultiplierStart,
/* q */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* r */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* s */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* s */ CharTraits.IdentifierStart | CharTraits.VarNameFirst | CharTraits.TypeSuffix,
/* t */ CharTraits.IdentifierStart | CharTraits.VarNameFirst | CharTraits.MultiplierStart,
/* u */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* u */ CharTraits.IdentifierStart | CharTraits.VarNameFirst | CharTraits.TypeSuffix,
/* v */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* w */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
/* x */ CharTraits.IdentifierStart | CharTraits.VarNameFirst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ internal static class CoreTypes
{ typeof(Guid), new[] { "guid" } },
{ typeof(Hashtable), new[] { "hashtable" } },
{ typeof(int), new[] { "int", "int32" } },
{ typeof(Int16), new[] { "int16" } },
{ typeof(Int16), new[] { "short", "int16" } },
{ typeof(long), new[] { "long", "int64" } },
{ typeof(CimInstance), new[] { "ciminstance" } },
{ typeof(CimClass), new[] { "cimclass" } },
Expand Down Expand Up @@ -770,9 +770,9 @@ internal static class CoreTypes
{ typeof(BigInteger), new[] { "bigint" } },
{ typeof(SecureString), new[] { "securestring" } },
{ typeof(TimeSpan), new[] { "timespan" } },
{ typeof(UInt16), new[] { "uint16" } },
{ typeof(UInt32), new[] { "uint32" } },
{ typeof(UInt64), new[] { "uint64" } },
{ typeof(UInt16), new[] { "ushort", "uint16" } },
{ typeof(UInt32), new[] { "uint", "uint32" } },
{ typeof(UInt64), new[] { "ulong", "uint64" } },
{ typeof(Uri), new[] { "uri" } },
{ typeof(ValidateCountAttribute), new[] { "ValidateCount" } },
{ typeof(ValidateDriveAttribute), new[] { "ValidateDrive" } },
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/parser/ast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5354,7 +5354,7 @@ public PipelineAst(IScriptExtent extent, IEnumerable<CommandBaseAst> pipelineEle
/// <exception cref="PSArgumentException">
/// If <paramref name="pipelineElements"/> is null or is an empty collection.
/// </exception>
public PipelineAst(IScriptExtent extent, IEnumerable<CommandBaseAst> pipelineElements) :this (extent, pipelineElements, background: false)
public PipelineAst(IScriptExtent extent, IEnumerable<CommandBaseAst> pipelineElements) :this(extent, pipelineElements, background: false)
{

}
Expand Down Expand Up @@ -5389,7 +5389,7 @@ public PipelineAst(IScriptExtent extent, CommandBaseAst commandAst, bool backgro
/// <exception cref="PSArgumentNullException">
/// If <paramref name="extent"/> or <paramref name="commandAst"/> is null.
/// </exception>
public PipelineAst(IScriptExtent extent, CommandBaseAst commandAst) :this (extent, commandAst, background: false)
public PipelineAst(IScriptExtent extent, CommandBaseAst commandAst) :this(extent, commandAst, background: false)
{

}
Expand Down
164 changes: 143 additions & 21 deletions src/System.Management.Automation/engine/parser/tokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ internal enum TokenizerMode
Signature, // i.e. class or method declaration
}

[Flags]
internal enum NumberSuffixFlags
{
None = 0x0,
Unsigned = 0x1,
Short = 0x2,
Long = 0x4,
Decimal = 0x8
}

//
// Class used to do a partial snapshot of the state of the tokenizer.
// This is used for nested scans on the same string.
Expand Down Expand Up @@ -3237,15 +3247,18 @@ private void ScanNumberAfterDot(StringBuilder sb, ref int signIndex, ref bool no
}
}

private static bool TryGetNumberValue(string strNum, bool hex, bool real, char suffix, long multiplier, out object result)
private static bool TryGetNumberValue(string strNum, bool hex, bool real, NumberSuffixFlags suffix, long multiplier, out object result)
{
checked
{
try
{
NumberStyles style = NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint |
NumberStyles.AllowExponent;
if (suffix == 'd' || suffix == 'D')

// Decimal parser does not accept hex literals, and 'd' is a valid hex character, so will never be read as Decimal literal
// e.g., 0x1d == 29
if (suffix == NumberSuffixFlags.Decimal)
{
decimal d;
if (Decimal.TryParse(strNum, style, NumberFormatInfo.InvariantInfo, out d))
Expand All @@ -3268,17 +3281,44 @@ private static bool TryGetNumberValue(string strNum, bool hex, bool real, char s
{
d = -0.0;
}
if (suffix == 'l' || suffix == 'L')
{
result = ((long)Convert.ChangeType(d, typeof(long), CultureInfo.InvariantCulture)) * multiplier;
}
else

switch (suffix)
{
result = d * multiplier;
case NumberSuffixFlags.None:
result = d * multiplier;
break;
case NumberSuffixFlags.Long:
result = ((long)Convert.ChangeType(d, typeof(long), CultureInfo.InvariantCulture) * multiplier);
break;
case NumberSuffixFlags.Short:
result = (short)((short)Convert.ChangeType(d, typeof(short), CultureInfo.InvariantCulture) * multiplier);
break;
case NumberSuffixFlags.Unsigned | NumberSuffixFlags.Long:
result = (ulong)Convert.ChangeType(d, typeof(ulong), CultureInfo.InvariantCulture) * (ulong)multiplier;
break;
case NumberSuffixFlags.Unsigned | NumberSuffixFlags.Short:
result = (ushort)((ushort)Convert.ChangeType(d, typeof(ushort), CultureInfo.InvariantCulture) * multiplier);
break;
case NumberSuffixFlags.Unsigned:
ulong testresult = (ulong)Convert.ChangeType(d, typeof(ulong), CultureInfo.InvariantCulture) * (ulong)multiplier;
if (testresult < uint.MaxValue)
{
result = (uint)testresult;
}
else
{
result = testresult;
}
break;
default:
result = null;
return false;
}

return true;
}

// TryParse on (real) number fails.
result = null;
return false;
}
Expand All @@ -3294,15 +3334,47 @@ private static bool TryGetNumberValue(string strNum, bool hex, bool real, char s
style = hex ? NumberStyles.AllowHexSpecifier : NumberStyles.AllowLeadingSign;

long longValue;
if (suffix == 'l' || suffix == 'L')
switch (suffix)
{
if (long.TryParse(strNum, style, NumberFormatInfo.InvariantInfo, out longValue))
{
result = longValue * multiplier;
return true;
}
result = null;
return false;
case NumberSuffixFlags.Long:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about "ul"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presently, that one lives under the default case, inside the checks for the Unsigned flags.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry case is not HasFlag. Closed.

if (long.TryParse(strNum, style, NumberFormatInfo.InvariantInfo, out longValue))
{
result = longValue * multiplier;
return true;
}

result = null;
return false;
case NumberSuffixFlags.Short:
if (short.TryParse(strNum, style, NumberFormatInfo.InvariantInfo, out short s))
{
result = (short)(s * multiplier);
return true;
}

result = null;
return false;
default:
if (suffix.HasFlag(NumberSuffixFlags.Unsigned) && ulong.TryParse(strNum, style, NumberFormatInfo.InvariantInfo, out ulong u))
{
u *= (ulong)multiplier;
if (suffix.HasFlag(NumberSuffixFlags.Short) && u <= ushort.MaxValue)
{
result = (ushort)u;
}
else if (!suffix.HasFlag(NumberSuffixFlags.Long) && u <= uint.MaxValue)
{
result = (uint)u;
}
else
{
// ulong
result = u;
}
return true;
}

break;
}

// From here on - the user hasn't specified the type, so we need to figure it out.
Expand Down Expand Up @@ -3377,7 +3449,7 @@ private Token ScanNumber(char firstChar)
|| (AllowSignedNumbers && (firstChar == '+' || firstChar.IsDash())), "Number must start with '.', '-', or digit.");

bool hex, real;
char suffix;
NumberSuffixFlags suffix;
long multiplier;

string strNum = ScanNumberHelper(firstChar, out hex, out real, out suffix, out multiplier);
Expand Down Expand Up @@ -3418,11 +3490,11 @@ private Token ScanNumber(char firstChar)
/// OR
/// return the string format of the number
/// </returns>
private string ScanNumberHelper(char firstChar, out bool hex, out bool real, out char suffix, out long multiplier)
private string ScanNumberHelper(char firstChar, out bool hex, out bool real, out NumberSuffixFlags suffix, out long multiplier)
{
hex = false;
real = false;
suffix = '\0';
suffix = NumberSuffixFlags.None;
multiplier = 1;

bool notNumber = false;
Expand Down Expand Up @@ -3492,8 +3564,58 @@ private string ScanNumberHelper(char firstChar, out bool hex, out bool real, out
if (c.IsTypeSuffix())
{
SkipChar();
suffix = c;
switch (c)
{
case 'u':
case 'U':
suffix |= NumberSuffixFlags.Unsigned;
break;
case 's':
case 'S':
suffix |= NumberSuffixFlags.Short;
break;
case 'l':
case 'L':
suffix |= NumberSuffixFlags.Long;
break;
case 'd':
case 'D':
suffix |= NumberSuffixFlags.Decimal;
break;
default:
notNumber = true;
break;
}

c = PeekChar();

if (c.IsTypeSuffix())
{
SkipChar();
if (suffix == NumberSuffixFlags.Unsigned)
{
switch (c)
{
case 'l':
case 'L':
suffix |= NumberSuffixFlags.Long;
break;
case 's':
case 'S':
suffix |= NumberSuffixFlags.Short;
break;
default:
notNumber = true;
break;
}
}
else
{
notNumber = true;
}

c = PeekChar();
}
}

if (c.IsMultiplierStart())
Expand Down Expand Up @@ -4317,7 +4439,7 @@ internal Token NextToken()
if (InExpressionMode() && (char.IsDigit(c1) || c1 == '.'))
{
bool hex, real;
char suffix;
NumberSuffixFlags suffix;
long multiplier;

// check if the next token is actually a number
Expand Down
Loading