From 6ec235ce192eff0bf448e67fc3cddb2e32c065ac Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Sun, 11 Jun 2017 00:17:56 +0200 Subject: [PATCH] nuxfs: Added macro support. Signed-off-by: Tony Tkacik --- inc/dsl/nuxfs.describe.dsl | 4 ++++ inc/dsl/nuxfs.dsl | 21 ++++++++++++--------- inc/nux-base.inc.sh | 12 ++++++++++++ inc/nux.dsl.inc.sh | 25 +++++++++++++++++-------- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/inc/dsl/nuxfs.describe.dsl b/inc/dsl/nuxfs.describe.dsl index 39b6e56..1651f26 100644 --- a/inc/dsl/nuxfs.describe.dsl +++ b/inc/dsl/nuxfs.describe.dsl @@ -3,3 +3,7 @@ .entered() { nux.dsl.info "$rel_path" $keyword } + +.check() { + return 0; +} diff --git a/inc/dsl/nuxfs.dsl b/inc/dsl/nuxfs.dsl index a0efb6a..4ac2e2b 100644 --- a/inc/dsl/nuxfs.dsl +++ b/inc/dsl/nuxfs.dsl @@ -21,6 +21,7 @@ sdir() { .allways.preprocess() { abs_path=$(realpath -Lms "$NUXFS_DEF_DIR/$path"); rel_path=$(realpath -Lms "$abs_path" --relative-base="$WORKDIR"); + def_path=$(realpath -Lms "$path" --relative-to="$NUXFS_DEF_DIR") } .check() { @@ -28,6 +29,17 @@ sdir() { nux.check.file.exists "$abs_path" } +.check.failed() { + if [ -z "$NUXFS_IGNORE_MISSING" ]; then + nux.dsl.error "$rel_path" does not exists. + fi +} +dir.entered() { + if nux.check.file.exists "$abs_path/.nuxfs"; then + source "$abs_path/.nuxfs" + fi +} + should-not-exists.check() { nux.log trace "Checking existence of $NC_White$abs_path$NC_No" if nux.check.file.exists "$abs_path"; then @@ -41,12 +53,3 @@ should-not-exists.check.failed() { nux.dsl.error $f Should not exists, but is present. done } - -.check.failed() { - nux.dsl.error "$rel_path" does not exists. -} -dir.entered() { - if nux.check.file.exists "$abs_path/.nuxfs"; then - source "$abs_path/.nuxfs" - fi -} diff --git a/inc/nux-base.inc.sh b/inc/nux-base.inc.sh index a25e8ba..1243a99 100644 --- a/inc/nux-base.inc.sh +++ b/inc/nux-base.inc.sh @@ -74,3 +74,15 @@ function nux.eval { nux.log trace Going to evaluate "$@" eval "$@" } + +function nux.exec.optional { + local FUNC="$1"; shift; + if nux.check.function $FUNC; then + nux.log trace Executing optional: ${NC_White}${FUNC}${NC_No} "$@"; + $FUNC "$@" + fi +} + +function nux.dirty.urlencode { + echo -n "$1" | sed "s/ /%20/g" +} diff --git a/inc/nux.dsl.inc.sh b/inc/nux.dsl.inc.sh index 2ff8348..a0849cd 100644 --- a/inc/nux.dsl.inc.sh +++ b/inc/nux.dsl.inc.sh @@ -55,17 +55,12 @@ function nux.dsl.keyword.exec { 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 + nux.exec.optional $ALLWAYS_NAME "$@"; if nux.check.function $FUNC_NAME; then - nux.log trace Executing: $NC_White$FUNC_NAME$NC_No "$@"; - $FUNC_NAME "$@"; + nux.exec.optional $FUNC_NAME "$@"; return $?; elif nux.check.function $DEFAULT_NAME; then - nux.log trace Executing: $NC_White$DEFAULT_NAME$NC_No "$@"; - $DEFAULT_NAME "$@"; + nux.exec.optional $DEFAULT_NAME "$@"; return $?; fi } @@ -186,6 +181,20 @@ function nux.dsl.execute { """ } + .macro() { + local keyword=$1 + nux.log trace Defining macro $NC_White"$keyword" + nux.eval """ + ${keyword}() { + $(.arg.parser "$@") + nux.exec.optional ${keyword}.entered \"\$@\" + } + end${keyword}() { + return 0; + } + """ + } + .keyword.virtual() { local keyword=$1 .keyword "$@"