diff options
| author | elioat <{ID}+{username}@users.noreply.github.com> | 2025-07-31 11:09:32 -0400 |
|---|---|---|
| committer | elioat <{ID}+{username}@users.noreply.github.com> | 2025-07-31 11:09:32 -0400 |
| commit | 40822b3e9c501d9057246bc28ba99b69a791e3b8 (patch) | |
| tree | 08cdac9800b0e3af7a8a264151168684479145ab /awk/rawk/rawk.awk | |
| parent | 0a45bdc13d1de92c04979c4a6be27db2fdcf8c85 (diff) | |
| download | tour-40822b3e9c501d9057246bc28ba99b69a791e3b8.tar.gz | |
*
Diffstat (limited to 'awk/rawk/rawk.awk')
| -rw-r--r-- | awk/rawk/rawk.awk | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/awk/rawk/rawk.awk b/awk/rawk/rawk.awk index f1d8dff..3fc734d 100644 --- a/awk/rawk/rawk.awk +++ b/awk/rawk/rawk.awk @@ -1,12 +1,17 @@ #!/usr/bin/env awk -f -# ----------------------------------------------------------------------------- -# rawk.awk - The `rawk` Language Compiler (Multi-Pass Version) +# rawk.awk + +# Author: @eli_oat +# License: Public Domain +# Version: +RAWK_VERSION = "0.0.1" + +# Lets help awk rawk. # # This script translates a `.rawk` source file into standard, portable awk code. -# It uses a multi-pass approach: -# Pass 1: Parse and collect all function definitions and source lines -# Pass 2: Generate the final AWK code (in END block) +# +# This script is implemented in awk, and should work with any POSIX awk. # # USAGE: # awk -f rawk.awk my_program.rawk | awk -f - @@ -15,7 +20,7 @@ # # Basic usage - compile and run # awk -f rawk.awk hello.rawk | awk -f - # -# # Compile to file for later use +# # Compile to rawk to an awk file for later use # awk -f rawk.awk hello.rawk > hello.awk # awk -f hello.awk # @@ -315,7 +320,7 @@ # # PORTABILITY: # - Output is compatible with standard awk (nawk, BSD awk) -# - Avoids gawk-specific features for maximum compatibility +# - Avoids gawk-specific features # - Uses only standard awk constructs and functions # # ----------------------------------------------------------------------------- @@ -386,7 +391,7 @@ BEGIN { # Handle multiple functions on the same line remaining_line = $0 while (remaining_line ~ /^[ \t]*\$[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*\([^)]*\)[ \t]*->[ \t]*[^\{]/) { - # Find the end of the current function (semicolon) + # Find the end of the current function by looking for a semicolon if (match(remaining_line, /^[ \t]*\$[a-zA-Z_][a-zA-Z0-9_]*[ \t]*=[ \t]*\([^)]*\)[ \t]*->[ \t]*[^;]*;/)) { current_func = substr(remaining_line, RSTART, RLENGTH) parse_single_line_function(current_func, line_count) @@ -432,7 +437,7 @@ BEGIN { } } - # Pattern 4: Start of multi-line function body (only if not already in function body) + # Pattern 4: Start of multi-line function body, but only if not already in a function body if (!in_function_body && in_function_def && $0 ~ /^[ \t]*\{/) { in_function_body = 1 brace_count = 1 @@ -440,7 +445,7 @@ BEGIN { next } - # Pattern 5: Regular code (but exclude function definition endings) + # Pattern 5: Regular code, but exclude function definition endings if ($0 ~ /^[ \t]*\}[ \t]*;[ \t]*$/) { SOURCE_LINE_TYPES[line_count] = "function_end" } else { @@ -1299,7 +1304,8 @@ END { generate_main_script() # Print compilation summary - print "# rawk compilation summary:" + print "# Rawk compilation summary:" + print "# - Rawk Version: " RAWK_VERSION print "# - Functions defined: " functions_defined print "# - Source lines: " source_lines print "# - Errors: " errors |