-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.js
34 lines (28 loc) · 900 Bytes
/
grammar.js
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
/**
* @file X12 EDI grammar for the tree-sitter parsing library
* @author Kyle Huggins <[email protected]>
* @license bsd-3-clause
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar({
name: "x12",
rules: {
source_file: ($) => repeat($.segment),
segment_header: ($) => /[A-Z][A-Z0-9]{1,2}/,
element_separator: ($) => "*",
component_element_separator: ($) => ">",
segment_separator: ($) => seq("~", optional("\n")),
numeric: ($) => /[0-9\.]+/,
// NOTE(hugginsio): this might not be all supported special characters
alphanumeric: ($) => /[A-Za-z0-9!@#$%&(),-_\.\s]+/,
segment: ($) =>
seq(
$.segment_header,
$.element_separator,
repeat1(choice($.element_separator, $.numeric, $.alphanumeric)),
optional($.component_element_separator),
$.segment_separator,
),
},
});