-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add Value
to eventually replace ValueObject
#104
Merged
atifaziz
merged 47 commits into
docopt:master
from
atifaziz:ApplicationResultAccumulator
Aug 16, 2021
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
e5c8a93
Replace "ValueObject" with simply "object"
atifaziz dc53de3
Add custom result building
atifaziz b59b26c
Add "Var" to avoid double-boxing
atifaziz 52f31d1
Bring back "ValueObject"
atifaziz 90a7683
Rename "Box" to "Boxed" then "Var" to "Box"
atifaziz 898ca90
Rename builders to accumulators
atifaziz e522b13
Remove non-generic accumulator
atifaziz b763c1f
Convert nil case to error
atifaziz 91c51fd
Convert accumulation switch into aggregate via LINQ
atifaziz a423100
Replace "Parse" with "Application" from "Apply"
atifaziz 895a3f2
Move accumulators to own file
atifaziz 0fe2175
Consolidate duplication across two accumulator implementations
atifaziz fc624d9
Ensure that object box case is of right type
atifaziz 51f895c
Merge branch 'master' into acc
atifaziz 1cd4c1a
Add box generalization
atifaziz 5af79fb
Add tests for "Box<>"
atifaziz 19b9d97
Revert README changes
atifaziz b28f2cd
Revert generated code (used in T4) changes
atifaziz 7f1602c
Remove "Stock" prefix form "ApplicationResultAccumulators"
atifaziz cc73d0d
Remove extra space
atifaziz 0b2045c
Fix leaf pattern string formatting
atifaziz 88c4e5f
Use plain arrays in tests
atifaziz 3884841
Check for "ICollection" instead of "ArrayList"
atifaziz 7b21d9b
Fix stack overflow in value formatting
atifaziz 1963e3f
Simplify value formatting
atifaziz 45b7874
Add value formatting tests
atifaziz e7d43ee
Inline "LeafPattern.Add" into leaf pattern matcher
atifaziz 423a489
Simplify leaf match for int & list
atifaziz 64268d1
Replace bare object values with "Value"
atifaziz 815a5ba
Remove unused "ValueObject" members
atifaziz 74db6b1
Remove unused imports
atifaziz 0613886
Use a stack/cons to represent string list value
atifaziz fdb39b8
Replace "Value.Init" with implicit conversions
atifaziz 56c6600
Disconnect "Command" from "Argument"
atifaziz 46bc837
Add debugger display for "Value"
atifaziz 0514563
Specialize stack as string list
atifaziz 6dc9620
Convert "Value.Box" to a property
atifaziz cbae0c6
Remove unused "StringList" members
atifaziz 407df7c
Merge value kind patterns
atifaziz 1916baf
Rename "Null" value to "None"
atifaziz 3f854d7
Move reversed list formatting into left pattern
atifaziz ca74d7e
Add tests for "Value"
atifaziz a8ce20a
Add tests for "StringList"
atifaziz eac9687
Pass "Value" to "DictionaryAccumulator" subclass for conversion
atifaziz e24ee6f
Add tests for application result accumulators
atifaziz 20d55cd
Add back distinct cases to "IApplicationResultAccumulator"
atifaziz ae4a2e3
Apply suggestions from code review
atifaziz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#nullable enable | ||
|
||
namespace DocoptNet | ||
{ | ||
using System.Collections.Generic; | ||
|
||
interface IApplicationResultAccumulator<T> | ||
{ | ||
T New(); | ||
T Command(T state, string name, bool value); | ||
T Command(T state, string name, int value); | ||
T Argument(T state, string name); | ||
T Argument(T state, string name, string value); | ||
T Argument(T state, string name, StringList value); | ||
T Option(T state, string name); | ||
T Option(T state, string name, bool value); | ||
T Option(T state, string name, string value); | ||
T Option(T state, string name, int value); | ||
T Option(T state, string name, StringList value); | ||
T Error(DocoptBaseException exception); | ||
} | ||
|
||
static class ApplicationResultAccumulators | ||
{ | ||
public static readonly IApplicationResultAccumulator<IDictionary<string, Value>> ValueDictionary = new ValueDictionaryAccumulator(); | ||
public static readonly IApplicationResultAccumulator<IDictionary<string, ValueObject>> ValueObjectDictionary = new ValueObjectDictionaryAccumulator(); | ||
|
||
sealed class ValueDictionaryAccumulator : IApplicationResultAccumulator<IDictionary<string, Value>> | ||
{ | ||
public IDictionary<string, Value> New() => new Dictionary<string, Value>(); | ||
public IDictionary<string, Value> Command(IDictionary<string, Value> state, string name, bool value) => Adding(state, name, value); | ||
public IDictionary<string, Value> Command(IDictionary<string, Value> state, string name, int value) => Adding(state, name, value); | ||
public IDictionary<string, Value> Argument(IDictionary<string, Value> state, string name) => Adding(state, name, Value.None); | ||
public IDictionary<string, Value> Argument(IDictionary<string, Value> state, string name, string value) => Adding(state, name, value); | ||
public IDictionary<string, Value> Argument(IDictionary<string, Value> state, string name, StringList value) => Adding(state, name, value); | ||
public IDictionary<string, Value> Option(IDictionary<string, Value> state, string name) => Adding(state, name, Value.None); | ||
public IDictionary<string, Value> Option(IDictionary<string, Value> state, string name, bool value) => Adding(state, name, value); | ||
public IDictionary<string, Value> Option(IDictionary<string, Value> state, string name, string value) => Adding(state, name, value); | ||
public IDictionary<string, Value> Option(IDictionary<string, Value> state, string name, int value) => Adding(state, name, value); | ||
public IDictionary<string, Value> Option(IDictionary<string, Value> state, string name, StringList value) => Adding(state, name, value); | ||
public IDictionary<string, Value> Error(DocoptBaseException exception) => null!; | ||
|
||
static IDictionary<string, Value> Adding(IDictionary<string, Value> dict, string name, Value value) | ||
{ | ||
dict[name] = value; | ||
return dict; | ||
} | ||
} | ||
|
||
sealed class ValueObjectDictionaryAccumulator : IApplicationResultAccumulator<IDictionary<string, ValueObject>> | ||
{ | ||
public IDictionary<string, ValueObject> New() => new Dictionary<string, ValueObject>(); | ||
public IDictionary<string, ValueObject> Command(IDictionary<string, ValueObject> state, string name, bool value) => Adding(state, name, value); | ||
public IDictionary<string, ValueObject> Command(IDictionary<string, ValueObject> state, string name, int value) => Adding(state, name, value); | ||
public IDictionary<string, ValueObject> Argument(IDictionary<string, ValueObject> state, string name) => Adding(state, name, null); | ||
public IDictionary<string, ValueObject> Argument(IDictionary<string, ValueObject> state, string name, string value) => Adding(state, name, value); | ||
public IDictionary<string, ValueObject> Argument(IDictionary<string, ValueObject> state, string name, StringList value) => Adding(state, name, value); | ||
public IDictionary<string, ValueObject> Option(IDictionary<string, ValueObject> state, string name) => Adding(state, name, null); | ||
public IDictionary<string, ValueObject> Option(IDictionary<string, ValueObject> state, string name, bool value) => Adding(state, name, value); | ||
public IDictionary<string, ValueObject> Option(IDictionary<string, ValueObject> state, string name, string value) => Adding(state, name, value); | ||
public IDictionary<string, ValueObject> Option(IDictionary<string, ValueObject> state, string name, int value) => Adding(state, name, value); | ||
public IDictionary<string, ValueObject> Option(IDictionary<string, ValueObject> state, string name, StringList value) => Adding(state, name, value); | ||
public IDictionary<string, ValueObject> Error(DocoptBaseException exception) => null!; | ||
|
||
static IDictionary<string, ValueObject> Adding(IDictionary<string, ValueObject> dict, string name, object? value) | ||
{ | ||
dict[name] = new ValueObject(value); | ||
return dict; | ||
} | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this to be public? I can't see how a user would inject an accumulator otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think eventually. For now, I wanted to bring this as an internal design, refactoring and changes that can eventually be added to the public API.