This package has been deprecated

Author message:

this is a WIP project as a vscode extension not meat for use as normal npm package

codefactory

0.1.2 • Public • Published

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 :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.

Enum[Template,] Example: #cf #Tpl[cfName] Parameters ... #cf Tpl#

Template Scope (default with keep context), Template can be nested

Enum[OverrideContext,] Example: #cf #CtxDel#

switch context to remove all lines without mark

Enum[KeepContext,] Example: #cf #CtxKeep#

switch context to keep all lines without mark

Enum[ParameterDefine,] Example: Param#{n:1,RW:["R","W"]}#

Parameters(TS Object) used by the template
Nested Template will inherit all parent parameters

Enum[ParamGenerator,] Example: #cf #ParamGen#[ParamName] (Push|Set)#{Sum(n);}#

Generate Parameter according to a rule

Enum[ParamCaptureLine,] 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

Enum[ParamCaptureBlock,] 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

Enum[FormatLine,] 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

Enum[FormatBlock,] 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

Enum[RebuildLine,] 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]

Enum[RebuildBlock,] 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.

Enum[ExpandLine,] 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

Enum[ExpandBlock,] 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

Enum[RemoveLine,] Example: #cf #Del#[cfName] (Find|Pattern|)

Remove this line or match in it if Pattern is provided. use this in a Keep context

Enum[RemoveBlock,] 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

Enum[KeepLine,] Example: #cf #Keep#[cfName]

Keep this line unchanged, use this in a Override context

Enum[KeepBlock,] Example: #cf #Keep[cfName] ... #cf Keep#

Keep this block unchanged, use this in a Override context

Enum[Find,] Example: Find#{name:"MyClass"}#

A string pattern to match
Matched slice will be findd by specific parameter according to the following rule

Enum[Pattern,] 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

Enum[ApplySubLine,] 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.

Enum[ApplySubBlock,] 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.

Enum[GenerateSubBlock,] 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.

Enum[RefSub,] 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.

Enum[UseSub,] 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.

Enum[ForEachSubLine,] Example: #cf #Each[cfName] [(RefSub|UseSub)...] ... #cf Sub[cfName]#

(Ref or Use) Each Sub on current line content

Enum[ForEachSubBlock,] Example: #cf #Each[cfName] [(RefSub|UseSub)...] ... #cf Sub[cfName]#

(Ref or Use) Each Sub on current block(mutiple line) content

Enum[SwitchLine,] Example: #cf #Switch[cfName] Pattern #Case[cfName]:(RefSub|UseSub)

Switch sub rutaion based on pattern match

Enum[SwitchBlock,] Example: #cf #Switch[cfName] Pattern #Case[cfName]:(RefSub|UseSub) ... #cf Switch[cfName] #

Switch sub rutaion based on pattern match

Enum[PipeSub,] Example: #cf #Generate#[cfName] Parameters=>(RefSub|UseSub)

Feed previous Sub output To following Sub as template source

Enum[CallSub,] 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,]

...

Enum[Declear,] Example: #cf #Dec[CfName] ... #cf Dec#

Mark a none-template Scope a special Sub than DO NOT generate code but just a namespace scope

Enum[Script,] 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,]

...

Enum[ComposeFrom,] 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

Enum[Priority,] Example: Priority#[0]#

Order of generated code if muiltiple CodeFactory is pipe to the target region at the same time

Enum[FixMark,] 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...

Enum[IncludeParam,] 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.

Enum[ExcludeParam,] 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


Readme

Keywords

none

Package Sidebar

Install

npm i codefactory

Weekly Downloads

2

Version

0.1.2

License

MIT

Unpacked Size

154 kB

Total Files

35

Last publish

Collaborators

  • lieene