Imaginary Preprocessor Language 0.1

This document describes imaginary preprocessor/markup language inspired by ANSI escape sequences. The language implementation should contain two parts: basic syntax parser (defined by this specification) and rules set, declaring operators that define exact behaviour.

Special characters

\ - escape control characters and "stop character"s when used with templated substitution operator (see 2.1)
^ - control sequence prefix
* - used as substitution character in templates (see 3)

Control sequences

Control sequence is a caret(^) and single character representing operator's identifier

Operator types

control sequence will be replaced with some string
paired occurences of control sequences will be replaced by corresponding pair of strings
Templated substitution
text fragment cut from control sequence to first "stop character" occurence will be substituted using template
Filtered substitution
text fragment cut from control sequence to first "stop character" occurence will be replaced by result of function

Operator declarations

Substitution operator

string for replacement

Switcher operator

pair of strings, represented by array, list or tuple

Templated/filtered substitution

stop character or string containing all of them
(only for templated substitution) template text
(only for filtered substitution) filter function


Template is string used for templated substitution where substitution character will be replaced by text fragment


This language implies one parsing iteration therefore there is no ability to nest markup in templated substitutions


 Original text: this is ^S
 Rule:          "S": { "type": "sub", "text": "Sample text" }
 Result:        this is Sample text
 Original text: this is ^bemphasized^b HTML text
 Rule:          "b": { "type": "mode", "text": ["<b>", "</b>"] }
 Result:        this is <b>emphasized</b> HTML text
 Original text: go to ^a
 Rule:          "a": { "type": "template", "stop": " \n", "text": "<a href='*'>*</a>" }
 Result:        go to <a href=''></a>
 Original text: 1234d is 0x^H1234
 Rule:          "H": { "type": "template", "stop": " \n", "filter": function(x){ return parseInt(x).toString(16).toUpperCase(); } }
 Result:        1234d is 0x4D2