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 nested
EnumOverrideContext, Example: #cf #CtxDel#
switch context to remove all lines without mark
EnumKeepContext, Example: #cf #CtxKeep#
switch context to keep all lines without mark
EnumParameterDefine, Example: Param#{n:1,RW:["R","W"]}#
Parameters(TS Object) used by the template
Nested Template will inherit all parent parameters
EnumParamGenerator, Example: #cf #ParamGen#[ParamName] (Push|Set)#{Sum(n);}#
Generate Parameter according to a rule
EnumParamCaptureLine, 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 array
EnumParamCaptureBlock, 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 array
EnumFormatLine, 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 param
EnumFormatBlock, 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 param
EnumRebuildLine, 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/Combined
EnumExpandBlock, 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/Combined
EnumRemoveLine, Example: #cf #Del#[cfName] (Find|Pattern|)
Remove this line or match in it if Pattern is provided. use this in a Keep context
EnumRemoveBlock, Example: #cf #Del[cfName] (Find|Pattern|) ... #cf Del#
Remove this block or match in it if Pattern is provided. use this in a Keep context
EnumKeepLine, Example: #cf #Keep#[cfName]
Keep this line unchanged, use this in a Override context
EnumKeepBlock, Example: #cf #Keep[cfName] ... #cf Keep#
Keep this block unchanged, use this in a Override context
EnumFind, Example: Find#{name:"MyClass"}#
A string pattern to match
Matched slice will be findd by specific parameter according to the following rule
EnumPattern, 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 rule
EnumApplySubLine, 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 content
EnumForEachSubBlock, Example: #cf #Each[cfName] [(RefSub|UseSub)...] ... #cf Sub[cfName]#
(Ref or Use) Each Sub on current block(mutiple line) content
EnumSwitchLine, Example: #cf #Switch[cfName] Pattern #Case[cfName]:(RefSub|UseSub)
Switch sub rutaion based on pattern match
EnumSwitchBlock, Example: #cf #Switch[cfName] Pattern #Case[cfName]:(RefSub|UseSub) ... #cf Switch[cfName] #
Switch sub rutaion based on pattern match
EnumPipeSub, Example: #cf #Generate#[cfName] Parameters=>(RefSub|UseSub)
Feed previous Sub output To following Sub as template source
EnumCallSub, Example: #cf #Apply#[cfName] Parameters.(RefSub|UseSub)
Feed Each Match from previous Sub will be processed by following Sub before previous Sub returns
Enum//...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 scope
EnumScript, 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 replaced
Enum//...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 block
EnumPriority, Example: Priority#[0]#
Order of generated code if muiltiple CodeFactory is pipe to the target region at the same time
EnumFixMark, 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