diff --git a/README.md b/README.md index 61c287b..8a25447 100644 --- a/README.md +++ b/README.md @@ -65,14 +65,28 @@ BPT employs a straightforward grammar whereby any content beyond the top-level d ## Examples -### Variable Replacement +### Variable Modding ``` {{var}} {{var or "abc"}} # Use "abc" if var is empty {{var or {{var2}}}} # Use {{var2}} if var is empty +{{var :- "abc"}} # Alias to {{var or "abc"}} + {{var and "abc"}} # Use "abc" if var is not empty {{var and {{var2}}}} # Use {{var2}} if var is not empty +{{var :+ "abc"}} # Alias to {{var and "abc"}} + +{{var :? "Err msg"}} # Abort rendering when varaible is empty + +{{var % "*:"}} # Remove prefix until first ':' +{{var %% "*:"}} # Remove prefix until last ':' +{{var # ":*"}} # Remove suffix from last ':' +{{var ## ":*"}} # Remove suffix from first ':' +{{var ^}} # Uppercase the first character +{{var ^^}} # Uppercase all characters +{{var ,}} # Lowercase the first character +{{var ,,}} # Lowercase all characters ``` Bash internal variables can also be used: @@ -224,12 +238,14 @@ QUOTE -> ld quote cl ARGS rd . ARGS -> ARGS STMT | STMT . VAR -> ld ID rd - | ld ID or VAR rd - | ld ID or STR rd - | ld ID and VAR rd - | ld ID and STR rd . -BOP -> ne | eq | gt | lt | ge | le - | strne | streq | strgt | strlt | strcm . + | ld ID MOD rd + | ld ID MOD VAR rd + | ld ID MOD STR rd . +MOD -> and | or | err + | pfx | ppfx | sfx | ssfx + | upp | uupp | low | llow . +BOP -> ne | eq | gt | lt | ge | le + | strne | streq | strgt | strlt | strcm . UOP -> ex . ID -> id . STR -> str . diff --git a/bpt.sh b/bpt.sh index 28ce145..aaaed31 100755 --- a/bpt.sh +++ b/bpt.sh @@ -787,10 +787,16 @@ bpt.print_help() { echo " bpt -l \"<<\" -r \">>\" g input.tpl > output.sh" echo echo -e "\033[1mTEMPLATE GRAMMAR EXAMPLES\033[0m" - echo " Variable replacements" + echo " Variable modding" echo ' {{ var }}' echo ' {{ var or "abc" }}' - echo ' {{ var or {{var2}} }}' + echo ' {{ var %% {{var2}} }}' + echo + echo ' Available modifiers are: ' + echo ' replacement: and or :- :+ ' + echo ' non-empty: :?' + echo ' pre/suf-fix: ## # %% %' + echo ' upper/lower: ^^ ^ ,, ,' echo echo " Branching" echo ' {{ {{x}}: {{var1}} : {{var2}} }}'