|
1 | | -# Design (Work-in-Progress) |
2 | 1 |
|
3 | | -Inner-class or nested-class is useful for bunching up a set of similar methods into using the same IscBoolean |
| 2 | +# Design Patterns (Python-based) |
| 3 | + |
| 4 | + |
| 5 | +## Factory Pattern |
| 6 | + |
| 7 | +Now for the wrapper of each EBNF. |
| 8 | + |
| 9 | +Given that `PyParsing` portion of `named.conf` EBNF is 100% completed, it would make most sense to wrap each individual `ParseElement` (aka EBNF) of each clause and statement with a new Python wrapper class so that each EBNF will have their own: |
| 10 | + |
| 11 | +* parser of `named.conf` |
| 12 | +* loader of Python token (mixed `dict`/`list`) variable |
| 13 | +* outputter |
| 14 | +* versioning |
| 15 | + * validation |
| 16 | + * verification |
| 17 | + * constraint checking |
| 18 | +* upgrader/downgrader |
| 19 | + |
| 20 | +Wrapping around EBNF as a syntax unit makes maintenance much easier for all things specific to that clause or statement keyword. |
| 21 | + |
| 22 | +Hence, it is imperative to prototype all of the above carefully before engaging in massive wrapping of some 2,400-odd EBNFs. |
| 23 | + |
| 24 | +### Parser - Factory Pattern |
| 25 | + |
| 26 | +Need to weight in on whether to break-up the existing ParseElement classes and re-integrate into a master wrapper class, one has to ask the following: |
| 27 | + |
| 28 | +* Pros of a Master Wrapper Class |
| 29 | + * How much harder is it to maintain if `ParseElement`s were broken up and reintegrated into a wrapper class covering its additional methods? |
| 30 | + * Need to rework all interface design on all `ParserElement` classes for handling of joining `ParseElement` into the new wrapper class just to construct its master parser. |
| 31 | + * Should the token variables be dispersed throughout each of its own class tree? Or maintained as a huge master token variable at the parent class? |
| 32 | + |
| 33 | +* Cons of a Master Wrapper Class |
| 34 | + * How much simpler is it to just start a new wrapper class and leave `PyParsing` alone? Are there any benefits to having this standalone Python token variable containing many `dict`/`list` elements? |
| 35 | + |
| 36 | +* Pros of keeping `ParseElement` classes together |
| 37 | + * Now have a single place to maintain a single EBNF syntax |
| 38 | + |
| 39 | +* Cons of keeping `ParseElement` classes together |
| 40 | + * Now have two separate places to maintain a single EBNF syntax |
| 41 | + |
| 42 | +### Loader - Factory Pattern |
| 43 | +### Outputter - Factory Pattern |
| 44 | +### Versioning - Factory Pattern |
| 45 | + |
| 46 | +## Nested-Class Pattern |
| 47 | + |
| 48 | +Inner-class or nested-class pattern is useful for bunching up a set of similar methods into using the same IscBoolean |
4 | 49 | class. (***DONE***) |
5 | 50 |
|
6 | | -Builder design is useful for doing things like `namedconf().view('red').recursion().get()` (a form of chaining) |
| 51 | + |
| 52 | +## Builder Pattern |
| 53 | + |
| 54 | +Builder pattern is useful for doing things like `namedconf().view('red').recursion().get()` (a form of Python method-chaining). May be possible to extend to be using a more simplified variant of `namedconf.view['red'].recursion.get()`, but this is NOT important now as getting the generated output of `named.conf` from its token variable. |
| 55 | + |
| 56 | + |
| 57 | +## Dataclass Pattern |
7 | 58 |
|
8 | 59 | Dataclass is useful for nesting ISC Bind9 `zone` statement(s) into either under `view` or under `options` clause. |
9 | 60 |
|
| 61 | + |
| 62 | +## Polymorphic Pattern |
| 63 | + |
10 | 64 | Polymorphic class is useful for overextending a class to having additional feature set (such as non-binary values along |
11 | 65 | with `IscBoolean` class' `True`/`False` and `yes`/`no`.) |
12 | 66 |
|
13 | | -# Method |
14 | 67 |
|
15 | | -subclass isc_boolean() |
| 68 | +# Versioning |
16 | 69 |
|
17 | | -subclass print() |
| 70 | +Because the configuration file of `named.conf` comes in various syntax due to evolution of new and obsoleted features, versioning support must be incorporated. |
18 | 71 |
|
19 | | -```python |
20 | | -class A: |
21 | | - def __init__(self): |
22 | | - print("A.__init__()") |
| 72 | +There is several orthogonal aspects of versioning here: |
| 73 | + |
| 74 | +* detection of current version (free-floating) |
| 75 | + * detecting conflict of clause/statement keywords |
| 76 | + * reporting supported range of versions |
| 77 | +* user-defined version (fixed variant) |
| 78 | + * report of ignored clause/statement keywords |
| 79 | + * requires version argument at Python class-level |
| 80 | +* reversioning (upgrade or downgrade) |
| 81 | + * report of ignored clause/statement keywords |
| 82 | + * requires version argument at Python class-level |
| 83 | + |
| 84 | +## Free-Floating Versioning |
| 85 | + |
| 86 | +The `PyParsing` handles all versions of ISC Bind9 from `8.1` to `9.19.1` but version-specific defaulting is discussed under later `Default Values` section. |
23 | 87 |
|
| 88 | +Minimum and maximum version variables are in the parent class along with `get_supported_version_range` method. |
24 | 89 |
|
25 | | -class B(A): |
26 | | - def __init__(self): |
27 | | - print("B.__init__()") |
28 | | - super(B, self).__init__() |
| 90 | +## Fixed Versioning |
| 91 | + |
| 92 | +The user may specify a specific version before loading of the `named.conf` thus may cause error due to version-mismatch, but it would assure the user of its correct version needed for their end-use (such as analysis or validation). This is not fully-implemented. |
| 93 | + |
| 94 | +Would have a `set_desired_version()` and `get_desired_version()` methods in the parent class to be made accessible and readable by all of its subclasses. |
| 95 | + |
| 96 | +## Reversioning |
| 97 | + |
| 98 | +A future capability set may allow for reversioning of the `named.conf` in form of either upgrade or downgrade. |
| 99 | + |
| 100 | +Such reversioning would entail reading the `named.conf` file at a specific or free-floating version, then outputting at a specific version. |
| 101 | + |
| 102 | +This calls for a reconstruction of `PyParsing` given a specific version. We hope to be able to do the following: |
| 103 | + |
| 104 | +```python |
| 105 | + import bind9_parser |
| 106 | + toplevel_config = process_entire_file_content(named_config) |
| 107 | + nc_parser = bind9_parser.clause_statements \ |
| 108 | + .setDebug(g_verbosity) \ |
| 109 | + .setParseAction(myAction2) \ |
| 110 | + .ignore(pp.cStyleComment) \ |
| 111 | + .ignore(pp.cppStyleComment) \ |
| 112 | + .ignore(pp.pythonStyleComment) |
| 113 | + |
| 114 | + nc_parser.set_version('9.6.1') |
| 115 | + nc_tokens = nc_parser.parseString( |
| 116 | + toplevel_config, |
| 117 | + parseAll=True) |
| 118 | + |
| 119 | + # Output a different version |
| 120 | + nc_output = bind9_outputter() |
| 121 | + nc_output.set_version('9.19.1') |
| 122 | + nc_output.read_tokens(nc_tokens) |
| 123 | + nc_output.output_file('new-named.conf') |
29 | 124 | ``` |
30 | 125 |
|
0 commit comments