ballanced

ballanced

part of shnell – a source to source compiler enhancement tool

© Jens Gustedt, 2019

A tool to process ballanced parenthesis.

The functions here read some parenthized code on stdin and by default dump it to stdout until the first open parenthesis is closed. Recognized parenthesis are Paren ~ (), Bracket ~ [], Brace ~ {} and Attr ~ [[]].

Instead of directly dumping to stdout, for each type of parenthesis there can be a callback that filters the the code that is received. Such a callback is defined by the variables callbackParen, callbackBracket, callbackBrace and callbackAttr, respectively.

The whole procedure uses (and reserves!) two variables, top for the current syntax element and line for the remainder of the current line.

For all of this to work, the parenthesis must be visible as individual words in the input. Therefore the input should have been pretreated by tokenize.

Coding and configuration

The following code is needed to enable the sh-module framework.

SRC="$_" . "${0%%/${0##*/}}/import.sh"

Imports

The following sh-modules are imported:

Details

Declared functions

deleteWord: Delete the current word and advance one word forward.

Newline characters are printed to stdout each time that the current line in line became empty.

popWord: Write out the current word and advance one word forward.

This is the main tool to move through the source stream.

Newline characters are printed to stdout each time that the current line in line became empty.

ignoreCallback: Callback to ignore all stdin

linesCallback: Callback to print empty lines

callBack: Process one single ballanced expression

ballancedParen: Process an expression that is surrounded by ().

ballancedBracket: Process an expression that is surrounded by [].

ballancedAttr: Process an expression that is surrounded by [[]].

ballancedBrace: Process an expression that is surrounded by {}.

ballancedBrace: Process an expression that is surrounded by {}.