Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
312 commits
Select commit Hold shift + click to select a range
83a30db
add minor-iskey test case
lmscunha Mar 26, 2025
337c89e
add minor-strkey testcase
lmscunha Mar 26, 2025
19f80df
remove duplicated test case
lmscunha Mar 26, 2025
0e6c92c
update the tests by remove unused test cases
lmscunha Mar 26, 2025
76c70f3
remove whitespace
lmscunha Mar 26, 2025
92d4d77
[WIP] ADD FINAL STRUCT FORMAT
lmscunha Mar 26, 2025
edb9b0d
[WIP] ADD FINAL STRUCT FORMAT
lmscunha Mar 26, 2025
3954ba2
make walk-log pass
lmscunha Mar 26, 2025
cbcde40
make walk basic pass
lmscunha Mar 26, 2025
81bbcc2
make merge-basic test case pass
lmscunha Mar 26, 2025
e5f0b55
make merge-cases test pass
lmscunha Mar 26, 2025
0481096
make merge-array test pass
lmscunha Mar 26, 2025
5252413
make merge-special test pass
lmscunha Mar 26, 2025
96ac838
make getpath tests pass
lmscunha Mar 26, 2025
f25bfe4
make inject test pass
lmscunha Mar 26, 2025
ea8c5c6
make transform tests pass
lmscunha Mar 26, 2025
b0343d5
make validate-basic test pass
lmscunha Mar 27, 2025
f1a74c5
make validate tests pass
lmscunha Mar 27, 2025
eb6c431
create client test suit
lmscunha Mar 27, 2025
b9fa449
refactor
lmscunha Mar 27, 2025
4af1420
refactor
lmscunha Mar 27, 2025
813090f
refactor runner to properly match TypeScript version
lmscunha Mar 27, 2025
59ff977
refactor struct_test.lua
lmscunha Mar 27, 2025
308c3c6
refactor
lmscunha Mar 27, 2025
d1ea0a2
refactor
lmscunha Mar 27, 2025
b0fef01
refactor
lmscunha Mar 27, 2025
5047403
create docs for lua code
lmscunha Mar 27, 2025
43085fd
go-updates
rjrodger Mar 27, 2025
36e33c2
apply-makeRunner-py-go-js
rjrodger Mar 28, 2025
f90ebaa
Merge pull request #13 from voxgig/rr-refactor-sdk-01
rjrodger Mar 28, 2025
1bb6ec9
Merge pull request #12 from lmscunha/lc-fix-transform-tests
rjrodger Mar 28, 2025
c84b40a
build-0
rjrodger Mar 28, 2025
f457845
build-1
rjrodger Mar 28, 2025
2e72f05
build-2
rjrodger Mar 28, 2025
9fae802
build-3
rjrodger Mar 28, 2025
bb51e5c
build-4
rjrodger Mar 28, 2025
be91035
build-5
rjrodger Mar 28, 2025
c397901
build-6
rjrodger Mar 28, 2025
b37a527
build-7
rjrodger Mar 28, 2025
80250e7
build-8
rjrodger Mar 28, 2025
d7ff38c
sdk-fixes
rjrodger Mar 28, 2025
6b73180
fix and expand the linux cmd to install lua and luarocks
lmscunha Mar 28, 2025
521c626
sdk-fixes
rjrodger Mar 28, 2025
05f4423
improve setup cmd for linux and macos
lmscunha Mar 28, 2025
6deb43f
update curl cmd
lmscunha Mar 28, 2025
bc9bcf4
Merge pull request #15 from lmscunha/lc-fix-lua-version-for-linux
rjrodger Mar 31, 2025
27aa9e9
sdk-py
rjrodger Apr 2, 2025
3f87354
validate-msg
rjrodger Apr 4, 2025
2dac37a
fix-sort-fields
rjrodger Apr 5, 2025
d8f6804
validate-msg
rjrodger Apr 5, 2025
03d1199
partial-contextify
rjrodger Apr 5, 2025
c4c2f6e
ts-EXACT
rjrodger Apr 6, 2025
a1c1f60
ts-exact
rjrodger Apr 7, 2025
b886a32
sep-client
rjrodger Apr 7, 2025
d00f18c
sdk-align
rjrodger Apr 7, 2025
052e7a6
fix-js
rjrodger Apr 8, 2025
9ce67cf
py-works-again
rjrodger Apr 9, 2025
3d8e290
Added ruby tests
Jose-Perigolo Apr 11, 2025
2233cab
Added ruby runner
Jose-Perigolo Apr 11, 2025
0fd4342
Added struct ruby
Jose-Perigolo Apr 11, 2025
0defd90
Update PHP Struct
Jose-Perigolo Apr 11, 2025
35d85c7
Update PHP Struct
Jose-Perigolo Apr 11, 2025
f80ff74
Create runner php
Jose-Perigolo Apr 11, 2025
9d7bb8a
create utility sdk php
Jose-Perigolo Apr 11, 2025
46a11b7
py-clone-obj-instance
rjrodger Apr 11, 2025
2956fce
Merge pull request #16 from Jose-Perigolo/dev
rjrodger Apr 15, 2025
6f0d433
sdk-fixes
rjrodger Apr 16, 2025
0dc745a
go-fix
rjrodger Apr 18, 2025
ba659a3
Merge pull request #17 from voxgig/rr-sdk-fix-01
rjrodger Apr 18, 2025
187d459
fix-haskey-joinurl-lua-php-rb
rjrodger Apr 18, 2025
09e82a6
fix-haskey-joinurl-lua-php-rb-1
rjrodger Apr 18, 2025
32dfb50
fix-haskey-joinurl-lua-php-rb-2
rjrodger Apr 18, 2025
23c5f1b
fix-haskey-joinurl-lua-php-rb-3
rjrodger Apr 18, 2025
fd0af95
fix-haskey-joinurl-lua-php-rb-3
rjrodger Apr 18, 2025
84a13d1
add new constants
lmscunha Apr 24, 2025
03fa0e5
Enhance matchval and fixJSON functions to handle special markers (NUL…
lmscunha Apr 24, 2025
6f7e495
Refactor test runner implementation to create a makeRunner function f…
lmscunha Apr 24, 2025
75612de
Add Utility class and enhance Client interface for improved struct ma…
lmscunha Apr 24, 2025
668956f
Enhance match function in test runner to include cloning of base stru…
lmscunha Apr 24, 2025
8ded294
Improve error handling in test runner by adding special cases for val…
lmscunha Apr 24, 2025
88e0517
Refactor struct tests to improve validation and error handling. Added…
lmscunha Apr 24, 2025
591aafb
Add $EXACT validator to struct.lua for precise value matching
lmscunha Apr 24, 2025
c4e3ead
Refactor struct test suite and update runner module integration
lmscunha Apr 24, 2025
38a6271
Update module paths in test files for consistency and accuracy
lmscunha Apr 24, 2025
5b83f63
Update module paths and refactor struct tests for improved loading an…
lmscunha Apr 24, 2025
f349ee1
Refactor client test runner variable for clarity and consistency
lmscunha Apr 25, 2025
1d069c7
Add validation enhancements to struct.lua for improved error reportin…
lmscunha Apr 25, 2025
bb15639
Update error message in validation function for clarity
lmscunha Apr 26, 2025
57eac26
Refactor validate_ONE function for improved error handling and clarity
lmscunha Apr 26, 2025
7cb4bc1
lint
lmscunha Apr 29, 2025
30ecbe2
update pathify
lmscunha Apr 29, 2025
8366a14
update validate
lmscunha Apr 29, 2025
e0be40f
update runner
lmscunha Apr 29, 2025
5e2c883
general struct refactor
lmscunha Apr 29, 2025
ee8c662
fix validate_ONE
lmscunha Apr 30, 2025
0451f88
fix validate_EXACT
lmscunha Apr 30, 2025
1b6de55
fix validate INVALID
lmscunha Apr 30, 2025
5855773
fix validate-custom
lmscunha Apr 30, 2025
e0f6be1
remove debug import
lmscunha Apr 30, 2025
5812f21
update makefile to run all tests
lmscunha Apr 30, 2025
a3509e1
remove unnecessary comments
lmscunha Apr 30, 2025
c18d102
create StructUtils and update SDK
lmscunha Apr 30, 2025
1bbd9eb
fix import remove unused code
lmscunha Apr 30, 2025
b1c4019
fix client test
lmscunha May 1, 2025
639d25e
general refactor
lmscunha May 1, 2025
e5fb5fb
refactor struct
lmscunha May 1, 2025
840d984
refactor struct test
lmscunha May 1, 2025
ee9fe24
refactor client test
lmscunha May 1, 2025
2fb0d4f
refactor runner
lmscunha May 1, 2025
cba5f57
refactor runner
lmscunha May 1, 2025
110a9f7
Update test setup to disable warnings
Jose-Perigolo May 6, 2025
ae90ff8
Update struct, major
Jose-Perigolo May 6, 2025
8cf7bcd
Added new tests for major functions
Jose-Perigolo May 6, 2025
6db19b0
Merge pull request #20 from Jose-Perigolo/dev
rjrodger May 7, 2025
d7a0d47
Merge pull request #19 from lmscunha/lc-update-lua-struct
rjrodger May 7, 2025
33b8ade
Added missing functions and fixes
Jose-Perigolo May 9, 2025
3e08c4a
Test client added
Jose-Perigolo May 9, 2025
d5f44e6
Added tests to missing functions
Jose-Perigolo May 9, 2025
9f06941
Merge pull request #21 from Jose-Perigolo/dev
rjrodger May 9, 2025
490c886
ref
rjrodger May 14, 2025
52ba6b1
ref-array-broken
rjrodger May 15, 2025
ba7022e
fix-ref-loop
rjrodger May 16, 2025
0106110
update struct based on the sdk development
lmscunha May 18, 2025
409ed9b
ref-works
rjrodger May 19, 2025
b937749
Merge pull request #23 from voxgig/rr-ref-01
rjrodger May 19, 2025
119c0c2
deps
rjrodger May 19, 2025
7308be6
size-slice
rjrodger May 19, 2025
45c4244
inject-methods
rjrodger May 20, 2025
9731834
fix-pack
rjrodger May 21, 2025
f337aca
Merge pull request #25 from voxgig/rr-util-01
rjrodger May 21, 2025
71ca3e4
Merge pull request #22 from lmscunha/lc-update-lua-struct
rjrodger May 21, 2025
bd7307c
almost
rjrodger May 21, 2025
24f1488
Merge pull request #26 from voxgig/rr-py-ref-01
rjrodger May 21, 2025
60918ee
Fixed getpath in /py
Garzo14 May 21, 2025
cc5dc4b
Merge pull request #27 from ConquerMediaIreland/gp-python-getpath-fix-01
rjrodger May 23, 2025
13377ef
Python implementation uses setval as in the TS implementation
Garzo14 May 23, 2025
a4f7c8c
Python implementation uses .child method now
Garzo14 May 23, 2025
28f2a07
working
rjrodger May 23, 2025
51a36b8
getpath-args
rjrodger May 24, 2025
fdfc70c
dparent-replaces-current
rjrodger May 24, 2025
d4dcfba
injdef-arg
rjrodger May 25, 2025
5fe05be
validate-args
rjrodger May 25, 2025
0748974
metarefs
rjrodger May 26, 2025
4828440
metaref-syntax
rjrodger May 26, 2025
8fce08a
Merge pull request #28 from ConquerMediaIreland/gp-use-setval-01
rjrodger May 26, 2025
66583d6
slice-string-numbers
rjrodger May 26, 2025
7b6ba88
comments
rjrodger May 26, 2025
b082aa2
delprop
rjrodger May 26, 2025
ac9780d
cleanup
rjrodger May 26, 2025
64864e2
Merge pull request #29 from voxgig/rr-rel-path-01
rjrodger May 26, 2025
42ffbff
validate-undef-fix
rjrodger May 27, 2025
1097ce0
Merge pull request #30 from voxgig/rr-rel-path-01
rjrodger May 27, 2025
ff5f345
jsonify
rjrodger May 29, 2025
1993e6c
go-jsonify
rjrodger Jun 4, 2025
21fc70b
Merge pull request #31 from voxgig/rr-inject-01
rjrodger Jun 4, 2025
4899c4c
select-works
rjrodger Jun 4, 2025
99709a8
Merge pull request #32 from voxgig/rr-select-01
rjrodger Jun 4, 2025
2fa280f
v0.0.1
rjrodger Jun 5, 2025
e50db97
Merge branch 'dev' of github.com:voxgig/struct into dev
rjrodger Jun 5, 2025
d60a15b
v0.0.2
rjrodger Jun 5, 2025
589d3f1
fix-stringify
rjrodger Jun 17, 2025
13332cb
jsonify-offset
rjrodger Jun 17, 2025
f3eee0e
fix-select-deep
rjrodger Jun 18, 2025
7c2075d
Added last changes
Jose-Perigolo Jun 30, 2025
a875aef
Added last tests
Jose-Perigolo Jun 30, 2025
100e513
getpath-dot
rjrodger Jun 30, 2025
d31ec54
v0.0.3
rjrodger Jun 30, 2025
1c4fd98
Added last changes
Jose-Perigolo Jun 30, 2025
49ee5c4
validate changes
Jose-Perigolo Jul 2, 2025
7af35c3
Merge pull request #33 from Jose-Perigolo/dev
rjrodger Jul 3, 2025
9bdecde
sdk-needed
rjrodger Jul 8, 2025
0a02a15
sdk-fix
rjrodger Jul 8, 2025
e2d8c34
Merge branch 'dev' of github.com:voxgig/struct into dev
rjrodger Jul 8, 2025
7af059a
v0.0.4
rjrodger Jul 8, 2025
fb960bf
merge-fix
rjrodger Jul 16, 2025
2e8a46c
v0.0.5
rjrodger Jul 17, 2025
1735ce8
v0.0.6
rjrodger Jul 30, 2025
f53fd46
Update runner
Jose-Perigolo Aug 12, 2025
96d3edf
struct general update
Jose-Perigolo Aug 12, 2025
1df8725
add init file
Jose-Perigolo Aug 12, 2025
7d4c052
updated tests
Jose-Perigolo Aug 12, 2025
13b87f5
Merge branch 'voxgig:dev' into dev
Jose-Perigolo Aug 12, 2025
0dc4a96
Merge pull request #37 from Jose-Perigolo/dev
rjrodger Aug 12, 2025
f90957a
rename-and-walk
rjrodger Aug 12, 2025
2f3b65a
better-merge
rjrodger Aug 13, 2025
9199b43
Merge branch 'dev' of github.com:voxgig/struct into dev
rjrodger Aug 13, 2025
cd6dbec
v0.0.7
rjrodger Aug 13, 2025
028a0cc
v0.0.8
rjrodger Aug 13, 2025
2631497
fix-validate-meta
rjrodger Aug 13, 2025
6f27b81
v0.0.9
rjrodger Aug 13, 2025
d7fa1bd
use-setprop
rjrodger Nov 10, 2025
d4933d3
select-alts-test
rjrodger Dec 12, 2025
e4a2fab
transform functions implementation - tests
Jose-Perigolo Jan 30, 2026
36de36e
transform functions implementation
Jose-Perigolo Jan 30, 2026
8a73c1c
format
rjrodger Feb 6, 2026
bd9fb54
cov-0
rjrodger Feb 10, 2026
0a2298a
Merge pull request #38 from Jose-Perigolo/dev
rjrodger Feb 11, 2026
9ff3c70
type-bits
rjrodger Feb 12, 2026
46f8592
Merge branch 'dev' of github.com:voxgig/struct into dev
rjrodger Feb 12, 2026
99b4aad
norming
rjrodger Feb 13, 2026
1e6e1fa
Convert Injection struct list fields (Keys, Path, Nodes) to use ListRef
claude Feb 14, 2026
7314a5b
Remove ListRef wrapper methods, access .List directly
claude Feb 14, 2026
3fe310c
Use Walk to wrap bare lists as ListRefs in Transform/Validate input, …
claude Feb 14, 2026
c277dee
Replace _setParentProp and _updateAncestors with direct SetProp
claude Feb 14, 2026
dd27570
Integrate list wrapping into CloneFlags, remove redundant Walk passes
claude Feb 14, 2026
e5caa0a
Add unwrap flag to CloneFlags, remove _unwrapLists Walk
claude Feb 14, 2026
4dc1841
Update Typify to use bitset approach matching TS dev branch
claude Feb 14, 2026
cca5860
Rename T_nil/S_nil to T_noval/S_noval to avoid confusion with Go nil
claude Feb 14, 2026
458d2e8
Skip test entries expecting T_noval for absent in/out values
claude Feb 14, 2026
818b1d7
Add missing functions from TS: GetDef, Size, Slice, Pad, GetElem,
claude Feb 14, 2026
ffefe68
Rename jo to jm and ja to jt in TypeScript code
claude Feb 14, 2026
1aae9c5
Rename UNDEF to NONE and T_nil to T_noval in TypeScript code
claude Feb 14, 2026
59cec5e
Merge pull request #39 from voxgig/claude/rename-functions-0ohDp
rjrodger Feb 14, 2026
2c510de
Update Go test code to match TS test code and fix library issues
claude Feb 14, 2026
64ac54c
Implement dual-tree tracking and full TS parity for transforms and va…
claude Feb 14, 2026
a3006b0
Merge pull request #40 from voxgig/claude/go-lists-explanation-Q4Uik
rjrodger Feb 15, 2026
4e31d63
lua: add type flag constants, typename, update typify to return bit c…
claude Feb 15, 2026
259df84
lua: add new utility functions and update stringify
claude Feb 15, 2026
be5811c
lua: update walk to support before/after callbacks and maxdepth
claude Feb 15, 2026
b2a0ee5
lua: update setprop to remove deletion handling
claude Feb 15, 2026
0054426
lua: rewrite merge to use before/after walk callbacks
claude Feb 15, 2026
2026c51
lua: rewrite getpath with new signature getpath(store, path, injdef)
claude Feb 15, 2026
49495b8
lua: rewrite Injection as class with descend/child/setval methods
claude Feb 15, 2026
d336991
lua: rewrite transform functions to match TS API
claude Feb 15, 2026
d1d49bc
lua: rewrite validate functions to match TS API
claude Feb 15, 2026
32d2709
lua: add select function and update module exports
claude Feb 15, 2026
5a09442
lua: update test files to match new TS API signatures
claude Feb 15, 2026
4a56117
lua: fix slice, walk, pad, items, setprop/delprop, transform, path split
claude Feb 15, 2026
5a6795c
lua: fix remaining test failures for TS parity (69/0 pass/fail)
claude Feb 15, 2026
7686777
lua: typify(nil) returns T_null, runner skips absent-key entries
claude Feb 15, 2026
eb7416f
Merge pull request #41 from voxgig/claude/lua-list-reference-stabilit…
rjrodger Feb 15, 2026
74bc912
minors
rjrodger Feb 16, 2026
a5e35dd
ts: change injection mode values from strings to bitfield
claude Feb 16, 2026
516d08b
Merge pull request #42 from voxgig/claude/injection-mode-bitfield-5b2AW
rjrodger Feb 16, 2026
c6a70b1
lua: fix multiple discrepancies with TS implementation
claude Feb 16, 2026
5da979d
go: update to match ts implementation
claude Feb 16, 2026
da09074
Merge pull request #43 from voxgig/claude/verify-lua-ts-implementatio…
rjrodger Feb 16, 2026
77d826a
Merge pull request #44 from voxgig/claude/update-go-version-u7OEX
rjrodger Feb 16, 2026
502422b
v0.0.10
rjrodger Feb 17, 2026
53f9901
local test fix php
Jose-Perigolo Feb 23, 2026
3ca64f7
PHP struct updates
Jose-Perigolo Feb 23, 2026
2a703af
Struct tests PHP
Jose-Perigolo Feb 23, 2026
f415ace
Python runner update
Jose-Perigolo Feb 23, 2026
05b46b0
Python struct updates
Jose-Perigolo Feb 23, 2026
582a55d
Python test struct updates
Jose-Perigolo Feb 23, 2026
1519702
Merge pull request #45 from Jose-Perigolo/dev
rjrodger Feb 24, 2026
ba1f999
makeContext
rjrodger Mar 1, 2026
7b101ab
mergbe
rjrodger Mar 1, 2026
82baed7
Merge branch 'dev' into dev-rc
rjrodger Mar 1, 2026
eace7bd
Merge dev into dev-rc; take theirs
rjrodger Mar 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 59 additions & 59 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,64 +84,64 @@ jobs:
working-directory: ./go
run: go test -v ./...

# test-ruby:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
# steps:
# - uses: actions/checkout@v3
# - name: Setup Ruby
# uses: ruby/setup-ruby@v1
# with:
# ruby-version: '3.2'
# bundler-cache: true
# - name: Install dependencies
# working-directory: ./rb
# run: |
# gem install bundler
# bundle install
# - name: Run tests
# working-directory: ./rb
# run: ruby test_voxgig_struct.rb
test-ruby:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Install dependencies
working-directory: ./rb
run: |
gem install bundler
bundle install
- name: Run tests
working-directory: ./rb
run: ruby test_voxgig_struct.rb

# test-php:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
# steps:
# - uses: actions/checkout@v3
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: '8.1'
# - name: Install dependencies
# working-directory: ./php
# run: composer install
# - name: Run tests
# working-directory: ./php
# run: vendor/bin/phpunit
test-php:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: Install dependencies
working-directory: ./php
run: composer install
- name: Run tests
working-directory: ./php
run: vendor/bin/phpunit

# test-lua:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# os: [ubuntu-latest, macos-latest]
# steps:
# - uses: actions/checkout@v3
# - name: Setup Lua
# uses: leafo/gh-actions-lua@v10
# with:
# luaVersion: "5.4"
# - name: Setup LuaRocks
# uses: leafo/gh-actions-luarocks@v4
# - name: Setup environment
# working-directory: ./lua
# shell: bash
# run: |
# chmod +x setup.sh
# ./setup.sh
# - name: Run tests
# working-directory: ./lua
# run: make test
test-lua:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: Setup Lua
uses: leafo/gh-actions-lua@v10
with:
luaVersion: "5.4"
- name: Setup LuaRocks
uses: leafo/gh-actions-luarocks@v4
- name: Setup environment
working-directory: ./lua
shell: bash
run: |
chmod +x setup.sh
./setup.sh
- name: Run tests
working-directory: ./lua
run: make test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
Expand Down Expand Up @@ -149,3 +148,5 @@ __pycache__
*.swp

package-lock.json

*.local.*
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# TODO

* getpath: document trailing . as ascending path

214 changes: 214 additions & 0 deletions build/extract-function-comments.js.NOT_FINISHED
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

// Language configuration
const languages = {
js: { file: 'js/src/struct.js', comment: '//' },
py: { file: 'py/voxgig_struct/voxgig_struct.py', comment: '#' },
go: { file: 'go/voxgigstruct.go', comment: '//' },
java: { file: 'java/src/Struct.java', comment: '//' },
php: { file: 'php/src/Struct.php', comment: '//' },
rb: { file: 'rb/voxgig_struct.rb', comment: '#' },
lua: { file: 'lua/src/struct.lua', comment: '--' },
cpp: { file: 'cpp/src/voxgig_struct.hpp', comment: '//' },
ts: { file: 'ts/src/struct.ts', comment: '//' }
};

// Get command line argument
const arg = process.argv[2];

if (!arg) {
console.log('Usage: node extract-function-comments.js <show|language>');
console.log('Available languages:', Object.keys(languages).join(', '));
process.exit(1);
}

// Read the TypeScript struct file to extract function comments
const structPath = path.join(__dirname, '../ts/src/struct.ts');
const sourceText = fs.readFileSync(structPath, 'utf8');

function extractFunctionComments(sourceText) {
const lines = sourceText.split('\n');
const functionComments = new Map();

let currentComment = '';
let inComment = false;

for (let i = 0; i < lines.length; i++) {
const line = lines[i].trim();

// Check if this line starts a single-line comment
if (line.startsWith('//')) {
if (!inComment) {
currentComment = line;
inComment = true;
} else {
currentComment += '\n' + line;
}
continue;
}

// Check if this line contains a function declaration
const functionMatch = line.match(/^(?:export\s+)?(?:async\s+)?function\s+(\w+)\s*\(/);

if (functionMatch) {
const functionName = functionMatch[1];

if (inComment && currentComment) {
// Filter out all lines starting from "NOTE:"
const lines = currentComment.split('\n');
const filteredLines = [];

for (const line of lines) {
if (line.trim().startsWith('// NOTE:')) {
break;
}
filteredLines.push(line);
}

const filteredComment = filteredLines.join('\n').trim();
if (filteredComment) {
functionComments.set(functionName, filteredComment);
}
}

currentComment = '';
inComment = false;
continue;
}

// If this line is not empty and not a comment, reset comment tracking
if (line !== '') {
currentComment = '';
inComment = false;
}
}

return functionComments;
}

function showComments(functionComments) {
console.log('Function Comments Map:');
console.log('=====================');

if (functionComments.size === 0) {
console.log('No functions with preceding comments found.');
} else {
for (const [functionName, comment] of functionComments) {
console.log(`\nFunction: ${functionName}`);
console.log('Comment:');
console.log(comment);
console.log('-'.repeat(50));
}
}

console.log(`\nTotal functions with comments found: ${functionComments.size}`);
}

function insertComments(fileContent, languageConfig, functionComments) {
console.log(`insertComments called for ${languageConfig.comment} syntax with ${functionComments.size} comments`);

const commentPrefix = languageConfig.comment;

// Convert TypeScript comments to target language syntax
const convertComment = (tsComment) => {
return tsComment
.split('\n')
.map(line => line.replace(/^\/\//, commentPrefix))
.join('\n');
};

// Escape comment prefix for regex (handle special chars like // and --)
const escapedPrefix = commentPrefix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

// Regular expression to match:
// 1. Optional whitespace/empty lines before comments
// 2. Comment block (excluding NOTE parts)
// 3. NOTE section (optional, captured separately to preserve)
// 4. Complete function declaration with function name and signature
const functionRegex = new RegExp(
`((?:\\s*\\n)*)` + // Group 1: Leading whitespace/empty lines
`((?:^\\s*${escapedPrefix}(?!.*NOTE:).*\\n)*)` + // Group 2: Non-NOTE comment lines
`((?:^\\s*${escapedPrefix}.*NOTE:.*\\n(?:^\\s*${escapedPrefix}.*\\n)*)?)` + // Group 3: NOTE section
`(\\s*)` + // Group 4: Whitespace before function
`(^\\s*(?:function\\s+|def\\s+|func\\s+|public\\s+(?:static\\s+)?(?:function\\s+)?)` + // Group 5: Function keywords
`(\\w+)` + // Group 6: Function name
`[^{]*\\{)`, // Rest of function signature up to opening brace
'gm'
);

let result = '';
let lastIndex = 0;
let match;

while ((match = functionRegex.exec(fileContent)) !== null) {
const [fullMatch, leadingWhitespace, oldComment, noteSection, preFunction, functionDeclaration, functionName] = match;
const matchStart = match.index;

console.log(`Found function: ${functionName}`);

// Add content before this match
result += fileContent.substring(lastIndex, matchStart);

if (functionComments.has(functionName)) {
console.log(`Updating comments for function: ${functionName}`);

// Convert the TypeScript comment to target language syntax
const newComment = convertComment(functionComments.get(functionName));

// Build the replacement:
// leading whitespace + new comment + NOTE section + pre-function whitespace + function declaration
result += leadingWhitespace +
newComment + '\n' +
(noteSection || '') +
preFunction +
functionDeclaration;
} else {
// No replacement needed, keep original
result += fullMatch;
}

lastIndex = match.index + fullMatch.length;
}

// Add any remaining content after the last match
result += fileContent.substring(lastIndex);

return result;
}

function updateLanguageFile(languageConfig, functionComments) {
const filePath = path.join(__dirname, '../', languageConfig.file);

if (!fs.existsSync(filePath)) {
console.error(`File not found: ${filePath}`);
return;
}

console.log(`Loading file: ${filePath}`);
const originalContent = fs.readFileSync(filePath, 'utf8');

console.log(`Processing comments for ${languageConfig.comment} syntax...`);
const updatedContent = insertComments(originalContent, languageConfig, functionComments);

console.log(`Writing updated content back to: ${filePath}`);
fs.writeFileSync(filePath, updatedContent);

console.log(`Successfully updated ${filePath}`);
}

// Main execution
const functionComments = extractFunctionComments(sourceText);

if (arg === 'show') {
showComments(functionComments);
} else if (languages[arg]) {
console.log(`Updating ${arg} implementation with TypeScript comments...`);
updateLanguageFile(languages[arg], functionComments);
} else {
console.error(`Unknown argument: ${arg}`);
console.log('Available options: show, ' + Object.keys(languages).join(', '));
process.exit(1);
}
Loading
Loading