File size: 2,049 Bytes
369fac9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# One INI
The core implementation of an AST based, idiomatic INI parser which aims to provide an easy to implement and consistent INI-standard.
This reference implementation is provided as Rust-library and WASM-package.
<!-- markdownlint-disable -->
[](https://github.com/jedmao/editorconfig-ini/actions)
<!-- markdownlint-restore -->
<!-- markdownlint-disable commands-show-output -->
The work on this project started with the search for an universal parser for the [EditorConfig INI file format specification](https://editorconfig-specification.readthedocs.io/en/latest/#id3).
## WASM
To use from [Web Assembly](https://webassembly.org/), compile with:
```sh
wasm-pack build --release --target nodejs
```
and run the (limited) WASM tests with:
```sh
wasm-pack test --node
```
You can call the genereted JS wrapper with either:
```js
import { parse_to_json } from './pkg/editorconfig_ini.js'
const results = parse_to_json(`
root = true
[*]
# always use unix line endings
end_of_line = lf
`)
// {
// "version": "0.1.0",
// "body": [
// { "type": "Pair", "key": "root", "value": "true" },
// {
// "type": "Section",
// "name": "*",
// "body": [
// { "type": "Comment", "indicator": "#", "value": "always use unix line endings" },
// { "type": "Pair", "key": "end_of_line", "value": "lf" }
// ]
// }
// ]
// }
```
or:
```js
import { parse_to_uint32array, TokenTypes } from './pkg/editorconfig_ini.js'
const buf = Buffer.from(`
root = true
[*]
# always use unix line endings
end_of_line = lf
`, 'utf8')
const ary = parse_to_uint32array(buf)
// Array with token type, start byte offset, end byte offset for each token
// Uint32Array(21) [
// TokenTypes.Key, 1, 5,
// TokenTypes.Value, 8, 12,
// TokenTypes.Section, 15, 16,
// TokenTypes.CommentIndicator, 18, 19,
// TokenTypes.CommentValue, 20, 48,
// TokenTypes.Key, 49, 60,
// TokenTypes.Value, 63, 65
// ]
```
|