diff options
| author | 2021-07-25 11:33:43 -0400 | |
|---|---|---|
| committer | 2021-07-26 22:55:41 -0400 | |
| commit | 633cf0fcd438ad0dfb05cfaf7f7127b525d8c52f (patch) | |
| tree | 130025d8687ad233200ebd727368a10d11fc623d /example | |
| parent | add inspect_tagmap.md (diff) | |
underwriter: start new argument parser
Diffstat (limited to 'example')
| -rw-r--r-- | example/natargs.md | 2 | ||||
| -rw-r--r-- | example/natargs_python_impl.md | 34 |
2 files changed, 36 insertions, 0 deletions
diff --git a/example/natargs.md b/example/natargs.md new file mode 100644 index 0000000..b9963e7 --- /dev/null +++ b/example/natargs.md @@ -0,0 +1,2 @@ +Natural arguments are those like git commands `git commit`, `git stash`, +etc. They are "natural" since they are arranged like an english sentence. diff --git a/example/natargs_python_impl.md b/example/natargs_python_impl.md new file mode 100644 index 0000000..e80d09a --- /dev/null +++ b/example/natargs_python_impl.md @@ -0,0 +1,34 @@ +The arguments are stored as a trie using python dictonaries. Each node +is a class consisting of two functions and a dict representing a subtree. + +One function is a check on the length of the arguments, and the other +is the function executed on the list of arguments. + +pseudocode +---------- + +``` +def addargs(dict, h::[], chk, f): + if dict[h] exists: + throw exception + dict[h].chk = chk + dict[h].f = f + dict[h].subtree = {} +def addargs(dict, h::t, chk, f): + if dict[h] does not exist: + dict[h].chk = None + dict[h].f = None + dict[h].subtree = addargs(dict[h].subtree, t, chk, f) + +def execargs(dict, h::t): + if dict[h] exists: + f,args = execargs(dict[h].subtree, t) + if f,args is None,None: + if not dict[h].chk(t): + return None,None + return dict[h].f,t + else: + return f,args + else: + return None,None +``` |
