-
-
Notifications
You must be signed in to change notification settings - Fork 56
Source generation support #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: sebastienros <[email protected]>
…ll arities) Co-authored-by: sebastienros <[email protected]>
Co-authored-by: sebastienros <[email protected]>
…egistry (WIP - investigating duplicate generation issue) Co-authored-by: sebastienros <[email protected]>
…to use ParserHelperRegistry Co-authored-by: sebastienros <[email protected]>
* Initial plan * Implement ISourceable for Always, Fail, Eof, Capture, Not, Discard, Optional Co-authored-by: sebastienros <[email protected]> * Implement ISourceable for Else, ElseError, Error family, and When Co-authored-by: sebastienros <[email protected]> * Implement ISourceable for Identifier, NonWhiteSpaceLiteral Co-authored-by: sebastienros <[email protected]> * Implement ISourceable for WhiteSpaceLiteral, WhiteSpaceParser, PatternLiteral, Seekable Co-authored-by: sebastienros <[email protected]> * Implement ISourceable for remaining parsers: If, StringLiteral, Separated, Select, Switch, WhenFollowedBy, WhenNotFollowedBy, TextBefore, WithWhiteSpaceParser, IParserAdapter, OneOf Co-authored-by: sebastienros <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: sebastienros <[email protected]>
…d performance - Updated various parser classes to replace tuple-based result handling with out parameters for success and value retrieval. - This change simplifies the code by eliminating the need for intermediate variable assignments and enhances readability. - Affected classes include Deferred, LeftAssociative, Not, OneOf, OneOrMany, Optional, Sequence, SequenceAndSkip, SequenceSkipAnd, SkipWhiteSpace, Then, Unary, When, ZeroOrMany, and ZeroOrOne.
…d readability and maintainability
|
@gpetrou 1.6.0-preview.3 is being published with |
|
@Bykiev I am not sure your benchmark is even using the generated source. Current status: [GenerateParser]
[IncludeUsings(
"NCalc.Domain",
"NCalc.Exceptions",
"NCalc.Visitors",
"System.Globalization",
"System.Collections.Concurrent"
)]
[IncludeFiles(
"src/NCalc.Core/Domain/BinaryExpression.cs",
"src/NCalc.Core/Domain/BinaryExpressionType.cs",
"src/NCalc.Core/Parser/Function.cs",
"src/NCalc.Core/Domain/Identifier.cs",
"src/NCalc.Core/Domain/LogicalExpression.cs",
"src/NCalc.Core/Domain/LogicalExpressionList.cs",
"src/NCalc.Core/Domain/TernaryExpression.cs",
"src/NCalc.Core/Domain/UnaryExpression.cs",
"src/NCalc.Core/Domain/UnaryExpressionType.cs",
"src/NCalc.Core/Domain/ValueExpression.cs",
"src/NCalc.Core/Domain/ValueType.cs",
"src/NCalc.Core/Exceptions/NCalcParserException.cs",
"src/NCalc.Core/Exceptions/NCalcException.cs",
"src/NCalc.Core/Exceptions/NCalcFunctionNotFoundException.cs",
"src/NCalc.Core/Exceptions/NCalcParameterNotDefinedException.cs",
"src/NCalc.Core/Exceptions/NCalcParserException.cs",
"src/NCalc.Core/Visitors/ILogicalExpressionVisitor.cs",
"src/NCalc.Core/Parser/LogicalExpressionParserOptions.cs",
"src/NCalc.Core/Parser/ArgumentSeparator.cs",
"src/NCalc.Core/Parser/LogicalExpressionParserContext.cs"
)]
public static Parser<LogicalExpression> CreateExpressionParserComma()
{
return CreateExpressionParser(CultureInfo.InvariantCulture, ',');
}As you see I am trying to apply the generation root on the main grammar, so everything gets generated as part of it, instead of have most parsers be standard and invoke very minimal ones as generated (not much gain otherwise). Still getting errors I am looking into. I may add back the mode where all the files of the current project are part of the compilation phase for the source generation. NCalc is quite complex (some options are questionable). I can see the |
|
@sebastienros, thank you for your inputs, indeed, in my PR most of the time |
|
I was able to use 1.6.0-preview.3 with |
|
@gpetrou slowly rewriting msbuild in Parlot ... Added support for glob patterns in IncludeFiles already after playing with Ncalc. I believe it's already including all referenced projects. Is the missing type from a PackageReference? |
Yes, it is. |
|
@Genteure I fixed all the possible compilation issues, at least it works on NCalc which relies on compiled regexes, logging source gen and PolySharp. Just saying that Parlot's source generator will also invoke other source generator so it can build and run the host assembly so it can generate new code for this same host assembly. Not sure how to feel about it, but it seems to work. I am pushing a new version right now. @Bykiev Made some progress and hitting a problem with the outer LeftAssociative parser that throws an exception, I don't understand what it does, neither does the source gen ;) |
|
I was watching the repository so this is already in my inbox, but appreciate the update 🙂 |
|
Should the new version work with |
|
@gpetrou ignore this one. Parlot stubs this one, and logger generator too. It should just work, my benchmark project had one too and it works. |
|
Oh, I see. OK thanks. It seems to be missing the |
…proved performance and memory efficiency
# Conflicts: # src/Parlot/Fluent/LeftAssociative.cs # src/Parlot/Fluent/Unary.cs
|
@gpetrou I added a test with you sample, it's working fine. NCalc is also working correctly without crazy changes. All the things that needed to be altered were described with the analyzer so it was smooth. The most copmlicated was to make the grammar change based on external options, since this can't be done when the parser is constructed anymore, but it all works out with the available parsers combinators (Select). ncalc/ncalc#533 |
- Replace environment variable checks (MSBuildExtensionsPath, MSBUILD_EXE_PATH) with DesignTimeBuild property - DesignTimeBuild is the official MSBuild property set during design-time builds (IDE IntelliSense) - Simplifies detection logic and improves reliability - Prevents assembly loading conflicts when running additional generators in IDE contexts
@lahma @jbevain just to show you how it's done.
The logic is not part of the source generator and is driven by user code execution, not code syntax.
The source generator has to run the code first to get the object describing the grammar. Then evaluates the generated tree, not the code itself. That requires the code to be in a static method but that's totally fine. If the grammar needs options then one can generate different parser for each option, and reuse grammar portions across.