aboutsummaryrefslogtreecommitdiffstats
path: root/awk/rawk/rawk.awk
diff options
context:
space:
mode:
authorelioat <{ID}+{username}@users.noreply.github.com>2025-07-31 22:35:38 -0400
committerelioat <{ID}+{username}@users.noreply.github.com>2025-07-31 22:35:38 -0400
commitbb344902c1ab24f56a722096726b6fe453ccaa94 (patch)
treec313b8424976cd3dfb82d70163b455968cadbbeb /awk/rawk/rawk.awk
parent94f9179d1a4a3685138976e354734b92c3ebc65a (diff)
downloadtour-bb344902c1ab24f56a722096726b6fe453ccaa94.tar.gz
*
Diffstat (limited to 'awk/rawk/rawk.awk')
-rw-r--r--awk/rawk/rawk.awk35
1 files changed, 23 insertions, 12 deletions
diff --git a/awk/rawk/rawk.awk b/awk/rawk/rawk.awk
index 8180a7b..5ee579b 100644
--- a/awk/rawk/rawk.awk
+++ b/awk/rawk/rawk.awk
@@ -1,11 +1,22 @@
#!/usr/bin/awk -f
+
+# rawk.awk
+
+# Author: @eli_oat
+# License: Public Domain
+# Version:
+RAWK_VERSION = "0.0.1"
+
+# Lets help awk rawk
+
# =============================================================================
-# rawk v2.0.0 - Multi-pass block-based compiler
+# Multi-pass compiler
# =============================================================================
#
-# This compiler transforms rawk code into standard awk with smart standard
-# library inclusion. It uses a multi-pass approach to overcome AWK's variable
-# scoping limitations and ensure deterministic compilation.
+# This compiler transforms rawk code into standard awk and smartly includes only
+# those standard library functions you've actually used. It uses a multi-pass
+# approach to overcome awk's variable scoping limitations and ensure
+# deterministic compilation.
#
# COMPILATION PROCESS:
# Pass 1: Collect all input lines into memory
@@ -27,7 +38,7 @@ BEGIN {
# =============================================================================
# Arrays to store compilation state
- delete lines # All input lines (Pass 1)
+ delete lines # All input lines (Pass 1)
delete FUNCTION_NAMES # User-defined function names (Pass 3)
delete FUNCTION_ARGS # User-defined function arguments (Pass 3)
delete FUNCTION_BODIES # User-defined function bodies (Pass 3)
@@ -307,7 +318,7 @@ END {
# user-defined functions, and the main script body.
# Output header with compilation metadata
- print "# Generated by rawk v2.0.0"
+ print "# Generated with rawk v" RAWK_VERSION
print "# Source: " ARGV[1]
print ""
@@ -334,13 +345,13 @@ END {
# This is the "smart inclusion" feature that only includes functions that are called
for (func_name in USED_STDLIB_FUNCTIONS) {
if (func_name == "assert") {
- print "function assert(condition, message) { if (!condition) { print \"❌ Assertion failed: \" message > \"/dev/stderr\"; exit 1 } }"
+ print "function assert(condition, message) { if (!condition) { print \"Assertion failed: \" message > \"/dev/stderr\"; exit 1 } }"
} else if (func_name == "expect_equal") {
- print "function expect_equal(actual, expected, message) { if (actual != expected) { print \"❌ Expected \" expected \" but got \" actual \" - \" message > \"/dev/stderr\"; exit 1 } }"
+ print "function expect_equal(actual, expected, message) { if (actual != expected) { print \"Expected \" expected \" but got \" actual \" - \" message > \"/dev/stderr\"; exit 1 } }"
} else if (func_name == "expect_true") {
- print "function expect_true(condition, message) { if (!condition) { print \"❌ Expected true but got false - \" message > \"/dev/stderr\"; exit 1 } }"
+ print "function expect_true(condition, message) { if (!condition) { print \"Expected true but got false - \" message > \"/dev/stderr\"; exit 1 } }"
} else if (func_name == "expect_false") {
- print "function expect_false(condition, message) { if (condition) { print \"❌ Expected false but got true - \" message > \"/dev/stderr\"; exit 1 } }"
+ print "function expect_false(condition, message) { if (condition) { print \"Expected false but got true - \" message > \"/dev/stderr\"; exit 1 } }"
} else if (func_name == "is_positive") {
print "function is_positive(value) { return is_number(value) && value > 0 }"
} else if (func_name == "is_negative") {
@@ -465,7 +476,7 @@ END {
# DISPATCH FUNCTION: Dynamic function calling for functional programming
# =============================================================================
# The dispatch_call function enables functional programming utilities (map, reduce, etc.)
- # to dynamically call user-defined functions by name. This is only included when needed.
+ # to dynamically call user-defined functions by name. This is only included when used.
if ("map" in USED_STDLIB_FUNCTIONS || "reduce" in USED_STDLIB_FUNCTIONS || "filter" in USED_STDLIB_FUNCTIONS || "find" in USED_STDLIB_FUNCTIONS || "findIndex" in USED_STDLIB_FUNCTIONS || "flatMap" in USED_STDLIB_FUNCTIONS || "pipe" in USED_STDLIB_FUNCTIONS || "pipe_multi" in USED_STDLIB_FUNCTIONS) {
print "# Dispatch function for functional programming"
@@ -521,7 +532,7 @@ END {
# =============================================================================
print ""
print "# Rawk compilation summary:"
- print "# - Rawk Version: 2.0.0"
+ print "# - Rawk Version: " RAWK_VERSION
print "# - Functions defined: " function_count
print "# - Source lines: " line_count
print "# - Standard library functions included: " length(USED_STDLIB_FUNCTIONS)