Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
7 changes: 4 additions & 3 deletions Cesium.Parser.Tests/PreprocessorTests/PreprocessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,14 @@ public Task FileDefine() => DoTest(
[InlineData("1 || 0", true)]
[InlineData("1 || 1", true)]

// TODO[#532]: Need to add support for parsing negative numbers, now "-" is recognized as a separator
// [InlineData("-10 < 9", true)]
// [InlineData("-10 > 9", false)]

[InlineData("0b11 == 3", true)]
[InlineData("021 == 17", true)]
[InlineData("0xF == 15", true)]
[InlineData("-10 > 9", false)]
[InlineData("-10 < 9", true)]
[InlineData("-10 < -9", true)]
[InlineData("-9 == -9", true)]
public async Task EvaluateExpressionAllVariants(
string expression,
bool expectedResult)
Expand Down
1 change: 1 addition & 0 deletions Cesium.Preprocessor/CPreprocessorTokenType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum CPreprocessorTokenType
[Token("...")]
Ellipsis,

[Regex("-[1-9][0-9]*")]
[Regex("[^ \t\v\f\r\n#;+\\-*/()=!<>\",.|\\[\\]&\\\\]+")]
PreprocessingToken,

Expand Down
3 changes: 3 additions & 0 deletions Cesium.Preprocessor/ConditionExpressions/BinaryExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ int Parse(Location location, string macrosValue)
if (Regex.IsMatch(macrosValue, $"^(0|[1-9][0-9]*)$"))
return int.Parse(macrosValue);

if (Regex.IsMatch(macrosValue, $"^(-[1-9][0-9]*)$"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the change should be in CPreprocessorExpresisonParser I think that's change not applicable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. We belive should not have negative numbers as tokens, expression can have them just fine. Negaive numbers can be treated as unary expression - Token, for example. So likely you should expand expression grammar in the CPreprocessorExpressionParser

Copy link
Contributor Author

@nt-devilboi nt-devilboi Oct 15, 2025

Choose a reason for hiding this comment

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

if unary expression with minus exists, I left it

Copy link
Collaborator

Choose a reason for hiding this comment

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

I strongly suspect that we have other issue here. Numbers are tokens without sign. Sign + or - handled by Unary expression, but that does not work for some reasons.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So probably something wrong with out Regex for PreprocessorToken

[Regex("[^ \t\v\f\r\n#;+\\-*/()=!<>\",.|\\[\\]&\\\\]+")]
PreprocessingToken,

Also I found issue in Yoakke, which generates lexer for us. LanguageDev/Yoakke#186 maybe that's related.

Copy link
Contributor Author

@nt-devilboi nt-devilboi Oct 16, 2025

Choose a reason for hiding this comment

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

I strongly suspect that we have other issue here. Numbers are tokens without sign. Sign + or - handled by Unary expression, but that does not work for some reasons.

currently, PreprocessorToken recognize number with operator - (sub) here.
Now Numbers are tokens without sign but with operator sub and etc.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No it's not, otherwise how do you get token -10 so you need to handle it here.

Copy link
Contributor Author

@nt-devilboi nt-devilboi Oct 17, 2025

Choose a reason for hiding this comment

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

i think error here

double \ is incorrect.
{ACF4787D-B634-4504-8CBF-1760896C6799}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently, the unary expression looks like this
{8B91DF64-F0D4-489C-82C0-453A783A70F4}
the Result from this function will be -10. is it not correct?
I don't understand how should be

return int.Parse(macrosValue);

if (Regex.IsMatch(macrosValue, "^0b[01]+$"))
return Convert.ToInt32(macrosValue[2..], 2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ internal sealed record IdentifierExpression(Location Location, string Identifier
if (Regex.IsMatch(searchValue, $"^(0|[1-9][0-9]*)$")
|| Regex.IsMatch(searchValue, $"^{Regexes.HexLiteral}$")
|| Regex.IsMatch(searchValue, "^0[0-7]+$")
|| Regex.IsMatch(searchValue, "^0b[01]+$"))
|| Regex.IsMatch(searchValue, "^0b[01]+$")
|| Regex.IsMatch(searchValue, "^(-[1-9][0-9]*)$"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the change should be in CPreprocessorExpresisonParser I think that's change not applicable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

{
return searchValue;
}
Expand Down
Loading