-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C# source generator for docopt text files (#77)
- Loading branch information
Showing
62 changed files
with
2,573 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
eg/SourceGenerator/ArgumentsExample/ArgumentsExample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
catch (DocoptExitException e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
return e.ErrorCode; | ||
} | ||
catch (DocoptInputErrorException e) | ||
{ | ||
Console.Error.WriteLine(e); | ||
return 0xbd; | ||
} | ||
|
||
foreach (var (name, value) in arguments) | ||
Console.WriteLine($"{name} = {value}"); | ||
|
||
Console.WriteLine($@"{{ | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
eg/SourceGenerator/CalculatorExample/CalculatorExample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using DocoptNet.Generated; | ||
using CalculatorExample; | ||
|
||
ProgramArguments arguments; | ||
|
||
try | ||
{ | ||
arguments = ProgramArguments.Apply(args); | ||
} | ||
catch (DocoptExitException e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
return e.ErrorCode; | ||
} | ||
catch (DocoptInputErrorException e) | ||
{ | ||
Console.Error.WriteLine(e); | ||
return 0xbd; | ||
} | ||
|
||
foreach (var (name, value) in arguments) | ||
Console.WriteLine($"{name} = {value}"); | ||
|
||
Console.WriteLine($@"{{ | ||
Help = {arguments.OptHelp }, | ||
+ = {arguments.CmdPlus }, | ||
- = {arguments.CmdMinus }, | ||
* = {arguments.CmdStar }, | ||
/ = {arguments.CmdSlash }, | ||
Function = {arguments.ArgFunction}, | ||
Comma = {arguments.CmdComma }, | ||
Value = [{string.Join(", ", arguments.ArgValue)}], | ||
}}"); | ||
|
||
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Not a serious example. | ||
|
||
Usage: | ||
calculator_example.py <value> ( ( + | - | * | / ) <value> )... | ||
calculator_example.py <function> <value> [( , <value> )]... | ||
calculator_example.py (-h | --help) | ||
|
||
Examples: | ||
calculator_example.py 1 + 2 + 3 + 4 + 5 | ||
calculator_example.py 1 + 2 '*' 3 / 4 - 5 # note quotes around '*' | ||
calculator_example.py sum 10 , 20 , 30 , 40 | ||
|
||
Options: | ||
-h, --help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using DocoptNet.Generated; | ||
using CountedExample; | ||
|
||
ProgramArguments arguments; | ||
|
||
try | ||
{ | ||
arguments = ProgramArguments.Apply(args); | ||
} | ||
catch (DocoptExitException e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
return e.ErrorCode; | ||
} | ||
catch (DocoptInputErrorException e) | ||
{ | ||
Console.Error.WriteLine(e); | ||
return 0xbd; | ||
} | ||
|
||
foreach (var (name, value) in arguments) | ||
Console.WriteLine($"{name} = {value}"); | ||
|
||
Console.WriteLine($@"{{ | ||
Help = {arguments.OptHelp }, | ||
V = {arguments.OptV }, | ||
Go = {arguments.CmdGo }, | ||
File = [{string.Join(", ", arguments.ArgFile)}], | ||
Path = {arguments.OptPath }, | ||
}}"); | ||
|
||
return 0; |
Oops, something went wrong.