# lib_sugar function library

Dependencies: lib_fn, lib_tools

## Description

This contains SFO's syntactic sugar, used by 'include', 'run', and anonymous functions.

## Public functions

sugar_apply(patch_only:i)=() patch

Apply SFO's syntactic sugar to the current file. If 'patch_only' is set to 1, don't bother with the action parts.

sugar_semicolons()=() patch

Replace double semicolons with line breaks.

sugar_test()=() action

Copy over the inline file 'sugartest.tp2' (at the end of this library) and apply syntactic sugar to it, then INCLUDE it to check it's well-formed.

## Internal functions

These should not be called from outside the library itself.

sugar_action()=() patch

Handle SFO abbreviations for action functions

sugar_comparison()=() patch

Swap in simpler versions of string comparison

sugar_decomment()=() patch

Remove //-style comments.

sugar_parse_action_arguments(args:s, input:s, input2:s, struct:s, type:s)=(ints:s, strs:s) patch

Preliminary processing: extract the contents of the argument bracket(s)

sugar_parse_arguments(args1:s, args2:s, input:s, input2:s, struct:s)=(ints:s, strs:s) patch

Work out the STR_VAR/INT_VAR part of the function, using info from sugar_parse_[patch|action]_arguments

sugar_parse_function(function:s)=(input:s, input2:s, function:s, struct:s, output:s, output2:s, type:s, output_array:s) patch

Parse the function for virtual-object data

sugar_parse_fundef_args(args:s)=(ints:s, strs:s) patch

Parse the function definition for INT_VARs and STR_VARs

sugar_parse_fundef_rets(args:s, RET, rets, retarrays)=() patch

sugar_parse_patch_arguments(args:s, input:s, input2:s, struct:s, type:s)=(ints:s, strs:s) patch

Exactly like sugar_parse_action_arguments, but with curly brackets instead of square brackets

sugar_parse_returns(output_array:i, returns:s, output:s, output2:s, struct:s, RET, ret)=() patch

Work out the 'RET' and 'RET_ARRAY' section of the function

sugar_patch()=() patch

Handle SFO abbreviations for patch functions

sugar_remove_inline(quote_index:i)=(quote_index:s, quote_array:a) patch

Extract inlined files (so we don't sugar them - main concern: LUA) and store them for later restoration in the format [unique integer]=string. quote_array tracks how many quotes so far, so that sugar_remove_inline and sugar_remove_quintuple_quotes can share.

sugar_remove_quintuple_quotes(quote_index:i)=(quote_index:s, quote_array:a) patch

Extract the contents of ~~~~~ - ~~~~~ -quoted data (so we don't sugar it - main concern: mangling the file when we sugar an anonymous function input to an action function that's itself sugared, e.g. the cre.edit interface) and store them for later restoration in the format [unique integer]=string. quote_array tracks how many quotes so far, so that sugar_remove_inline and sugar_remove_quintuple_quotes can share.

Incidentally, we don't do single-quoted or tilde-quoted data because in a few cases - e.g SPRINT var "~" - it will mangle the file.

sugar_replace_removed_data(quote_array:s)=() patch

Put back data sequestered by sugar_remove_[whatever]

test_sugar_helper()=() action

Doesn't actually exist: contained in the inline 'sugartext.tp2' (and is well-formed but doesn't work)