HASHSCRIPT v2

• Align syntax with JS
• Improve error messages

© 2022-23 Docly ™ | www.docly.net
Updated: 17.11.2023 11:03

The new ver­sion of HashJ­S

HS v2 is backwards compatible with v1.
Se documentation here:
https://tech.docly.net/Creating-forms/HASH-Templates

All examples will be updated soon with v2 syntax.

Over­vie­w

What How
Simplify the language syntax • Switch to Javascript syntax in language
• Still support for previous syntax
• Show syntax errors when coding
• Possible to declare your own functions (also so you can use and create your own libraries)
• Better syntax highlighting when writing API functions (.HS extension)
Improve error messages • Provide line number of exceptions in compilation and runtime errors
• Show 5 lines of code before and after with error highlighted
As an extra measure we will implement a site validation feature to make sure your sites do not have errors.
* Prepare future support for - this will not be included initially for v2.

Chan­ges and examp­les

For loop­s

Example - JS syntax:
Select all
<ul>
    #var index=1#
    #for(var item of List) {#
        <li>#index#. #item.Name#</li>
        #index++#
    #}#
</ul>
The old syntax is still supported with brackets: [data-loop=items].

If sta­temen­ts

Select all
#if(a>b) {#
    <b>A is greater than B</b>
#} else {#
    <b>B is equaler or greater than A</b>
#}#


New fea­ture­s

Co­de blocks (cur­ly brac­kets­)

Select all
#{
    // Comments in code
    var a=1;
    var b = 10;
    
    if(a>b)
    {
        var x = "123";
        // do stuff
        return "test 1";
    }
    else
        return "test 2";
}#

New ser­ver si­de .JS fi­les (A­PI fol­der on­ly)

For better syntax highlighting, no need for #{ }#
Select all
var a = 1;
var b = 10;
if(a > b) 
{
    // ...
    return JSON(a);
}
else
    return JSON(b);
Only available for JSON functions that are placed in the #/API folder.

JS syn­tax for ope­rator­s and va­riab­les

Select all
var a = 1;
var b = 10;
if (a + 5 > (5 - b) * 2)
{
    a = a + 1;
    a++;
    a += b;
}

Imp­roved er­ror mes­sage­s

New error messages will not provide line number and 5 lines of code:
Select all
Error: [message here]

Line 23: [line-2] 
Line 24: [line-1] 
Line 25: [line with error, code highlighted]
Line 26: [line+1] 
Line 27: [line+2]

Dec­lare func­tion­s

Example:
Select all
#{
    function MyFunction(a,b) {
        return a * b;
    }
}#

Use function #MyFunction(3, 2)#
Multiples param 1 with param 2. Output will be 6.
Note that we are NOT CASE SENSITIVE on function names. Declaring the same function twice will simply overwrite the previous function code with no errors.
Output:
Select all
Use function 6