Skip to content

Commit 87d5048

Browse files
committed
Add checks for additional numeric literal syntax error edge cases
1 parent 9a9f606 commit 87d5048

File tree

3 files changed

+73
-40
lines changed

3 files changed

+73
-40
lines changed

Assembler.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,15 +786,24 @@ public static OperandType DetermineOperandType(string operand)
786786
: Regex.Match(operand, @"[^0-9_\.](?<!^-)");
787787
if (invalidMatch.Success)
788788
{
789-
throw new SyntaxError(string.Format(Strings.Assembler_Error_Numeric_Invalid_Character, operand, new string(' ', invalidMatch.Index)));
789+
throw new SyntaxError(string.Format(Strings.Assembler_Error_Literal_Invalid_Character, operand, new string(' ', invalidMatch.Index)));
790790
}
791-
if (operand[0] == '.' && operand.Length == 1)
791+
// Edge-case syntax errors not detected by invalid character regular expressions
792+
if ((operand[0] == '.' && operand.Length == 1) || operand == "-.")
792793
{
793-
throw new SyntaxError(Strings.Assembler_Error_Floating_Point_Decimal_Only);
794+
throw new SyntaxError(Strings.Assembler_Error_Literal_Floating_Point_Decimal_Only);
795+
}
796+
if (operand[0] == '-' && operand.Length == 1)
797+
{
798+
throw new SyntaxError(Strings.Assembler_Error_Literal_Negative_Dash_Only);
794799
}
795800
if (operand.IndexOf('.') != operand.LastIndexOf('.'))
796801
{
797-
throw new SyntaxError(string.Format(Strings.Assembler_Error_Numeric_Too_Many_Points, operand, new string(' ', operand.LastIndexOf('.'))));
802+
throw new SyntaxError(string.Format(Strings.Assembler_Error_Literal_Too_Many_Points, operand, new string(' ', operand.LastIndexOf('.'))));
803+
}
804+
if (operand is "0x" or "0b")
805+
{
806+
throw new SyntaxError(Strings.Assembler_Error_Literal_Base_Prefix_Only);
798807
}
799808
return OperandType.Literal;
800809
}

Resources/Localization/Strings.Designer.cs

Lines changed: 51 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/Localization/Strings.resx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,16 +820,16 @@ Consult the language reference for a list of all valid mnemonic/operand combinat
820820
{1}^
821821
Label names may not contain symbols other than underscores, and cannot start with a numeral.</value>
822822
</data>
823-
<data name="Assembler_Error_Numeric_Invalid_Character" xml:space="preserve">
823+
<data name="Assembler_Error_Literal_Invalid_Character" xml:space="preserve">
824824
<value>Invalid character in numeric literal:
825825
{0}
826826
{1}^
827827
Did you forget a '0x' prefix before a hexadecimal number or put a digit other than 1 or 0 in a binary number?</value>
828828
</data>
829-
<data name="Assembler_Error_Floating_Point_Decimal_Only" xml:space="preserve">
829+
<data name="Assembler_Error_Literal_Floating_Point_Decimal_Only" xml:space="preserve">
830830
<value>Floating point numeric literals must contain a digit on at least one side of the decimal point.</value>
831831
</data>
832-
<data name="Assembler_Error_Numeric_Too_Many_Points" xml:space="preserve">
832+
<data name="Assembler_Error_Literal_Too_Many_Points" xml:space="preserve">
833833
<value>Numeric literal contains more than one decimal point:
834834
{0}
835835
{1}^</value>
@@ -1018,4 +1018,10 @@ Press ENTER to continue, or type a command ('help' for command list): </value>
10181018
<data name="Assembler_Error_Label_Empty_Name" xml:space="preserve">
10191019
<value>Label names cannot be empty. Did you mean to include a colon here?</value>
10201020
</data>
1021+
<data name="Assembler_Error_Literal_Negative_Dash_Only" xml:space="preserve">
1022+
<value>Negative numeric literals must contain at least one digit.</value>
1023+
</data>
1024+
<data name="Assembler_Error_Literal_Base_Prefix_Only" xml:space="preserve">
1025+
<value>Numeric literals with a base prefix (0x or 0b) must contain at least one digit after the prefix.</value>
1026+
</data>
10211027
</root>

0 commit comments

Comments
 (0)