Procedural Text Edit

Runs on Windows, Linux Buy here Video Documentation

Procedural Text Edit is a very powerful text editing tool driven by its own programming language.
Both the full version and a demo are currently available on itch.io.

.ptep programs are interpreted and run on input texts to produce the desired result.
Procedural Text Edit is available both as GUI version (for very easy usage) and as CLI version (for easy automation and combination with existing programs or scripts). The program’s functions are applied in sequence on the input, feeding their result to the next function.

  +-------+     +----+      +---------+     +----+      +---------+                +--------+
  | INPUT |  +  | F1 |  =>  | Change1 |  +  | F2 |  =>  | Change2 |  ...  =>  ...  | OUTPUT |
  +-------+     +----+      +---------+     +----+      +---------+                +--------+

The programs only have read access to the input. It therefore is impossible to break the input data.
The available functions are grouped into different categories, explained below.

Overview of function types

Note that the documentation lists all available functions including a description and an example for each.
There’s also a video showing more usage examples.
The clips below show the GUI. The CLI version is shown separately further down.

Actions

Actions directly alter the text. There’s actions to append text, align the input, sort it, move words, remove duplicates and much more.
There’s also combinators to apply other actions e.g. per line, per word or at certain split characters.

sort word cs      -- sort the words case sensitive
reverse char      -- reverse everything character by character
forEach line {    -- apply the following per line
    prepend "[] " -- prepends "[] " to every line
    append "."    -- appends "." to every line
}

Below a basic usage example. The program is inserted at the top, the input written to the left. Procedural Text Edit then prints the result in the bottom right.
There’s also a list showing the available functions and their parameters. Note that ci stands for case insensitive, while cs stands for case sensitive.

Math Actions

There’s also many basic math functions that can be used the same as actions. They are applied if the input is a number, otherwise they do nothing.

Conditions

Conditions can be used in if statements to only alter the text in certain cases.
contains, endsWith, isNumber and many more. There’s also combinators such as all or not which make it possible to create really complex conditions. There’s also ifelse accepting a second set of actions that is executed if the condition is false.

-- append "." to every number
--        "!" to others
ifElse (isNumber) {
    append "."
} {
    append "!"
}

Conditions in action:

Selectors

With selectors actions can be applied to certain parts of the input. The selected part will be affected, while the rest will stay unchanged. There’s selectors such as after, between, firstN and nth.

-- replace the third word of every line by "third"
forEachLine {
    select (nth word 3) {
        replace "third"
    }
}

The clip below shows the usage of selectors:

Alignment

There’s also several functions that can be used to align the text at certain keywords or positions:

Usage

GUI

The GUI version can be started by running either proceduralTextEditGUI or proceduralTextEditGUIDemo.
It is split in 4 areas:

  • Top: The program
  • Bottom left: The input
  • Bottom right: The result / output
  • Far right: The autocomplete suggestions

There’s save and load buttons for the program, input and output.
The program can both be saved and loaded, the input only loaded and the output only saved.

Any changes to the input or program will result in an update of the output.
In case of an error, the error message and the last valid result will be displayed.
You have immediate feedback while writing the program or changing the input data.

CLI

The CLI or console version can be started by running either proceduralTextEditCLI or proceduralTextEditCLIDemo.

If run without parameters

Per default, proceduralTextEditCLI behaves interactively and awaits two inputs.
First the input of the program, then the program itself.
The inputs have to be single lines, consider using \n or one of the below explained parameters.
The result will be printed to stdout.

$ ./proceduralTextEditCLI
> Input as one line...
  Line one\nLine two
> Program as one line...
  toUpper    append "!"
> LINE ONE
> LINE TWO!

The parameters

You can pass the --help or -h flag to list the available parameters.

./proceduralTextEditCLI --help
Procedural Text Edit x.xx.x - © Martin Buck

Usage: proceduralTextEditCLI [-s|--silent] [-c|--maxcreate INT]
                             [-p|--program PATH] [-i|--input PATH]
                             [-o|--output PATH]
  Awaiting input as single line followed by program as single line with escaped
  newlines, or use the --program and --input flags

Available options:
  -h,--help                Show this help text
  -s,--silent              Surpress any output but the result
  -c,--maxcreate INT       Maximum count of added chars in commands (e.g. when
                           indending by n) (default: 50)
  -p,--program PATH        Path to the file that shall be parsed as program
                           (optional, not asked for program if present)
  -i,--input PATH          Path to the file that shall be used as input
                           (optional, not asked for input if present)
  -o,--output PATH         Path to the file that the result shall be written to
                           (optional, result written to file instead of stdout
                           if present)

–silent

If present, this flag surpresses any output but the result.
This makes it easier to use with other scripts or programs,
since messages such as Input as one line... won’t have to be filtered anymore.

–maxcreate

Equal to the parameter in the cfg.cfg, see the description there.

–program

You can use this flag to use the content of a file as program.
In this case you won’t be asked for a program anymore.

### program.ptep
toUpper
append "!"
$ ./proceduralTextEditCLI --program "program.ptep"
> Input as one line...
  Line one\nLine two
> LINE ONE
> LINE TWO!

–input

You can use this flag to use the content of a file as input.
In this case you won’t be asked for the input anymore.

### input.txt
Line one
Line two
$ ./proceduralTextEditCLI --input "input.txt"
> Program as one line...
  toUpper    append "!"
> LINE ONE
> LINE TWO!

–output

It’s also possible to define an output path.
The result will then be written to this file, not writing to console. (similar to using > on Linux)

$ ./proceduralTextEditCLI --output "result.txt"
> Input as one line...
  Line one\nLine two
> Program as one line...
  toUpper    append "!"
### result.txt
LINE ONE
LINE TWO!

Combination of parameters

By combining --input, --program and --output, proceduralTextEditCLI can be switched from interactive mode to file processing.

### program.ptep
toUpper
append "!"
### input.txt
Line one
Line two
$ ./proceduralTextEditCLI --program "program.ptep" --input "input.txt" --output "result.txt"
### result.txt
LINE ONE
LINE TWO!