feat(package): hemar: continios work
This commit is contained in:
@@ -3,5 +3,5 @@
|
||||
self,
|
||||
pkgs
|
||||
}: {
|
||||
hemar = import ./hemar.nix { inherit self system pkgs; };
|
||||
hemar = import ./hemar { inherit self system pkgs; };
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
{ pkgs, ... }: pkgs.mkShell {
|
||||
buildInputs = (with pkgs; [
|
||||
dash
|
||||
]);
|
||||
}
|
||||
8
devshell/dev/hemar/default.nix
Normal file
8
devshell/dev/hemar/default.nix
Normal file
@@ -0,0 +1,8 @@
|
||||
{ pkgs, ... }: pkgs.mkShell {
|
||||
buildInputs = (with pkgs; [
|
||||
dash
|
||||
(pkgs.writeShellScriptBin "letest" ''
|
||||
${pkgs.dash}/bin/dash ${./test.sh} "$@"
|
||||
'')
|
||||
]);
|
||||
}
|
||||
7
devshell/dev/hemar/test.sh
Normal file
7
devshell/dev/hemar/test.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/dash
|
||||
|
||||
ROOT_DIR="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
||||
|
||||
if [ "${1:?}" = 'test' ]; then
|
||||
dash "${ROOT_DIR}/package/hemar/test.sh"
|
||||
fi
|
||||
@@ -1,17 +1,133 @@
|
||||
#!/bin/dash
|
||||
|
||||
# 0 - text
|
||||
# 1 - deside tag type
|
||||
# 2 - interpolation
|
||||
# 3 - section
|
||||
# 4 - include
|
||||
# 5 - compute
|
||||
STAGE=0
|
||||
STAGE_BUFFER="$(mktemp)"
|
||||
open_tag_flag=0
|
||||
# Syntax scheme:
|
||||
#
|
||||
# hemar
|
||||
# elements
|
||||
#
|
||||
# elements
|
||||
# element
|
||||
# element ws elements
|
||||
#
|
||||
# element
|
||||
# tag
|
||||
# text
|
||||
#
|
||||
# text
|
||||
# text-item
|
||||
# text-item text
|
||||
#
|
||||
# text-item
|
||||
# '0020' . '10FFFF' - '{'
|
||||
# nopatern
|
||||
#
|
||||
# tag
|
||||
# '{[' ws path ws ']}'
|
||||
# '{[' ws loop-statement ws ']}'
|
||||
# '{[' ws include-header ws ']}'
|
||||
# '{[' ws "end" ws ']}'
|
||||
# '{[' ws function ws ']}'
|
||||
#
|
||||
# # loop tag
|
||||
# loop-statemant
|
||||
# "for" string "in" path
|
||||
#
|
||||
# # include tag
|
||||
# include-header
|
||||
# "include" path
|
||||
#
|
||||
# # fucntion tag
|
||||
# function
|
||||
# "compute" language function-body
|
||||
# "compute" - function-body
|
||||
#
|
||||
# language
|
||||
# "dash"
|
||||
# "plpgsql"
|
||||
#
|
||||
# function-body
|
||||
# ""
|
||||
# '0020' . '10FFFF', function-body
|
||||
#
|
||||
# function-character
|
||||
# '0020' . '10FFFF' - ']'
|
||||
# ncpatern
|
||||
#
|
||||
# # path
|
||||
# path
|
||||
# "."
|
||||
# segmented-path
|
||||
#
|
||||
# segmented-path
|
||||
# segment
|
||||
# segment "." segmented-path
|
||||
#
|
||||
# segment
|
||||
# string
|
||||
# index
|
||||
#
|
||||
# index
|
||||
# '\' digit
|
||||
# '\' onenine digits
|
||||
# '\' '-' digit
|
||||
# '\' '-' onenine digits
|
||||
#
|
||||
# # types
|
||||
# string
|
||||
# character
|
||||
# character string
|
||||
#
|
||||
# character
|
||||
# '0020' . '10FFFF' - '"' - '\' - '.' - ']'
|
||||
# '\' escape
|
||||
# ncpatern
|
||||
#
|
||||
# escape
|
||||
# '.'
|
||||
# ']}'
|
||||
# '"'
|
||||
# '\'
|
||||
# '/'
|
||||
# 'b'
|
||||
# 'f'
|
||||
# 'n'
|
||||
# 'r'
|
||||
# 't'
|
||||
# 'u' hex hex hex hex
|
||||
#
|
||||
# hex
|
||||
# digit
|
||||
# 'A' . 'F'
|
||||
# 'a' . 'f'
|
||||
#
|
||||
# digits
|
||||
# digit
|
||||
# digit digits
|
||||
#
|
||||
# digit
|
||||
# '0'
|
||||
# onenine
|
||||
#
|
||||
# onenine
|
||||
# '1' . '9'
|
||||
#
|
||||
# # paterns
|
||||
# ws
|
||||
# ""
|
||||
# '0020' ws
|
||||
# '000A' ws
|
||||
# '000D' ws
|
||||
# '0009' ws
|
||||
#
|
||||
# nopatern
|
||||
# '{' '0020' . '10FFFF' - '['
|
||||
#
|
||||
# ncpatern
|
||||
# ']' '0020' . '10FFFF' - '}'
|
||||
|
||||
# data structure :)
|
||||
|
||||
# AST Plex:
|
||||
#
|
||||
# Type = 0..=5
|
||||
#
|
||||
# Text = string # just a text body
|
||||
@@ -44,9 +160,21 @@ open_tag_flag=0
|
||||
# | Compute
|
||||
# }
|
||||
#
|
||||
# Hemar = {
|
||||
# AbstarctSyntaxTree (ATS) = {
|
||||
# e = [Element] # elements array
|
||||
#}
|
||||
AST=''
|
||||
|
||||
# 0 - text
|
||||
# 1 - deside tag type
|
||||
# 2 - interpolation
|
||||
# 3 - section
|
||||
# 4 - include
|
||||
# 5 - compute
|
||||
STAGE=0
|
||||
STAGE_BUFFER="$(mktemp)"
|
||||
open_tag_flag=0
|
||||
|
||||
# finds close pattern and store the char to the STAGE_BUFFER
|
||||
find_close_pattern() {
|
||||
char="${1:?}"
|
||||
|
||||
0
package/hemar/log.sh
Normal file
0
package/hemar/log.sh
Normal file
@@ -1,12 +1,5 @@
|
||||
#!/bin/dash
|
||||
|
||||
#data_size="$(eval printf '%s' "\$$structname" | wc -c)"
|
||||
#if [ "$data_size" -ge "$(getconf ARG_MAX)" ]; then
|
||||
# # TODO: handle large text
|
||||
# echo "Data too large for an environment variable"
|
||||
# exit 1
|
||||
#fi
|
||||
|
||||
plex_set() {
|
||||
local structname key val regex base esc_key regex esc temp
|
||||
structname=$1 key=$2 val=$3
|
||||
67
package/hemar/plex/backend/file.sh
Normal file
67
package/hemar/plex/backend/file.sh
Normal file
@@ -0,0 +1,67 @@
|
||||
#!/bin/dash
|
||||
|
||||
PLEX_TEMP="$(mktemp -d)"
|
||||
|
||||
plex_set() {
|
||||
local plexfile key val regex base esc_key esc
|
||||
plexfile="${PLEX_TEMP:?}${1:?}" key="${2:?}" val="${3:?}"
|
||||
|
||||
# construct regex for ancestors
|
||||
regex="^$key="
|
||||
|
||||
base=$key
|
||||
while expr "$base" : '.*\.' >/dev/null; do
|
||||
base=$(printf '%s\n' "$base" | sed 's/\.[^.]*$//')
|
||||
esc=$(printf '%s\n' "$base" | sed 's/\./\\./g')
|
||||
regex="$regex|^$esc="
|
||||
done
|
||||
|
||||
# add descendants
|
||||
esc_key="$(printf '%s\n' "$key" | sed 's/\./\\./g')"
|
||||
regex="$regex|^${esc_key}\."
|
||||
|
||||
# remove old
|
||||
grep -v -E "$regex" "$plexfile" > "$plexfile.tmp" && mv "$plexfile.tmp" "$plexfile"
|
||||
|
||||
# add new
|
||||
printf '%s=%s\n' "$key" "$val" >> "$plexfile"
|
||||
}
|
||||
|
||||
plex_child() {
|
||||
local plexfile key
|
||||
plexfile="${PLEX_TEMP:?}${1:?}" key="${2:?}"
|
||||
|
||||
grep "^$key\." "" | sed "s|^$key\.||"
|
||||
}
|
||||
|
||||
plex_val() {
|
||||
local plexfile key
|
||||
plexfile="${PLEX_TEMP:?}${1:?}" key="${2:?}"
|
||||
grep "^$key=" | cut -d= -f2- "$plexfile"
|
||||
}
|
||||
|
||||
plex_fetch() {
|
||||
local plexfile key temp
|
||||
plexfile="${PLEX_TEMP:?}${1:?}" key="${2:?}"
|
||||
|
||||
if temp="$(grep "^$key=" | cut -d= -f2- "$plexfile")"; then
|
||||
printf '%s' "$temp"
|
||||
else
|
||||
grep "^$key\." "" | sed "s|^$key\.||"
|
||||
fi
|
||||
}
|
||||
|
||||
plex_push() {
|
||||
local plex prefix val max idx newidx kv
|
||||
plex="${1:?}" prefix="${2:?}" val="${3:?}"
|
||||
|
||||
# find max index
|
||||
max=0
|
||||
for kv in $(plex_fetch "$plex" "$prefix"); do
|
||||
idx=${kv%%=*}
|
||||
[ "$idx" -gt "$max" ] 2>/dev/null && max=$idx
|
||||
done
|
||||
|
||||
newidx=$((max + 1))
|
||||
plex_set "$plex" "$prefix.$newidx" "$val"
|
||||
}
|
||||
18
package/hemar/plex/plex.sh
Normal file
18
package/hemar/plex/plex.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/dash
|
||||
|
||||
init_plex() {
|
||||
local backend
|
||||
backend=${1:?}
|
||||
|
||||
case "$backend" in
|
||||
env)
|
||||
. ${WORKSPACE}/plex/backend/env_var.sh
|
||||
;;
|
||||
file)
|
||||
. ${WORKSPACE}/plex/backend/file.sh
|
||||
;;
|
||||
*)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -3,4 +3,4 @@
|
||||
WORKSPACE="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
#. "${WORKSPACE:?}/test/plex.sh"
|
||||
. "${WORKSPACE:?}/test/time.sh"
|
||||
. "${WORKSPACE:?}/test/plex/time.sh"
|
||||
|
||||
@@ -83,7 +83,7 @@ count="$WORD_CREATE_ACCURACY"
|
||||
set_word_length 8
|
||||
i=0
|
||||
start=$(date +%s)
|
||||
while [ "$i" -lt "$count" ]; do
|
||||
while [ "$i" -lt "${count:?}" ]; do
|
||||
new_word >/dev/null
|
||||
i=$((i + 1))
|
||||
done
|
||||
@@ -94,11 +94,11 @@ bench_set 'Set element with depth 1 length 8' 1 "$BENCH_ACCURACY" "$wordtime"
|
||||
bench_set 'Set element with depth 2 length 8' 2 "$BENCH_ACCURACY" "$wordtime"
|
||||
bench_set 'Set element with depth 3 length 8' 3 "$BENCH_ACCURACY" "$wordtime"
|
||||
|
||||
count="$W"
|
||||
count="$WORD_CREATE_ACCURACY"
|
||||
set_word_length 2
|
||||
i=0
|
||||
start=$(date +%s)
|
||||
while [ "$i" -lt "$count" ]; do
|
||||
while [ "$i" -lt "${count:?}" ]; do
|
||||
new_word >/dev/null
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user