https://github.com/broady/preprocess
https://github.com/broady/preprocess
Last synced: 18 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/broady/preprocess
- Owner: broady
- Created: 2017-11-10T07:35:00.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-11-10T23:19:34.000Z (over 7 years ago)
- Last Synced: 2025-02-17T08:16:41.267Z (3 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# preprocess
A simple line-by-line preprocessor.
## Command-line
### Installation
```
go get -u github.com/broady/preprocess
```### Process a file
```
preprocess < in > out
```### Usage/Options
```
Usage of preprocess:
-prefix string
Prefix for pragma. (default "//#")
```## Directives
### `if`
Takes a flag as an argument. Flags are set via command-line arguments (i.e., `preprocess foo`).
```
//# if foo
hello
//# endalso handles negations:
//# if !foo
foo flag is unset
//# end
```### `omit`
Omits the entire line.
```
won't be in the output //# omit
will be in output
```### `omit if`
Takes a flag as an argument. Omits the entire line if the flag is set.
```
foo flag is set //# omit if !foo
foo flag is unset //# omit if foo
```Trailing spaces are omitted if the line is printed.
### `include if`
Opposite of `omit if`. Includes the line if the flag is set.
```
foo flag is set //# include if foo
foo flag is unset //# include if !foo
```### `def`
Takes a name as an argument to define a template. The template is defined as the lines up to the `enddef` directive.
```
//# def newclient
ctx := context.Background()
client, err := foo.NewClient(ctx)
//# enddef
```Templates may include other directives, like `omit` and `if`.
### `template`
Takes a template name as an argument. Replaces the line with the given template.
```
//# def foo
foo
//# enddefthis line will be replaced by the foo template //# template foo
```### `replace`
Replaces a given string with another string in the output.
```
//# replace __SOMEVAR__ XXX
hello__SOMEVAR__world
```Output:
```
helloXXXworld
```Note: currently no support for whitespace in the sentinel string or the replacement string, and no way to remove a replacement.