Using ChatGPT to convert to new syntax

This document provides a guide on using ChatGPT to convert existing HashScript code into the new HashJS-syntax. It includes prompts and instructions to make use of ChatGPT capabilities in the conversion task.
Updated: 02.05.2024 14:34
IMPORTANT!

Always manually check the result to ensure that the conversion was done correctly and verify all syntax changes.

Prompt to use from Chat GPT cha­t

Select all
I will now first give you your task, then I will give you the code you need to update. Just reply OK when you understand.

Task: Convert code from specific bracket syntax to JavaScript (HashJS) syntax. It is a server-side language that uses # followed by JavaScript code. It ends with # as well, so if you write #{ }# it becomes a code block without writing to the output. If you write #expression# without curly brackets, it directly outputs the expression on the page. If you write a statement (e.g., if), there will be no output.

Replace all instances of #[expression]# with #if(expression) {#. This goes to all the #[variablename]# statements as well, those will become #if(variablename) {# statements.
Replace all instances of #[/expression]# and #[/variablename]# ending statements with #}# to end the code blocks.
Replace all instances of #[data-loop=expression]# with #for(let item of expression) {#. Also convert data-loop attributes to this new syntax. You need to place the loop right after the tag  and wrap around all the child elements of the tag where the attribute was placed. Update references to unknown variables inside loops to use the specified loop variable instead of implicitly fetching from 'this'. So you have to check every variable within the loops and update the unknown ones with "item.variablename".
Replace all instances of #[/data-loop=expression]# with #}#.
Replace all instances of #setvar(variablename, value)# to either declare with #let variablename = value# also just update variables if they have already been declared. You must keep track of this because the old syntax didn't declare variables. Change "add" increment calls to simple #{ variable++; }# statements, make sure to place them in a code block, so they don't output to the content.

Reply only and exclusively with the updated code.
  • Paste prompt
    • Then paste code

      Prompt to use from co­de fi­les

      Enable AI extensions and press ALT+A in a code file. Convert your files in to operations:
      Convert IF statements:
      Select all
      Task: Convert code from specific HashScript (bracket syntax) to JavaScript (HashJS) syntax. It is a server-side language that uses # followed by JavaScript code. It ends with # as well, so if you write #{ }# it becomes a code block without writing to the output. If you write #expression# without curly brackets, it directly outputs the expression on the page. If you write a statement (e.g., if), there will be no output.
      
      
      Important, do not change any #[data-loop]# expressions now. That is done in a later step.
      
      Do not modify any standard javascript code in <script> blocks.
      
      Replace all instances of #[expression]# (must be bracket, but not #[data-loop=expression]#) with #if(expression) {#. This goes to all the #[variablename]# statements as well, those will become #if(variablename) {# statements.
      
      Replace all instances of #[/expression]#  (must be bracket, but not #[/data-loop=expression]#) and #[/variablename]# ending statements with #}# to end the code blocks.
      
      Replace all instances of #setvar(variablename, value)# to either declare with #let variablename = value# also just update variables if they have already been declared. You must keep track of this because the old syntax didn't declare variables. Change "add" increment calls to simple #{ variable++; }# statements, make sure to place them in a code block, so they don't output to the content.
      
      Leave all other instances of #expression# without the bracket and setvar as they are.
      Convert LOOP statements:
      Select all
      Task: Convert code from specific bracket syntax to JavaScript (HashJS) syntax. It is a server-side language that uses # followed by JavaScript code. It ends with # as well, so if you write #{ }# it becomes a code block without writing to the output. If you write #expression# without curly brackets, it directly outputs the expression on the page. If you write a statement (e.g., if), there will be no output.
      
      Replace all instances of #[data-loop=expression]# with #for(let item of expression) {#. Update references to unknown variables inside loops to use the specified loop variable instead of implicitly fetching from 'this'. So you have to check every variable within the loops and update the unknown ones with "item.variablename".
      Replace all instances of #[/data-loop=expression]# with #}#.
      Replace all instances of "data-loop" attributes to this new syntax. You need to place the loop right after the tag  and wrap around all the child elements of the tag where the attribute was placed. Also update all variables here.
      Replace all instances of #setvar(variablename, value)# to either declare with #let variablename = value# also just update variables if they have already been declared. You must keep track of this because the old syntax didn't declare variables. Change "add" increment calls to simple #{ variable++; }# statements, make sure to place them in a code block, so they don't output to the content.
      
      Never change any other code in the file.
      Se screenshots below