mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nuxfs: Small fixes.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
5d69659e3c
commit
7479fb53f8
6 changed files with 108 additions and 32 deletions
|
|
@ -26,14 +26,12 @@ function nux.dsl.block.push {
|
|||
local btype="$1"
|
||||
local value="$2"
|
||||
local parent=$(nux.dsl.block.path)
|
||||
nux.log trace "Pushing $NC_White$btype '$value'$NC_No on stack."
|
||||
#nux.log trace "Pushing $NC_White$btype '$value'$NC_No on stack."
|
||||
DSL_BLOCK_TYPE[${#DSL_BLOCK_TYPE[@]}]="$btype"
|
||||
DSL_BLOCK_ID[${#DSL_BLOCK_ID[@]}]="$value"
|
||||
DSL_BLOCK_PATH[${#DSL_BLOCK_PATH[@]}]="$parent/$value";
|
||||
}
|
||||
|
||||
|
||||
|
||||
function nux.dsl.error {
|
||||
local tag="$1"; shift;
|
||||
nux.echo.error "$tag"$NC_No: $*;
|
||||
|
|
@ -41,12 +39,12 @@ function nux.dsl.error {
|
|||
|
||||
function nux.dsl.warning {
|
||||
local tag="$1"; shift;
|
||||
nux.echo.warning "$1"$NC_No: $*;
|
||||
nux.echo.warning "$tag"$NC_No: $*;
|
||||
}
|
||||
|
||||
function nux.dsl.info {
|
||||
local tag="$1"; shift;
|
||||
echo -e $NC_White"$1"$NC_No: $*;
|
||||
echo -e $NC_White"$tag"$NC_No: $*;
|
||||
}
|
||||
|
||||
function nux.dsl.keyword.exec {
|
||||
|
|
@ -54,15 +52,21 @@ function nux.dsl.keyword.exec {
|
|||
local keyword="$2";
|
||||
local FUNC_NAME=$keyword$func;
|
||||
local DEFAULT_NAME=$func;
|
||||
local ALLWAYS_NAME=.allways$func;
|
||||
|
||||
shift; shift;
|
||||
if nux.check.function $ALLWAYS_NAME; then
|
||||
nux.log trace Executing: $NC_White$ALLWAYS_NAME$NC_No "$@";
|
||||
$ALLWAYS_NAME "$@";
|
||||
fi
|
||||
if nux.check.function $FUNC_NAME; then
|
||||
nux.log trace Executing: $NC_White$FUNC_NAME$NC_No "$@";
|
||||
$FUNC_NAME "$@";
|
||||
return;
|
||||
return $?;
|
||||
elif nux.check.function $DEFAULT_NAME; then
|
||||
nux.log trace Executing: $NC_White$DEFAULT_NAME$NC_No "$@";
|
||||
$DEFAULT_NAME "$@";
|
||||
return;
|
||||
return $?;
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +81,7 @@ function nux.dsl.block.start {
|
|||
id="$2";
|
||||
path="$parent/$id";
|
||||
|
||||
#nux.log trace Starting Block: "$keyword" ID: "$id" Parent: $parent
|
||||
nux.log trace Starting Block: "$keyword" ID: "$id" Parent: $parent
|
||||
#nux.log debug "Skip is: $nux_dsl_skip, test should return $(test -z "$nux_dsl_skip")"
|
||||
nux.dsl.block.push "$keyword" "$id"
|
||||
if [[ $path == $nux_dsl_only_subtree* && -z "$nux_dsl_skip" ]]; then
|
||||
|
|
@ -102,21 +106,32 @@ function nux.dsl.block.end {
|
|||
id=$(nux.dsl.block.id)
|
||||
path=$(nux.dsl.block.path)
|
||||
|
||||
nux.log trace Ending block $NC_White"$keyword" "'$id'"
|
||||
#nux.log trace Ending block $NC_White"$keyword" "'$id'"
|
||||
nux.dsl.block.pop "$1"
|
||||
|
||||
if [ "$path" = "$nux_dsl_skip" ];then
|
||||
nux_dsl_skip="";
|
||||
fi
|
||||
nux.dsl.block.pop "$1"
|
||||
if [[ $path == $nux_dsl_only_subtree* ]]; then
|
||||
nux.dsl.keyword.exec .exited "$keyword" "'$id'"
|
||||
|
||||
nux.log trace Ending block $NC_White"$keyword" "'$id'"
|
||||
fi
|
||||
}
|
||||
|
||||
function nux.dsl.load {
|
||||
function nux.dsl.execute {
|
||||
local language=$1
|
||||
local script=$2
|
||||
local language_dir=$(dirname "$language");
|
||||
local script_dir=$(dirname "$script");
|
||||
function .use-dsl {
|
||||
if nux.check.file.exists "$language_dir/$1.dsl"; then
|
||||
source "$language_dir/$1.dsl";
|
||||
elif nux.check.file.exists "$script_dir/$1.dsl"; then
|
||||
source "$script_dir/$1.dsl";
|
||||
else
|
||||
nux.dsl.error $1 Language not found in $NC_White$language_dir$NC_No and $NC_White$script_dir$NC_No
|
||||
exit 1;
|
||||
fi
|
||||
}
|
||||
|
||||
function .entered {
|
||||
nux.log debug Keyword $NC_White$1$NC_No is noop.
|
||||
|
|
@ -129,13 +144,28 @@ function nux.dsl.load {
|
|||
return 1
|
||||
}
|
||||
|
||||
function .arg.parser {
|
||||
keyword="$1"; shift;
|
||||
offset=1;
|
||||
echo """# Parsing arguments
|
||||
|
||||
keyword=$keyword
|
||||
id=\"\$1\""""
|
||||
for var in "$@"; do
|
||||
echo " ${var}=\"\$$offset\""
|
||||
let offset=$offset+1
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
function .block {
|
||||
local keyword="$1"
|
||||
nux.log trace Defining block named $NCWhite"$keyword"
|
||||
nux.log trace Defining block keyword $NC_White"$keyword"
|
||||
#FIXME: Add aliasing of binary of same name.
|
||||
eval """
|
||||
nux.eval """
|
||||
$keyword() {
|
||||
nux.dsl.block.start $keyword "\$@";
|
||||
$(.arg.parser "$@")
|
||||
nux.dsl.block.start $keyword \"\$@\";
|
||||
}
|
||||
end$keyword() {
|
||||
nux.dsl.block.end $keyword
|
||||
|
|
@ -146,14 +176,37 @@ function nux.dsl.load {
|
|||
function .keyword {
|
||||
local keyword="$1"
|
||||
#FIXME: Add aliasing of binary of same name.
|
||||
nux.log trace Defining block named $NCWhite"$keyword"
|
||||
eval """
|
||||
nux.log trace Defining keyword $NC_White"$keyword"
|
||||
nux.eval """
|
||||
$keyword() {
|
||||
nux.dsl.block.start $keyword "\$@";
|
||||
$(.arg.parser "$@")
|
||||
nux.dsl.block.start $keyword \"\$@\";
|
||||
nux.dsl.block.end $keyword;
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
.keyword.virtual() {
|
||||
local keyword=$1
|
||||
.keyword "$@"
|
||||
nux.eval """
|
||||
${keyword}.check() {
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
.block.virtual() {
|
||||
local keyword=$1
|
||||
.block "$@"
|
||||
nux.eval """
|
||||
${keyword}.check() {
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
nux.dsl.block.init
|
||||
$language
|
||||
source "$language.dsl"
|
||||
source "$script"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue