Skip to content
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

C# source generator for docopt usage #77

Merged
merged 143 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 128 commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
61f41da
Add C# source generator from docopt usage
atifaziz Apr 4, 2021
5bea89f
Allow packaging of source generator
atifaziz Apr 4, 2021
04f7336
Remove project reference since DocoptNet is embedded
atifaziz Apr 4, 2021
c271e21
Merge branch 'master' into source-generator
atifaziz Apr 5, 2021
490e650
Merge remote-tracking branch 'upstream/master' into source-generator
atifaziz Apr 5, 2021
41bf0c0
Generate pattern tree as comment
atifaziz Apr 5, 2021
54825a7
Add statically initialized pattern tree
atifaziz Apr 5, 2021
0dc9902
Merge branch 'master' into source-generator
atifaziz Apr 5, 2021
9c67277
Merge remote-tracking branch 'upstream/master' into source-generator
atifaziz Apr 5, 2021
ca85081
Add extension for invariant formatting
atifaziz Apr 6, 2021
eb3425c
Add option value (like default) that was missing
atifaziz Apr 6, 2021
addc09a
Merge branch 'master' into source-generator
atifaziz Apr 24, 2021
ddf1f5a
Merge branch 'master' into source-generator
atifaziz Apr 25, 2021
cd5ebac
Merge remote-tracking branch 'upstream/master' into source-generator
atifaziz Apr 30, 2021
0100f0f
Initial rough-cut of "Apply" as generated code
atifaziz May 1, 2021
7f02925
Add generated code to share results (during development)
atifaziz May 1, 2021
0897db4
Add initial scaffolding for source generation tests
atifaziz May 1, 2021
836079b
Validate & move static part of source generation into resources
atifaziz May 2, 2021
a174cd7
Track only the generated code
atifaziz May 2, 2021
1c1f5af
Merge remote-tracking branch 'upstream/master' into source-generator
atifaziz May 6, 2021
e12b25a
Split common into module and patterns
atifaziz May 6, 2021
5606825
Embed all of DocoptNet into generated code for max reuse
atifaziz May 6, 2021
ec13039
Add arg parsing
atifaziz May 6, 2021
2473361
Add help and version handling
atifaziz May 6, 2021
e7721af
Add C# string literal formatter
atifaziz May 6, 2021
dc66b77
Untabify
atifaziz May 8, 2021
390631f
Add complete code generation of "Apply"
atifaziz May 8, 2021
fb5b2b4
Extract branch patterns for eventual reuse in generated code
atifaziz May 8, 2021
c94f69d
Generalize branch pattern matching
atifaziz May 8, 2021
b4535be
Add indexed looping to generalized branch pattern matching
atifaziz May 9, 2021
7b914e6
Use, as much as possible, static matching logic for generated code
atifaziz May 9, 2021
1583410
Merge remote-tracking branch 'upstream/master' into source-generator
atifaziz May 9, 2021
0147498
Implement a tight source generation DSL
atifaziz May 9, 2021
5f124d1
Merge remote-tracking branch 'upstream/master' into source-generator
atifaziz May 9, 2021
64e3129
Add full test of executing generated code
atifaziz May 9, 2021
3a97cb9
Lift MSBuild warning CS8785 to error
atifaziz May 11, 2021
afc8acc
Add facades to easily test generated NavalFate program
atifaziz May 11, 2021
04d585a
Remove need for support module for generated code
atifaziz May 11, 2021
9e30f9a
Name matcher types consistently
atifaziz May 11, 2021
056ddf8
Rename "OnMatch" of "IBranchPatternMatcher" to "Fold"
atifaziz May 11, 2021
facc894
Remove bad addition of usage as C# source
atifaziz May 14, 2021
c63ab7f
Merge branch 'master' into source-generator
atifaziz May 15, 2021
78a4acf
Generalize program generation for tests
atifaziz May 15, 2021
b8f3ec9
Fix null case for option short/long name
atifaziz May 15, 2021
805d4bb
Fix case of no options causing error CS0826
atifaziz May 15, 2021
961b527
Merge remote-tracking branch 'upstream/master' into HEAD
atifaziz May 16, 2021
a2e789e
Consider match failure if leaves are left at the end
atifaziz May 15, 2021
014d83e
Allow "OptionsShortcut" patterns at init
atifaziz May 15, 2021
94732f4
Handle more "ValueObject" cases
atifaziz May 15, 2021
12741a1
Copy options so they can be modified at runtime
atifaziz May 15, 2021
7f250d8
Use options potentially modified by "ParsePattern"
atifaziz May 15, 2021
5c42c78
Fix indexing errors when no children in a pattern
atifaziz May 15, 2021
1417d30
Fix error CS1525 caused by skipping empty patterns
atifaziz May 15, 2021
0967adb
Add language agnostic tests for source generator output
atifaziz May 15, 2021
52b3641
Remove "DOCNETOPT_GENERATED" that's no longer needed/used
atifaziz May 16, 2021
27f6f73
Add missing propagation of exit arg in NavalFate
atifaziz May 21, 2021
b0a4478
Add port of "arguments_example.py"
atifaziz May 16, 2021
f9e7e72
Fix legacy project GUIDs
atifaziz May 16, 2021
2747fdf
Consolidate source generation targets
atifaziz May 16, 2021
2c9d825
Consolidate source generation properties across samples
atifaziz May 16, 2021
57675df
Enable F5 debugging support for source generation
atifaziz May 25, 2021
cb93a0e
Allow generated Cmd/Opt properties to be true when int > 0
atifaziz May 25, 2021
3ce166e
Add port of "calculator_example.py"
atifaziz May 25, 2021
5e5e798
Add port of "counted_example.py"
atifaziz May 25, 2021
1cd0087
Add port of "odd_even_example.py"
atifaziz May 25, 2021
d1105fc
Add port of "options_example.py"
atifaziz May 25, 2021
6822c3a
Add port of "options_shortcut_example.py"
atifaziz May 25, 2021
6503535
Add port of "quick_example.py"
atifaziz May 25, 2021
de67fda
Revert "Enable F5 debugging support for source generation"
atifaziz May 26, 2021
e950796
Merge remote-tracking branch 'upstream/master' into source-generator
atifaziz May 26, 2021
5bbe08c
Enable F5 debugging support for source generation (🎬 2)
atifaziz Jun 19, 2021
7dfb6f8
Merge branch 'master' into source-generator
atifaziz Aug 17, 2021
e6c8010
Merge branch 'master' into source-generator
atifaziz Aug 17, 2021
c9db880
Fix help & version condition
atifaziz Aug 17, 2021
28bf934
Handle exit error in examples for clean output
atifaziz Aug 17, 2021
29d11b8
Use "Value" instead of "ValueObject"
atifaziz Aug 20, 2021
007a244
Merge remote-tracking branch 'upstream/master' into source-generator
atifaziz Aug 23, 2021
b5556d3
Remove redundant qualifier
atifaziz Aug 23, 2021
1f02dae
Add "StringList" string representation
atifaziz Aug 24, 2021
eac663a
Make generated args as strong-typed as possible
atifaziz Aug 24, 2021
16cd938
Remove args class nesting
atifaziz Aug 24, 2021
6153a78
Remove no longer needed static pattern tree generation
atifaziz Aug 27, 2021
d048519
Inline options list, removing static
atifaziz Aug 27, 2021
01c5a71
Replace object pattern with strong string cast
atifaziz Aug 27, 2021
52b9e7f
Replace last uses of "ValueObject" in pattern matching
atifaziz Aug 27, 2021
fa5ed43
Use "ValueKind" entirely when matching leaves
atifaziz Aug 27, 2021
e6a668f
Remove comment tree in generated code
atifaziz Aug 27, 2021
5baa302
Make iterator methods formatting clearer
atifaziz Aug 27, 2021
87cbf03
Move property modifier generation to common part
atifaziz Aug 27, 2021
d30a9bd
Remove unused string extension
atifaziz Aug 27, 2021
36df455
Add XML doc summary for options
atifaziz Aug 27, 2021
8332450
Rename "InferType" to "MapType"
atifaziz Aug 27, 2021
9aaca1c
Add block to do-while source builder
atifaziz Aug 27, 2021
71fd57d
Expose usage as a constant in addition to help text
atifaziz Aug 27, 2021
e112f5a
Remove extra blank line before help const
atifaziz Aug 28, 2021
6fab8eb
Clean-up code generation
atifaziz Aug 27, 2021
50c9e65
Revert to non-thread-static code builder
atifaziz Aug 30, 2021
4382a1d
Delegate some generated code to static module
atifaziz Aug 31, 2021
439bb08
Replace do-while for scoping purely with empty block
atifaziz Aug 31, 2021
cc773c3
Name top-required pattern more clearly
atifaziz Aug 31, 2021
752ece9
Move pattern matching code tree into local function
atifaziz Aug 31, 2021
8250966
Reuse "Assign" in "Const"
atifaziz Aug 31, 2021
d0b5852
Make "SwitchFlow" return type consistent with rest
atifaziz Aug 31, 2021
cc7e66b
Connect more parts of the generated code
atifaziz Aug 31, 2021
24ac5d0
Move const names into consts
atifaziz Aug 31, 2021
d3617fd
Rename help text const name to simply "Help"
atifaziz Aug 31, 2021
9d31156
Clean-up accessibility of "CSharpSourceBuilder" members
atifaziz Aug 31, 2021
3955331
Convert "CSharpSourceBuilder.StringBuilder" to auto-property
atifaziz Aug 31, 2021
d3c6c91
Connect all generated code
atifaziz Aug 31, 2021
8ff3f6e
Enable nullable annotations for source generator
atifaziz Aug 31, 2021
27eeb91
Name leaf vars specifically
atifaziz Aug 31, 2021
0de4efa
Use conventional & conforming names in branch pattern matchers
atifaziz Aug 31, 2021
816e9bd
Consolidate "Next" implementation for most branch pattern matchers
atifaziz Aug 31, 2021
e7ba98a
Improve "OneOrMoreMatcher.Result" code formatting
atifaziz Aug 31, 2021
094e802
Move branch pattern matching together
atifaziz Aug 31, 2021
57b136c
Merge branch 'master' into source-generator
atifaziz Sep 1, 2021
495f904
Add Git examples
atifaziz Sep 1, 2021
c8a0185
Add missing license header
atifaziz Sep 1, 2021
9a2930f
Enable nullable context for most generator project files
atifaziz Sep 1, 2021
c5632ba
Fix variable names
atifaziz Sep 1, 2021
be89878
Add "Arguments" suffix to file name to match class name
atifaziz Sep 1, 2021
10cf72f
Merge branch 'master' into source-generator
atifaziz Sep 1, 2021
9801233
Delete launch settings JSON files
atifaziz Sep 1, 2021
127205c
Fix code formatting
atifaziz Sep 2, 2021
8b50984
Remove unused "Value" to "ValueObject" conversion
atifaziz Sep 2, 2021
b54f6ab
Revert unneeded "Value" accessibility edits
atifaziz Sep 2, 2021
01943e6
Revert unused (T4) code generation changes
atifaziz Sep 2, 2021
3ef3138
Merge branch 'master' into source-generator
atifaziz Sep 2, 2021
922165d
Add missing linked file extension in project
atifaziz Sep 3, 2021
0c5b203
Remove need for SOURCE_GENERATION conditional symbol in tests
atifaziz Sep 4, 2021
fa0c013
Remove "exit" option; for now implemented as "exit: true"
atifaziz Sep 5, 2021
783d813
Fix tests with respect to removal of "exit" parameter
atifaziz Sep 5, 2021
adf7e0c
Combine the "SourceGeneratorTests" parts
atifaziz Sep 5, 2021
adbdefe
Remove ".dll" extension from test assembly name
atifaziz Sep 5, 2021
c2e3cc8
Use project's convention for naming test cases
atifaziz Sep 5, 2021
1cf45cd
Remove extra blank line
atifaziz Sep 6, 2021
20d2410
Wrap "AdditionalFiles" attributes in targets file
atifaziz Sep 6, 2021
7834bf0
Use "docopt" all lower for "SourceItemType"
atifaziz Sep 6, 2021
b00100b
Merge branch 'master' into source-generator
atifaziz Sep 6, 2021
83e09ec
Merge branch 'master' into source-generator
atifaziz Sep 6, 2021
ede640e
Revert duplicate package refs in test project
atifaziz Sep 6, 2021
4de329c
Remove the generated code
atifaziz Sep 11, 2021
0adc6f1
Change diagnostic ID prefix to "DCPT" (remove vowels)
atifaziz Sep 13, 2021
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
11 changes: 11 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
<LangVersion>9</LangVersion>
<Nullable>warnings</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<!--
> [CS8785] warning is emitted if a source generator failed to produce output
> due to an exception and there are no generated files. Since the warning
> is easy to miss among errors from missing sources it's useful to promote
> it to an error.
Credit:
- Andrey Dyatlov
- https://github.com/TessenR/BestPracticesSourceGeneratorsDemo
- b8be40f0e153f46ccc79682397680be1b2649b6d
-->
<MSBuildWarningsAsErrors>CS8785</MSBuildWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
156 changes: 156 additions & 0 deletions DocoptNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,34 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.rst = README.rst
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocoptNet.CodeGeneration", "src\DocoptNet.CodeGeneration\DocoptNet.CodeGeneration.csproj", "{37D45A51-EB3E-4D6D-9943-EF2F3967343C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SourceGenerator", "SourceGenerator", "{99846126-1D88-42CC-897C-ACEA7C2DBB2B}"
ProjectSection(SolutionItems) = preProject
eg\SourceGenerator\Directory.Build.props = eg\SourceGenerator\Directory.Build.props
eg\SourceGenerator\Directory.Build.targets = eg\SourceGenerator\Directory.Build.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NavalFate", "eg\SourceGenerator\NavalFate\NavalFate.csproj", "{E41419E5-251C-4093-ADDE-77EF694964E3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ArgumentsExample", "eg\SourceGenerator\ArgumentsExample\ArgumentsExample.csproj", "{99A5B165-A15E-4CE1-B68E-E0992F4478D9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CalculatorExample", "eg\SourceGenerator\CalculatorExample\CalculatorExample.csproj", "{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CountedExample", "eg\SourceGenerator\CountedExample\CountedExample.csproj", "{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OddEvenExample", "eg\SourceGenerator\OddEvenExample\OddEvenExample.csproj", "{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OptionsExample", "eg\SourceGenerator\OptionsExample\OptionsExample.csproj", "{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OptionsShortcutExample", "eg\SourceGenerator\OptionsShortcutExample\OptionsShortcutExample.csproj", "{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickExample", "eg\SourceGenerator\QuickExample\QuickExample.csproj", "{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocoptNet.Playground", "src\DocoptNet.Playground\DocoptNet.Playground.csproj", "{93595D4E-5AE9-4714-AC8B-1FB24D68A15C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Git", "eg\SourceGenerator\Git\Git.csproj", "{63B571D9-DA1B-4209-B4E2-59F0AC529E06}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -95,6 +121,114 @@ Global
{5A641DFB-CB1A-4044-AF52-554CC8904449}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{5A641DFB-CB1A-4044-AF52-554CC8904449}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{5A641DFB-CB1A-4044-AF52-554CC8904449}.Release|x86.ActiveCfg = Release|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Debug|x86.ActiveCfg = Debug|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Debug|x86.Build.0 = Debug|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Release|Any CPU.Build.0 = Release|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Release|x86.ActiveCfg = Release|Any CPU
{37D45A51-EB3E-4D6D-9943-EF2F3967343C}.Release|x86.Build.0 = Release|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Debug|x86.ActiveCfg = Debug|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Debug|x86.Build.0 = Debug|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Release|Any CPU.Build.0 = Release|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Release|x86.ActiveCfg = Release|Any CPU
{E41419E5-251C-4093-ADDE-77EF694964E3}.Release|x86.Build.0 = Release|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Debug|x86.ActiveCfg = Debug|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Debug|x86.Build.0 = Debug|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Release|Any CPU.Build.0 = Release|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Release|x86.ActiveCfg = Release|Any CPU
{99A5B165-A15E-4CE1-B68E-E0992F4478D9}.Release|x86.Build.0 = Release|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Debug|x86.ActiveCfg = Debug|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Debug|x86.Build.0 = Debug|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Release|Any CPU.Build.0 = Release|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Release|x86.ActiveCfg = Release|Any CPU
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E}.Release|x86.Build.0 = Release|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Debug|x86.ActiveCfg = Debug|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Debug|x86.Build.0 = Debug|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Release|Any CPU.Build.0 = Release|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Release|x86.ActiveCfg = Release|Any CPU
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18}.Release|x86.Build.0 = Release|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Debug|x86.ActiveCfg = Debug|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Debug|x86.Build.0 = Debug|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Release|Any CPU.Build.0 = Release|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Release|x86.ActiveCfg = Release|Any CPU
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B}.Release|x86.Build.0 = Release|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Debug|x86.ActiveCfg = Debug|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Debug|x86.Build.0 = Debug|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Release|Any CPU.Build.0 = Release|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Release|x86.ActiveCfg = Release|Any CPU
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE}.Release|x86.Build.0 = Release|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Debug|x86.ActiveCfg = Debug|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Debug|x86.Build.0 = Debug|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Release|Any CPU.Build.0 = Release|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Release|x86.ActiveCfg = Release|Any CPU
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74}.Release|x86.Build.0 = Release|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Debug|x86.ActiveCfg = Debug|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Debug|x86.Build.0 = Debug|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Release|Any CPU.Build.0 = Release|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Release|x86.ActiveCfg = Release|Any CPU
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D}.Release|x86.Build.0 = Release|Any CPU
{93595D4E-5AE9-4714-AC8B-1FB24D68A15C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93595D4E-5AE9-4714-AC8B-1FB24D68A15C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93595D4E-5AE9-4714-AC8B-1FB24D68A15C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand All @@ -107,12 +241,34 @@ Global
{93595D4E-5AE9-4714-AC8B-1FB24D68A15C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{93595D4E-5AE9-4714-AC8B-1FB24D68A15C}.Release|x86.ActiveCfg = Release|Any CPU
{93595D4E-5AE9-4714-AC8B-1FB24D68A15C}.Release|x86.Build.0 = Release|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Debug|x86.ActiveCfg = Debug|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Debug|x86.Build.0 = Debug|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Release|Any CPU.Build.0 = Release|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Release|x86.ActiveCfg = Release|Any CPU
{63B571D9-DA1B-4209-B4E2-59F0AC529E06}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2B454F8B-D702-4281-80DF-367142007B0C} = {AE631D61-6BE6-438F-A535-955BB9A0218F}
{99846126-1D88-42CC-897C-ACEA7C2DBB2B} = {AE631D61-6BE6-438F-A535-955BB9A0218F}
{E41419E5-251C-4093-ADDE-77EF694964E3} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
{99A5B165-A15E-4CE1-B68E-E0992F4478D9} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
{8BCB1D8B-0233-48C5-B5C6-6E3EDB566D3E} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
{962D6BAB-A7DE-41BC-9E91-567A6EEE4C18} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
{E4EB11FF-6FD7-42F5-A5CD-2C7C2B52568B} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
{6C3733DD-C7BD-47C7-BF9A-691A3D0ACCCE} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
{21E4EA57-6291-4C58-BFC4-CA8ACF48DB74} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
{86843F8B-9B83-4985-9E68-77F9ACF4DA2D} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
{63B571D9-DA1B-4209-B4E2-59F0AC529E06} = {99846126-1D88-42CC-897C-ACEA7C2DBB2B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3DEED27A-6D3F-4F2E-A5D5-1F71648F2413}
Expand Down
14 changes: 14 additions & 0 deletions eg/SourceGenerator/ArgumentsExample/ArgumentsExample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\DocoptNet.CodeGeneration\DocoptNet.CodeGeneration.csproj" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
</ItemGroup>

<Import Project="..\..\..\src\DocoptNet.CodeGeneration\DocoptNet.CodeGeneration.targets" />

</Project>
36 changes: 36 additions & 0 deletions eg/SourceGenerator/ArgumentsExample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using DocoptNet.Generated;
using ArgumentsExample;

ProgramArguments arguments;

try
{
arguments = ProgramArguments.Apply(args, exit: true);
}
catch (DocoptExitException e)
{
Console.WriteLine(e.Message);
return e.ErrorCode;
}
catch (DocoptInputErrorException e)
{
Console.Error.WriteLine(e);
return 0xbd;
atifaziz marked this conversation as resolved.
Show resolved Hide resolved
}

foreach (var (name, value) in arguments)
Console.WriteLine($"{name} = {value}");

Console.WriteLine($@"{{
Copy link
Member

Choose a reason for hiding this comment

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

This is as clean and simple as the Python version. Someone on my team was commenting that there was a lot of magic happening. The good news is that magic is not as costly as one would expect.

Help = {arguments.OptHelp },
V = {arguments.OptV },
Q = {arguments.OptQ },
R = {arguments.OptR },
Left = {arguments.OptLeft },
Right = {arguments.OptRight },
Correction = {arguments.ArgCorrection},
File = [{string.Join(", ", arguments.ArgFile)}],
}}");

return 0;
17 changes: 17 additions & 0 deletions eg/SourceGenerator/ArgumentsExample/Program.docopt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Usage: ArgumentsExample [-vqrh] [FILE] ...
ArgumentsExample (--left | --right) CORRECTION FILE

Process FILE and optionally apply correction to either left-hand side or
right-hand side.

Arguments:
FILE optional input file
CORRECTION correction angle, needs FILE, --left or --right to be present

Options:
-h --help
-v verbose mode
-q quiet mode
-r make report
--left use left-hand side
--right use right-hand side
Loading