From 531fcacbe70c5d435321de6df89fbb338bdcb75e Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 4 Jul 2025 06:14:08 +0200 Subject: [PATCH] constants/regex --- sh/main.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 48e7f08..4316a9a 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -163,26 +163,31 @@ rwx_find_shell() { # │ main │ parse │ # ╰──────┴───────╯ +RWX_REGEX_CONSTANT="[_A-Z][_0-9A-Z]*" +RWX_REGEX_FUNCTION="[_A-Za-z][_0-9A-Za-z]*" +RWX_REGEX_SET="=.*" +RWX_REGEX_SPACES="[[:space:]]*" + +RWX_REGEX_BEGIN="^${RWX_REGEX_SPACES}" +RWX_REGEX_OPEN="\ +${RWX_REGEX_SPACES}(${RWX_REGEX_SPACES})${RWX_REGEX_SPACES}{.*" + rwx_parse() { - local ws="[[:space:]]*" - local start="^${ws}" - local constant="[_A-Z][_0-9A-Z]*" - local setting="=.*" - local func="${ws}(${ws})${ws}{.*" - local id="[_a-zA-Z][_a-z0-9A-Z]*" local line + # parse constants RWX_CONSTANTS="" printf "%s\n" "${RWX_CODE}" | - grep "${start}${constant}${setting}" | - sed "s|${start}\\(${constant}\\)${setting}|\\1|" | + grep "${RWX_REGEX_BEGIN}${RWX_REGEX_CONSTANT}${RWX_REGEX_SET}" | + sed "s|${RWX_REGEX_BEGIN}\\(${RWX_REGEX_CONSTANT}\\)${RWX_REGEX_SET}|\\1|" | while IFS= read -r line; do RWX_CONSTANTS="${RWX_CONSTANTS}${line} " done + # parse functions RWX_FUNCTIONS="" printf "%s\n" "${RWX_CODE}" | - grep "${start}${id}${func}" | - sed "s|${start}\\(${id}\\)${func}|\\1|" | + grep "${RWX_REGEX_BEGIN}${RWX_REGEX_FUNCTION}${RWX_REGEX_OPEN}" | + sed "s|${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}|\\1|" | while IFS= read -r line; do RWX_FUNCTIONS="${RWX_FUNCTIONS}${line} "