matchertext

  1. matchertext
  2. Description
  3. Syntax
  4. Examples
    1. Simple usage
  5. Author
  6. Repository
  7. Requirements
  8. Version history
  9. License

Description

matchertext is a "syntactic discipline" that allows for cross-language embedding of source code. It was invented by Bryan Ford (who also invented parsing expression grammars and packrat parsing). To learn more, see Ford's introductory blog post, and his more substantial paper. Briefly (quote from the blog post),

The pragmatic essence of the matchertext idea is simple. First, we define six
particular ASCII characters as matchers: namely the open and close parentheses
(), the square brackets [], and the curly braces {}. We call these characters
matchers because their traditional, already-ubiquitous purpose is to be used in
matching pairs to surround and delimit other text.

Now we define matchertext as any plain text string conforming to one additional
rule or “syntactic discipline”: namely that matchers must match, throughout any
matchertext string, without exception. Nesting is allowed, but must use
corresponding matchers. For example, the string ‘([{foo}])’ is valid
matchertext, but strings like ‘(foo’, ‘bar}’, or ‘(]’ are not matchertext.

The matchertext egg extends the Scheme language to be able to host matchertext in string literals.

Syntax

[syntax] #m{MATCHERTEXT}

This is a string literal, where MATCHERTEXT is valid matchertext; no need to escape any characters as long as matchers match.

Examples

To run the examples, don't forget to

(import matchertext)

Simple usage

(string=? "hello, world" #m{hello, world}) ; #t
(string=? "#[{(##)}]\\\\(\\)[]#[{\"}]" #m{#[{(##)}]\\(\)[]#[{"}]}) ; #t

Let's try to print the code of the above example.

(display #m{(string=? "#[{(##)}]\\\\(\\)[]#[{\"}]" #m{#[{(##)}]\\(\)[]#[{"}]}) ; #t})

Author

Hernán Ibarra Mejia

Repository

Development happens in SourceHut.

Requirements

None (but testing requires the test egg).

Version history

1.0
Initial release.

License

GPLv3.