When contributing to this repository, it's worth discussing first the change you wish to make via issue, email, Discord (stirante#0001), or any other method with the owners of this repository before making a change.
Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests:
- Fork the repo and create your branch from
master
. - If you've added code that should be tested, add tests.
- If you've added code that should be documented, add documentation.
- Try your best to follow the effective go guidelines as much as possible.
- Be sure to test your modifications.
- Format your code with
go fmt
. - Write a good commit message.
- Issue that pull request!
In short, when you submit code changes, your submissions are understood to be under the same MIT License that covers the project. Feel free to contact the maintainers if that's a concern.
Report bugs using Github's issues
We use GitHub issues to track public bugs. Report a bug by opening a new issue; it's that easy!
- Create a new file in the
jsonte/functions
directory. The file should be named<group>_functions.go
. - Write a function that registers all functions within that group. This function should be named
Register<group>Functions
. - Use the
RegisterGroup
function to register the group. You will need to input the following structure:Name
- The group's nameTitle
- The group's titleSummary
- A brief description of the group
- Register all functions to the newly created group (refer to the Adding a New Function section for more details).
- Include a call to the newly created function in the
Init
function, located injsonte/functions/function_definition.go
. - Write tests for all the functions in the new group. These should be placed in a new file named
test/<group>_functions_test.go
.
- Create a new function within the
jsonte/functions
directory. The appropriate file for this function will be determined by the group your function belongs to, e.g.,array_functions.go
. - Ensure the parameters and the return value of your function conform to the following types:
utils.JsonArray
- arrayutils.JsonObject
- objectutils.JsonString
- stringutils.JsonNumber
- numberutils.JsonBool
- booleanutils.JsonLambda
- lambda[]utils.JsonType
- varargs of any type
- The function may also return an additional value of the
error
type. If this value is notnil
, the error will be returned to the user. - Register the function by calling the
RegisterFunction
function withinRegister<group>Functions
. You will need to input a structure with the following fields:Group
- The group's nameName
- The function's nameBody
- The function itselfIsInstance
- A flag indicating whether this function can be invoked on an instance of an object (currently only supported forarray
andstring
types)IsUnsafe
- A flag indicating whether this function should be marked as unsafe and consequently disabled in safe mode (applicable to file manipulation, network access, etc.)Docs
- The function's documentation
- Write a test for your new function. This should be placed in the
test
directory, in the file associated with your function's group, e.g.,array_functions_test.go
.
- Execute the
scripts/setup_env.ps1
script to configure the environment. This only needs to be done once. The script will establish the environment inC:\antlr
and add it to the path. - Make necessary changes to the
grammar/JsonTemplate.g4
file (refer to the official Antlr4 documentation). - Run the
scripts/compile_antlr.ps1
script to compile the parser. - Implement the new grammar by writing corresponding code in the
jsonte/expression_visitor.go
file. - When creating a new rule, provide an interface implementation in the
Visit<rule>
function and include a call to this function in theVisit
function, located in thejsonte/expression_visitor.go
file. - Write tests for your grammar changes. These should be included in the
test/eval_test.go
file. - Execute the
go test
command to verify that all modifications are working as expected.