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
The Commandlet
CodeFactory Marks: Detail explain of each CodeFactory in source marks. Note: The :Enum[name,] 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.
#cf #Tpl[cfName] Parameters ... #cf Tpl#
Enum[Template,] Example: Template Scope (default with keep context), Template can be nested
#cf #CtxDel#
Enum[OverrideContext,] Example: switch context to remove all lines without mark
#cf #CtxKeep#
Enum[KeepContext,] Example: switch context to keep all lines without mark
Param#{n:1,RW:["R","W"]}#
Enum[ParameterDefine,] Example: Parameters(TS Object) used by the template
Nested Template will inherit all parent parameters
#cf #ParamGen#[ParamName] (Push|Set)#{Sum(n);}#
Enum[ParamGenerator,] Example: Generate Parameter according to a rule
#cf #Capture# [(Find|Pattern)...]
Enum[ParamCaptureLine,] Example: 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
#cf #Capture [(Find|Pattern)...] ... #cf Capture#
Enum[ParamCaptureBlock,] Example: 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
#cf #Fmt#[cfName] (Find|Pattern)
Enum[FormatLine,] Example: 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
#cf #Fmt[cfName] (Find|Pattern) ... #cf Fmt#
Enum[FormatBlock,] Example: 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
#cf #Rbd#[cfName] Pattern (RefSub|FromSub)
Enum[RebuildLine,] Example: 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]
#cf #Rbd[cfName] Pattern (RefSub|FromSub) ... #cf Rbd#
Enum[RebuildBlock,] Example: 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.
#cf #Expand#[cfName] (Find|Pattern) (RefSub|FromSub)
Enum[ExpandLine,] Example: 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
#cf #Expand[cfName] (Find|Pattern) Rule ... #cf Expand#
Enum[ExpandBlock,] Example: 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
#cf #Del#[cfName] (Find|Pattern|)
Enum[RemoveLine,] Example: Remove this line or match in it if Pattern is provided. use this in a Keep context
#cf #Del[cfName] (Find|Pattern|) ... #cf Del#
Enum[RemoveBlock,] Example: Remove this block or match in it if Pattern is provided. use this in a Keep context
#cf #Keep#[cfName]
Enum[KeepLine,] Example: Keep this line unchanged, use this in a Override context
#cf #Keep[cfName] ... #cf Keep#
Enum[KeepBlock,] Example: Keep this block unchanged, use this in a Override context
Find#{name:"MyClass"}#
Enum[Find,] Example: A string pattern to match
Matched slice will be findd by specific parameter according to the following rule
Match#{\^[A-Za-z_][A-Za-z0-9_]*$\}#
Enum[Pattern,] Example: A RegExp to match
Match will be findd by feeding parameters to groups in the Match acording to the following rule
#cf #Apply#[cfName] Parameters
Enum[ApplySubLine,] Example: 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.
#cf #Apply[cfName] Parameters ... #cf Apply#
Enum[ApplySubBlock,] Example: 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.
#cf #Generate[cfName] Parameters ... #cf Generate#
Enum[GenerateSubBlock,] Example: Generate code from Sub:[cfName] with Parameters on current source inert point
Sub can be any CodeFactory action.
Ref#[cfName] (P#[pnfrom:pnTo]...|)
Enum[RefSub,] Example: 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.
Use#[cfName] (P#[pnfrom:pnTo...]|)
Enum[UseSub,] Example: Generate code from Sub:[cfName] with Parameters on previous CodeFactory Sub match location
Sub can be any CodeFactory action.
#cf #Each[cfName] [(RefSub|UseSub)...] ... #cf Sub[cfName]#
Enum[ForEachSubLine,] Example: (Ref or Use) Each Sub on current line content
#cf #Each[cfName] [(RefSub|UseSub)...] ... #cf Sub[cfName]#
Enum[ForEachSubBlock,] Example: (Ref or Use) Each Sub on current block(mutiple line) content
#cf #Switch[cfName] Pattern #Case[cfName]:(RefSub|UseSub)
Enum[SwitchLine,] Example: Switch sub rutaion based on pattern match
#cf #Switch[cfName] Pattern #Case[cfName]:(RefSub|UseSub) ... #cf Switch[cfName] #
Enum[SwitchBlock,] Example: Switch sub rutaion based on pattern match
#cf #Generate#[cfName] Parameters=>(RefSub|UseSub)
Enum[PipeSub,] Example: Feed previous Sub output To following Sub as template source
#cf #Apply#[cfName] Parameters.(RefSub|UseSub)
Enum[CallSub,] Example: Feed Each Match from previous Sub will be processed by following Sub before previous Sub returns
Enum[//...V0.0.1 Marks above,]
...
#cf #Dec[CfName] ... #cf Dec#
Enum[Declear,] Example: Mark a none-template Scope a special Sub than DO NOT generate code but just a namespace scope
#cf #Script[cfName] Parameters #{TS scripts}#
Enum[Script,] Example: 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,]
...
#cf #New# From Pattern (RefSub|UseSub)
Enum[ComposeFrom,] Example: Compose codes based on rule
Note:this is this same as format only template is not from source but from block
Priority#[0]#
Enum[Priority,] Example: Order of generated code if muiltiple CodeFactory is pipe to the target region at the same time
Fix#
Enum[FixMark,] Example: Inform CodeFactory that this is a fixing generate action
Code Gen will try to preserv edit based on template rules... not supportted yes...
Include#[param1_s,param2_s]#
Enum[IncludeParam,] Example: 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.
Exclude#[param1_s,param2_s]#
Enum[ExcludeParam,] Example: 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