codefactory v0.1.2
CodeFactory README
CodeFactory is Template based repeative pattern code generator. Currenlly C# Only, but will extand to JS/TS and more.
Features
- Generate composed code from template
- Structured(Permutated/Combined) Snippets Alike
- Template srouce code act like snippets
- Template Paramter act like placeholders in snippets
- Paramter Generation helps create complex pattern
- JS base CodeFactory Marks inside code comment
- with CodeFactory Mark generator
- Generate code inside code or any where
- Auto template validation as template can be source file of target language
- Write code blocks => Mark how to generate => go
...Future... Features
- Templet from ClipBoard
- Param Preview / Manager
- Transient line/block CodeFactory without template this need a Param Manager
- Support block comment only language like markdown/html
Concepts
- Template
- Sub named gorup of CodeFactory actions, Template,Format,Build,Expand,Remove,Keep with name can all be refered as Sub
- Parameter
- Rule
- Format Basic building block of CodeFactory, all CodeFactory action are structured formats
- Build(line/block)
- Build/Expand
- Find/Pattern
- Line/Block
- Regex match/named group
Name space (cfName) All CodeFactory Sub is refferenced by cfName if cfName has a string befroe '#' that will be used as a path(relative or absolute) to the file where the CodeFactory Sub will be sreached cfName after '#' is scoped by '.' each cfTemplate/cfDeclear starts a deeper scope
CodeFactory Marks: The Commandlet
Detail explain of each CodeFactory in source marks. Note: The :Enumname, pattern is the enum values for each command let used for CodeFactory to choose command. They are of this shape to make multi-select and past to CodeFactory as enum type easier, while will in turn keep doc and code in sync.
EnumTemplate, Example: #cf #Tpl[cfName] Parameters ... #cf Tpl#
Template Scope (default with keep context), Template can be nestedEnumOverrideContext, Example: #cf #CtxDel#
switch context to remove all lines without markEnumKeepContext, Example: #cf #CtxKeep#
switch context to keep all lines without markEnumParameterDefine, Example: Param#{n:1,RW:["R","W"]}#
Parameters(TS Object) used by the template
Nested Template will inherit all parent parametersEnumParamGenerator, Example: #cf #ParamGen#[ParamName] (Push|Set)#{Sum(n);}#
Generate Parameter according to a ruleEnumParamCaptureLine, Example: #cf #Capture# [(Find|Pattern)...]
Capture Parameter form source line with a string as [Find] or a regex as [Pattern]
named group in [Pattern] will be added to param of the name. this may turn param to arrayEnumParamCaptureBlock, Example: #cf #Capture [(Find|Pattern)...] ... #cf Capture#
Capture Parameter form source block(mutiple lines) with a regex as [Pattern]
named group in [Pattern] will be added to param of the name. this may turn param to arrayEnumFormatLine, Example: #cf #Fmt#[cfName] (Find|Pattern)
Format a line with matching parameters
Simply a string format Basic building block of CodeFactory action
look for format insert-point with a string as [Find] or a regex as [Pattern]
[Find] match one string with one param
[Pattern] match one named group to one paramEnumFormatBlock, Example: #cf #Fmt[cfName] (Find|Pattern) ... #cf Fmt#
Format a block(mutiple lines) with matching parameters
Simply a string format Basic building block of CodeFactory action
look for format insert-point with a string as [Find] or a regex as [Pattern]
[Find] match one string with one param
[Pattern] match one named group to one paramEnumRebuildLine, Example: #cf #Rbd#[cfName] Pattern (RefSub|FromSub)
Generally used to generated line expression like funtion argument defeinitions
Build block content by following patterns and rules.
look for [Match] with a regex[Pattern] map one named group to one param
pass each [Match] to [Sub] format source with porcessed [Match]EnumRebuildBlock, Example: #cf #Rbd[cfName] Pattern (RefSub|FromSub) ... #cf Rbd#
Generally used to generated block(mutiple lines) expression like strcut field defeinitions
look for format insert-point with a regex as [Pattern]
[Pattern] map one named group to one param
this is not just a string format.
The rule can form complex long output when parameter is a array.
As array can be used as a sequence to be Permutated/Combined.EnumExpandLine, Example: #cf #Expand#[cfName] (Find|Pattern) (RefSub|FromSub)
Generally used to generated mutiple lines of expression of similar format
Build line content into multiple instance lines, by following rule.
find format elemt by 'find' string or regex 'pattern' and generate lines
'find' match one word with one param and rule runs on the word
'pattern' match a pattern to run the rule while each named gorup match a parameter
Rule will be applied to each line per parameter[item].
Mutiple parameters can be permutated by ParamGenerator.
The rule can form complex long output when parameter[item] is a array itself.
As array can be used as a sequence to be Permutated/CombinedEnumExpandBlock, Example: #cf #Expand[cfName] (Find|Pattern) Rule ... #cf Expand#
Generally used to generated mutiple blocks of expression of similar format
Build block content into multiple instance blocks, by following rule.
find format elemt by 'find' string or regex 'pattern' and generate lines
'find' match one word with one param and rule runs on the word
'pattern' match a pattern to run the rule while each named gorup match a parameter
Rule will be applied to each line per parameter[item].
Mutiple parameters can be permutated by ParamGenerator.
The rule can form complex long output when parameter[item] is a array itself.
As array can be used as a sequence to be Permutated/CombinedEnumRemoveLine, Example: #cf #Del#[cfName] (Find|Pattern|)
Remove this line or match in it if Pattern is provided. use this in a Keep contextEnumRemoveBlock, Example: #cf #Del[cfName] (Find|Pattern|) ... #cf Del#
Remove this block or match in it if Pattern is provided. use this in a Keep contextEnumKeepLine, Example: #cf #Keep#[cfName]
Keep this line unchanged, use this in a Override contextEnumKeepBlock, Example: #cf #Keep[cfName] ... #cf Keep#
Keep this block unchanged, use this in a Override contextEnumFind, Example: Find#{name:"MyClass"}#
A string pattern to match
Matched slice will be findd by specific parameter according to the following ruleEnumPattern, Example: Match#{\^[A-Za-z_][A-Za-z0-9_]*$\}#
A RegExp to match
Match will be findd by feeding parameters to groups in the Match acording to the following ruleEnumApplySubLine, Example: #cf #Apply#[cfName] Parameters
Apply CodeFactory Sub:[cfName] with Parameters on current source line
Note: this action dose not use source line from Sub instead it use current source line
Sub can only be a line action.EnumApplySubBlock, Example: #cf #Apply[cfName] Parameters ... #cf Apply#
Apply CodeFactory Sub:[cfName] with Parameters on current source block(mutiple line)
Note: this action dose not use source block from Sub instead it use current source block
Sub can only be a none-template block action.EnumGenerateSubBlock, Example: #cf #Generate[cfName] Parameters ... #cf Generate#
Generate code from Sub:[cfName] with Parameters on current source inert point
Sub can be any CodeFactory action.EnumRefSub, Example: Ref#[cfName] (P#[pnfrom:pnTo]...|)
Apply CodeFactory Sub:[cfName] with Parameters on text caller Sub provides
(P#[pnfrom:pnTo]...|) is parameter name map,
Note: this action dose not use source block from Sub instead it use text caller CodeFactory Sub provides(source/ouput/match)
Sub can only be a line action.EnumUseSub, Example: Use#[cfName] (P#[pnfrom:pnTo...]|)
Generate code from Sub:[cfName] with Parameters on previous CodeFactory Sub match location
Sub can be any CodeFactory action.EnumForEachSubLine, Example: #cf #Each[cfName] [(RefSub|UseSub)...] ... #cf Sub[cfName]#
(Ref or Use) Each Sub on current line contentEnumForEachSubBlock, Example: #cf #Each[cfName] [(RefSub|UseSub)...] ... #cf Sub[cfName]#
(Ref or Use) Each Sub on current block(mutiple line) contentEnumSwitchLine, Example: #cf #Switch[cfName] Pattern #Case[cfName]:(RefSub|UseSub)
Switch sub rutaion based on pattern matchEnumSwitchBlock, Example: #cf #Switch[cfName] Pattern #Case[cfName]:(RefSub|UseSub) ... #cf Switch[cfName] #
Switch sub rutaion based on pattern matchEnumPipeSub, Example: #cf #Generate#[cfName] Parameters=>(RefSub|UseSub)
Feed previous Sub output To following Sub as template sourceEnumCallSub, Example: #cf #Apply#[cfName] Parameters.(RefSub|UseSub)
Feed Each Match from previous Sub will be processed by following Sub before previous Sub returnsEnum//...V0.0.1 Marks above,
...EnumDeclear, Example: #cf #Dec[CfName] ... #cf Dec#
Mark a none-template Scope a special Sub than DO NOT generate code but just a namespace scopeEnumScript, Example: #cf #Script[cfName] Parameters #{TS scripts}#
Sub runs TypeScirpt code that can only be used as RefSub
Where access able var includes:
- SourceBlock: block of source from template
- Matches: list of match source with rang porperty indication insert points
- Params: object with name fields as paramters
Output : Matches[n].text are expected to be replacedEnum//...V0 .0.2 Added Marks above,
...EnumComposeFrom, Example: #cf #New# From Pattern (RefSub|UseSub)
Compose codes based on rule
Note:this is this same as format only template is not from source but from blockEnumPriority, Example: Priority#[0]#
Order of generated code if muiltiple CodeFactory is pipe to the target region at the same timeEnumFixMark, Example: Fix#
Inform CodeFactory that this is a fixing generate action
Code Gen will try to preserv edit based on template rules... not supportted yes...EnumIncludeParam, Example: Include#[param1_s,param2_s]#
include listed parameters from parent scope template, ingoring all others.
Can not be used with ExcParameters.
Include all parameter from parent scope is default fro template with no include/exclude defined, so there are no need to IncludeParam with all names.EnumExcludeParam, Example: Exclude#[param1_s,param2_s]#
Exclude listed parameters from parent scope template, inheriting all others.
Can not be used with IncludeParam.
Nested template will inherit all parent scope parameters by default.
When nested template define a parameter with the same name as in parent scope, that parameter will be overrided.
Overrided parameter anme will be accessable no matter what.Enum//...Future... Marks above,
...Extension Settings
Nah.. But will be...
Known Issues
Bah... WIP Not impletmented
Release Notes
Err... UnReleased