├── bindings ├── rust │ ├── syntax.rs │ ├── errors.rs │ ├── main.rs │ ├── syntax │ │ ├── ast.rs │ │ ├── red.rs │ │ └── green.rs │ ├── build.rs │ └── lib.rs └── node │ ├── index.js │ └── binding.cc ├── queries ├── matchup.scm ├── indents.scm └── highlights.scm ├── .gitignore ├── binding.gyp ├── package.json ├── Cargo.toml ├── README.md ├── test └── corpus │ └── literals.txt ├── src ├── tree_sitter │ └── parser.h ├── scanner.c └── grammar.json └── grammar.js /bindings/rust/syntax.rs: -------------------------------------------------------------------------------- 1 | pub mod ast; 2 | pub mod green; 3 | pub mod red; 4 | -------------------------------------------------------------------------------- /queries/matchup.scm: -------------------------------------------------------------------------------- 1 | (block_text 2 | ["'<" "<"] @open.block 3 | ">" @close.block 4 | ) @scope.block 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | node_modules 3 | build 4 | *.log 5 | package-lock.json 6 | examples 7 | !examples/ast.rs 8 | /target/ 9 | -------------------------------------------------------------------------------- /bindings/rust/errors.rs: -------------------------------------------------------------------------------- 1 | use thiserror::Error; 2 | 3 | #[derive(Debug, Clone, Error)] 4 | pub enum TSSatysfiError { 5 | #[error("parser does not respond any results.")] 6 | ParseReturnedNone, 7 | } 8 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "tree_sitter_YOUR_LANGUAGE_NAME_binding", 5 | "include_dirs": [ 6 | " 3 | #include "nan.h" 4 | 5 | using namespace v8; 6 | 7 | extern "C" TSLanguage * tree_sitter_YOUR_LANGUAGE_NAME(); 8 | 9 | namespace { 10 | 11 | NAN_METHOD(New) {} 12 | 13 | void Init(Local exports, Local module) { 14 | Local tpl = Nan::New(New); 15 | tpl->SetClassName(Nan::New("Language").ToLocalChecked()); 16 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 17 | 18 | Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); 19 | Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); 20 | Nan::SetInternalFieldPointer(instance, 0, tree_sitter_YOUR_LANGUAGE_NAME()); 21 | 22 | Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("YOUR_LANGUAGE_NAME").ToLocalChecked()); 23 | Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); 24 | } 25 | 26 | NODE_MODULE(tree_sitter_YOUR_LANGUAGE_NAME_binding, Init) 27 | 28 | } // namespace 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tree-sitter-satysfi 2 | 3 | [SATySFi](https://github.com/gfngfn/SATySFi) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter) 4 | 5 | ## Neovim でのインストール方法 6 | 7 | [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) をインストールした上で、 8 | `$XDG_CONFIG_HOME/nvim/init.lua` などの設定ファイルに以下を記載する。 9 | 10 | ```lua 11 | local parser_config = require "nvim-treesitter.parsers".get_parser_configs() 12 | parser_config.satysfi = { 13 | install_info = { 14 | url = "https://github.com/monaqa/tree-sitter-satysfi", -- local path or git repo 15 | files = {"src/parser.c", "src/scanner.c"} 16 | }, 17 | filetype = "satysfi", -- if filetype does not agrees with parser name 18 | } 19 | 20 | require'nvim-treesitter.configs'.setup { 21 | ensure_installed = { 22 | 'satysfi', 23 | }, 24 | highlight = { 25 | enable = true, 26 | }, 27 | -- if you use indent.scm 28 | -- indent = { 29 | -- enable = true, 30 | -- }, 31 | -- if you use https://github.com/andymass/vim-matchup 32 | -- matchup = { 33 | -- enable = true, 34 | -- }, 35 | } 36 | ``` 37 | 38 | その後、 `queries/` 以下のファイルを `$XDG_CONFIG_HOME/nvim/after/queries/satysfi/` 以下にコピー。 39 | (おそらく `runtimepath` 下に適切に配置されていればよさそう) 40 | -------------------------------------------------------------------------------- /bindings/rust/syntax/ast.rs: -------------------------------------------------------------------------------- 1 | //! Type definition for syntactic node. 2 | //! 3 | //! See 4 | 5 | use anyhow::*; 6 | use itertools::Itertools; 7 | use std::sync::Arc; 8 | 9 | use super::{green::GreenNodeData, red::SyntaxNode}; 10 | 11 | pub trait AstNode { 12 | fn cast(syntax: SyntaxNode) -> Option 13 | where 14 | Self: Sized; 15 | 16 | fn syntax(&self) -> &SyntaxNode; 17 | } 18 | 19 | macro_rules! register_ast_node { 20 | ($struct_name:ident, $syntax_name:literal) => { 21 | /// pub struct for $syntax_name 22 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 23 | pub struct $struct_name { 24 | syntax: SyntaxNode, 25 | } 26 | 27 | impl AstNode for $struct_name { 28 | fn cast(syntax: SyntaxNode) -> Option { 29 | match syntax.green().kind().as_str() { 30 | $syntax_name => Some($struct_name { syntax }), 31 | _ => None, 32 | } 33 | } 34 | 35 | fn syntax(&self) -> &SyntaxNode { 36 | &self.syntax 37 | } 38 | } 39 | }; 40 | } 41 | 42 | register_ast_node!(SourceFile, "source_file"); 43 | -------------------------------------------------------------------------------- /bindings/rust/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let src_dir = std::path::Path::new("src"); 3 | 4 | let mut c_config = cc::Build::new(); 5 | c_config.include(&src_dir); 6 | c_config 7 | .flag_if_supported("-Wno-unused-parameter") 8 | .flag_if_supported("-Wno-unused-but-set-variable") 9 | .flag_if_supported("-Wno-trigraphs"); 10 | let parser_path = src_dir.join("parser.c"); 11 | c_config.file(&parser_path); 12 | 13 | // If your language uses an external scanner written in C, 14 | // then include this block of code: 15 | 16 | let scanner_path = src_dir.join("scanner.c"); 17 | c_config.file(&scanner_path); 18 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 19 | 20 | c_config.compile("parser"); 21 | println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); 22 | 23 | // If your language uses an external scanner written in C++, 24 | // then include this block of code: 25 | 26 | /* 27 | let mut cpp_config = cc::Build::new(); 28 | cpp_config.cpp(true); 29 | cpp_config.include(&src_dir); 30 | cpp_config 31 | .flag_if_supported("-Wno-unused-parameter") 32 | .flag_if_supported("-Wno-unused-but-set-variable"); 33 | let scanner_path = src_dir.join("scanner.cc"); 34 | cpp_config.file(&scanner_path); 35 | cpp_config.compile("scanner"); 36 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 37 | */ 38 | } 39 | -------------------------------------------------------------------------------- /queries/indents.scm: -------------------------------------------------------------------------------- 1 | [ 2 | 3 | (block_text) 4 | (inline_text) 5 | (inline_text_list) 6 | (inline_text_bullet_list) 7 | (inline_text_bullet_item) 8 | (cmd_expr_arg) 9 | 10 | (match_expr) 11 | (parened_expr) 12 | (list) 13 | (record) 14 | (tuple) 15 | 16 | (application) 17 | (binary_expr) 18 | 19 | (sig_stmt) 20 | (struct_stmt) 21 | 22 | (let_stmt) 23 | (let_inline_stmt) 24 | (let_block_stmt) 25 | (let_math_stmt) 26 | 27 | (match_arm) 28 | 29 | ] @indent 30 | 31 | ; (match_arm expr: (_) @indent) 32 | 33 | (ctrl_if 34 | ; cond:(_) @indent 35 | "then" @branch 36 | "else" @branch 37 | ; true_clause:(_) @indent 38 | ; false_clause:(_) @indent 39 | ) @indent 40 | 41 | ; (let_stmt expr:(_) @indent) 42 | ; (let_inline_stmt expr:(_) @indent) 43 | ; (let_block_stmt expr:(_) @indent) 44 | ; (let_math_stmt expr:(_) @indent) 45 | 46 | (block_text ">" @indent_end) 47 | (inline_text "}" @indent_end) 48 | (inline_text_list "}" @indent_end) 49 | (inline_text_bullet_list "}" @indent_end) 50 | (parened_expr ")" @indent_end) 51 | (cmd_expr_arg ")" @indent_end) 52 | 53 | (list "]" @indent_end) 54 | (record "|)" @indent_end) 55 | (tuple ")" @indent_end) 56 | 57 | [ 58 | ")" 59 | "]" 60 | "}" 61 | "|)" 62 | "end" 63 | ] @branch 64 | (block_text ">" @branch) 65 | 66 | ; (match_arm "|" @branch) 67 | 68 | ; ( 69 | ; (binary_expr 70 | ; (binary_operator) @binop 71 | ; ) @aligned_indent 72 | ; (#set! "delimiter" "|") 73 | ; (#matches! @binop "|>") 74 | ; ) 75 | -------------------------------------------------------------------------------- /test/corpus/literals.txt: -------------------------------------------------------------------------------- 1 | ======= 2 | integer 3 | ======= 4 | 5 | let _ = 123 6 | let _ = 0x12 7 | let _ = 0xAB 8 | 9 | --- 10 | 11 | (source_file 12 | (program_satyh 13 | (preamble 14 | (let_stmt 15 | (literal_int)) 16 | (let_stmt 17 | (literal_int)) 18 | (let_stmt 19 | (literal_int))))) 20 | 21 | ======= 22 | float 23 | ======= 24 | 25 | let _ = 1.23 26 | let _ = .56 27 | let _ = 0. 28 | 29 | --- 30 | 31 | (source_file 32 | (program_satyh 33 | (preamble 34 | (let_stmt 35 | (literal_float)) 36 | (let_stmt 37 | (literal_float)) 38 | (let_stmt 39 | (literal_float))))) 40 | 41 | ======= 42 | length 43 | ======= 44 | 45 | let _ = 1.23pt 46 | let _ = 0pt 47 | let _ = 3cm 48 | let _ = .3cm 49 | let _ = -1.23pt 50 | 51 | --- 52 | 53 | (source_file 54 | (program_satyh 55 | (preamble 56 | (let_stmt 57 | (literal_length)) 58 | (let_stmt 59 | (literal_length)) 60 | (let_stmt 61 | (literal_length)) 62 | (let_stmt 63 | (literal_length)) 64 | (let_stmt 65 | (literal_length))))) 66 | 67 | ======= 68 | string 69 | ======= 70 | 71 | let _ = `a` 72 | let _ = ``a`` 73 | let _ = ``a` `` 74 | let _ = ``a` ``# 75 | let _ = #``a` ``# 76 | 77 | --- 78 | 79 | (source_file 80 | (program_satyh 81 | (preamble 82 | (let_stmt 83 | (literal_string)) 84 | (let_stmt 85 | (literal_string)) 86 | (let_stmt 87 | (literal_string)) 88 | (let_stmt 89 | (literal_string)) 90 | (let_stmt 91 | (literal_string))))) 92 | -------------------------------------------------------------------------------- /bindings/rust/lib.rs: -------------------------------------------------------------------------------- 1 | //! This crate provides satysfi language support for the [tree-sitter][] parsing library. 2 | //! 3 | //! Typically, you will use the [language][language func] function to add this language to a 4 | //! tree-sitter [Parser][], and then use the parser to parse some code: 5 | //! 6 | //! ``` 7 | //! let code = ""; 8 | //! let mut parser = tree_sitter::Parser::new(); 9 | //! parser.set_language(tree_sitter_satysfi::language()).expect("Error loading satysfi grammar"); 10 | //! let tree = parser.parse(code, None).unwrap(); 11 | //! ``` 12 | //! 13 | //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 14 | //! [language func]: fn.language.html 15 | //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html 16 | //! [tree-sitter]: https://tree-sitter.github.io/ 17 | 18 | pub mod errors; 19 | pub mod syntax; 20 | 21 | use tree_sitter::Language; 22 | 23 | extern "C" { 24 | fn tree_sitter_satysfi() -> Language; 25 | } 26 | 27 | /// Get the tree-sitter [Language][] for this grammar. 28 | /// 29 | /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 30 | pub fn language() -> Language { 31 | unsafe { tree_sitter_satysfi() } 32 | } 33 | 34 | /// The content of the [`node-types.json`][] file for this grammar. 35 | /// 36 | /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types 37 | pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); 38 | 39 | // Uncomment these to include any queries that this grammar contains 40 | 41 | // pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); 42 | // pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); 43 | // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); 44 | // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); 45 | 46 | #[cfg(test)] 47 | mod tests { 48 | #[test] 49 | fn test_can_load_grammar() { 50 | let mut parser = tree_sitter::Parser::new(); 51 | parser 52 | .set_language(super::language()) 53 | .expect("Error loading SATySFi language"); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /queries/highlights.scm: -------------------------------------------------------------------------------- 1 | [ 2 | "and" 3 | "as" 4 | "block-cmd" 5 | "command" 6 | "constraint" 7 | "direct" 8 | "do" 9 | "else" 10 | "end" 11 | "false" 12 | "fun" 13 | "if" 14 | "in" 15 | "inline-cmd" 16 | "let" 17 | "let-block" 18 | "let-inline" 19 | "let-math" 20 | "let-mutable" 21 | "let-rec" 22 | "match" 23 | "math-cmd" 24 | "module" 25 | "not" 26 | "of" 27 | "open" 28 | "sig" 29 | "struct" 30 | "then" 31 | "true" 32 | "type" 33 | "val" 34 | "when" 35 | "while" 36 | "with" 37 | "|" 38 | ] @keyword 39 | 40 | [ 41 | "@stage:" 42 | "@require:" 43 | "@import:" 44 | ] @include 45 | 46 | (module_name) @namespace 47 | 48 | ;; types 49 | 50 | [ 51 | (type_name) 52 | ] @type 53 | 54 | (type_param) @parameter 55 | 56 | (type_prod "*") @operator.special 57 | (type_list "?") @operator.special 58 | 59 | (type_record_unit 60 | (identifier) @field 61 | ) 62 | 63 | ;; stmt 64 | (let_stmt 65 | pattern: (identifier) @function 66 | [ 67 | arg: (_) @parameter 68 | optarg: (_) @parameter 69 | ] 70 | ) 71 | 72 | (let_rec_inner 73 | pattern: (identifier) @function 74 | ) 75 | 76 | (let_inline_stmt 77 | [ 78 | arg: (_) @parameter 79 | optarg: (_) @parameter 80 | ] 81 | ) 82 | 83 | (let_block_stmt 84 | [ 85 | arg: (_) @parameter 86 | optarg: (_) @parameter 87 | ] 88 | ) 89 | 90 | ;; expr 91 | 92 | (lambda 93 | arg: (_) @parameter 94 | ) 95 | 96 | (application 97 | function: (identifier) @function 98 | ) 99 | 100 | (application 101 | function: (modvar (identifier) @function) 102 | ) 103 | 104 | (modvar "." @namespace) 105 | 106 | (binary_operator) @operator 107 | 108 | [ 109 | "?:" 110 | "?->" 111 | "->" 112 | "<-" 113 | "=" 114 | "!" 115 | "::" 116 | ] @operator.special 117 | 118 | (variant_name) @type 119 | 120 | (record_unit 121 | . (identifier) @field 122 | ) 123 | 124 | ; (inline_token) @embedded 125 | (inline_text_list 126 | "|" @punctuation.delimiter 127 | ) 128 | (math_list 129 | "|" @punctuation.delimiter 130 | ) 131 | 132 | (math_token 133 | [ 134 | "^" 135 | "_" 136 | ] @operator 137 | ) 138 | 139 | 140 | ;; brackets/punctuations 141 | [ 142 | "{" 143 | "${" 144 | "}" 145 | 146 | "(" 147 | ")" 148 | 149 | "(|" 150 | "|)" 151 | 152 | "[" 153 | "]" 154 | ] @punctuation.bracket 155 | 156 | (block_text 157 | ["<" "'<"] @punctuation.bracket 158 | ">" @punctuation.bracket 159 | ) 160 | 161 | [ 162 | ";" 163 | ":" 164 | "," 165 | (inline_text_bullet_star) 166 | "#" 167 | ] @punctuation.delimiter 168 | 169 | ;; horizontal/vertical mode 170 | 171 | (inline_cmd_name) @function.special 172 | (block_cmd_name) @function.special 173 | ; inline_cmd_name と見分け付かないので一旦 parameter にしておく 174 | (math_cmd_name) @parameter 175 | 176 | (sig_val_stmt 177 | name: (inline_cmd_name) @parameter 178 | signature: (type_math_cmd) 179 | ) 180 | 181 | (sig_direct_stmt 182 | name: (inline_cmd_name) @parameter 183 | signature: (type_math_cmd) 184 | ) 185 | 186 | [ 187 | (inline_text_embedding) 188 | (block_text_embedding) 189 | (math_embedding) 190 | ] @function.special 191 | 192 | (block_cmd_name 193 | (module_name) @function.special 194 | ) 195 | 196 | (inline_literal_escaped) @string.escape 197 | 198 | ;; literal 199 | 200 | [ 201 | (literal_int) 202 | (literal_float) 203 | (literal_length) 204 | ] @number 205 | 206 | [ 207 | (literal_string) 208 | ] @string 209 | 210 | [ 211 | (comment) 212 | ] @comment 213 | 214 | (inline_literal_escaped) @escape 215 | -------------------------------------------------------------------------------- /src/tree_sitter/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef TREE_SITTER_PARSER_H_ 2 | #define TREE_SITTER_PARSER_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define ts_builtin_sym_error ((TSSymbol)-1) 13 | #define ts_builtin_sym_end 0 14 | #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 15 | 16 | typedef uint16_t TSStateId; 17 | 18 | #ifndef TREE_SITTER_API_H_ 19 | typedef uint16_t TSSymbol; 20 | typedef uint16_t TSFieldId; 21 | typedef struct TSLanguage TSLanguage; 22 | #endif 23 | 24 | typedef struct { 25 | TSFieldId field_id; 26 | uint8_t child_index; 27 | bool inherited; 28 | } TSFieldMapEntry; 29 | 30 | typedef struct { 31 | uint16_t index; 32 | uint16_t length; 33 | } TSFieldMapSlice; 34 | 35 | typedef struct { 36 | bool visible; 37 | bool named; 38 | bool supertype; 39 | } TSSymbolMetadata; 40 | 41 | typedef struct TSLexer TSLexer; 42 | 43 | struct TSLexer { 44 | int32_t lookahead; 45 | TSSymbol result_symbol; 46 | void (*advance)(TSLexer *, bool); 47 | void (*mark_end)(TSLexer *); 48 | uint32_t (*get_column)(TSLexer *); 49 | bool (*is_at_included_range_start)(const TSLexer *); 50 | bool (*eof)(const TSLexer *); 51 | }; 52 | 53 | typedef enum { 54 | TSParseActionTypeShift, 55 | TSParseActionTypeReduce, 56 | TSParseActionTypeAccept, 57 | TSParseActionTypeRecover, 58 | } TSParseActionType; 59 | 60 | typedef union { 61 | struct { 62 | uint8_t type; 63 | TSStateId state; 64 | bool extra; 65 | bool repetition; 66 | } shift; 67 | struct { 68 | uint8_t type; 69 | uint8_t child_count; 70 | TSSymbol symbol; 71 | int16_t dynamic_precedence; 72 | uint16_t production_id; 73 | } reduce; 74 | uint8_t type; 75 | } TSParseAction; 76 | 77 | typedef struct { 78 | uint16_t lex_state; 79 | uint16_t external_lex_state; 80 | } TSLexMode; 81 | 82 | typedef union { 83 | TSParseAction action; 84 | struct { 85 | uint8_t count; 86 | bool reusable; 87 | } entry; 88 | } TSParseActionEntry; 89 | 90 | struct TSLanguage { 91 | uint32_t version; 92 | uint32_t symbol_count; 93 | uint32_t alias_count; 94 | uint32_t token_count; 95 | uint32_t external_token_count; 96 | uint32_t state_count; 97 | uint32_t large_state_count; 98 | uint32_t production_id_count; 99 | uint32_t field_count; 100 | uint16_t max_alias_sequence_length; 101 | const uint16_t *parse_table; 102 | const uint16_t *small_parse_table; 103 | const uint32_t *small_parse_table_map; 104 | const TSParseActionEntry *parse_actions; 105 | const char * const *symbol_names; 106 | const char * const *field_names; 107 | const TSFieldMapSlice *field_map_slices; 108 | const TSFieldMapEntry *field_map_entries; 109 | const TSSymbolMetadata *symbol_metadata; 110 | const TSSymbol *public_symbol_map; 111 | const uint16_t *alias_map; 112 | const TSSymbol *alias_sequences; 113 | const TSLexMode *lex_modes; 114 | bool (*lex_fn)(TSLexer *, TSStateId); 115 | bool (*keyword_lex_fn)(TSLexer *, TSStateId); 116 | TSSymbol keyword_capture_token; 117 | struct { 118 | const bool *states; 119 | const TSSymbol *symbol_map; 120 | void *(*create)(void); 121 | void (*destroy)(void *); 122 | bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); 123 | unsigned (*serialize)(void *, char *); 124 | void (*deserialize)(void *, const char *, unsigned); 125 | } external_scanner; 126 | const TSStateId *primary_state_ids; 127 | }; 128 | 129 | /* 130 | * Lexer Macros 131 | */ 132 | 133 | #define START_LEXER() \ 134 | bool result = false; \ 135 | bool skip = false; \ 136 | bool eof = false; \ 137 | int32_t lookahead; \ 138 | goto start; \ 139 | next_state: \ 140 | lexer->advance(lexer, skip); \ 141 | start: \ 142 | skip = false; \ 143 | lookahead = lexer->lookahead; 144 | 145 | #define ADVANCE(state_value) \ 146 | { \ 147 | state = state_value; \ 148 | goto next_state; \ 149 | } 150 | 151 | #define SKIP(state_value) \ 152 | { \ 153 | skip = true; \ 154 | state = state_value; \ 155 | goto next_state; \ 156 | } 157 | 158 | #define ACCEPT_TOKEN(symbol_value) \ 159 | result = true; \ 160 | lexer->result_symbol = symbol_value; \ 161 | lexer->mark_end(lexer); 162 | 163 | #define END_STATE() return result; 164 | 165 | /* 166 | * Parse Table Macros 167 | */ 168 | 169 | #define SMALL_STATE(id) id - LARGE_STATE_COUNT 170 | 171 | #define STATE(id) id 172 | 173 | #define ACTIONS(id) id 174 | 175 | #define SHIFT(state_value) \ 176 | {{ \ 177 | .shift = { \ 178 | .type = TSParseActionTypeShift, \ 179 | .state = state_value \ 180 | } \ 181 | }} 182 | 183 | #define SHIFT_REPEAT(state_value) \ 184 | {{ \ 185 | .shift = { \ 186 | .type = TSParseActionTypeShift, \ 187 | .state = state_value, \ 188 | .repetition = true \ 189 | } \ 190 | }} 191 | 192 | #define SHIFT_EXTRA() \ 193 | {{ \ 194 | .shift = { \ 195 | .type = TSParseActionTypeShift, \ 196 | .extra = true \ 197 | } \ 198 | }} 199 | 200 | #define REDUCE(symbol_val, child_count_val, ...) \ 201 | {{ \ 202 | .reduce = { \ 203 | .type = TSParseActionTypeReduce, \ 204 | .symbol = symbol_val, \ 205 | .child_count = child_count_val, \ 206 | __VA_ARGS__ \ 207 | }, \ 208 | }} 209 | 210 | #define RECOVER() \ 211 | {{ \ 212 | .type = TSParseActionTypeRecover \ 213 | }} 214 | 215 | #define ACCEPT_INPUT() \ 216 | {{ \ 217 | .type = TSParseActionTypeAccept \ 218 | }} 219 | 220 | #ifdef __cplusplus 221 | } 222 | #endif 223 | 224 | #endif // TREE_SITTER_PARSER_H_ 225 | -------------------------------------------------------------------------------- /bindings/rust/syntax/red.rs: -------------------------------------------------------------------------------- 1 | //! Type definition for red node (syntax node). 2 | //! 3 | //! See 4 | 5 | use std::{hash::Hash, sync::Arc}; 6 | 7 | use super::green::{GreenNode, NodeChild}; 8 | 9 | #[derive(Debug, Clone)] 10 | pub struct SyntaxNode(Arc); 11 | 12 | impl std::ops::Deref for SyntaxNode { 13 | type Target = Arc; 14 | 15 | fn deref(&self) -> &Self::Target { 16 | &self.0 17 | } 18 | } 19 | 20 | #[derive(Debug, Clone, Hash)] 21 | pub struct SyntaxData { 22 | offset: usize, 23 | parent: Option, 24 | green: GreenNode, 25 | } 26 | 27 | impl SyntaxData { 28 | /// Get a reference to the syntax data's green. 29 | pub fn green(&self) -> GreenNode { 30 | self.green.clone() 31 | } 32 | } 33 | 34 | impl SyntaxNode { 35 | pub fn new_root(root: GreenNode) -> SyntaxNode { 36 | SyntaxNode(Arc::new(SyntaxData { 37 | offset: 0, 38 | parent: None, 39 | green: root, 40 | })) 41 | } 42 | 43 | pub fn parent(&self) -> Option { 44 | self.parent.clone() 45 | } 46 | 47 | pub fn children(&self) -> impl Iterator + '_ { 48 | let mut offset = self.offset; 49 | self.green.children().iter().map(move |green_child| { 50 | let child_offset = offset; 51 | offset += green_child.node().text_len(); 52 | SyntaxNode(Arc::new(SyntaxData { 53 | offset: child_offset, 54 | parent: Some(self.clone()), 55 | green: green_child.node(), 56 | })) 57 | }) 58 | } 59 | 60 | pub fn children_recursive(&self) -> Vec { 61 | Some(self.clone()) 62 | .into_iter() 63 | .chain(self.children().flat_map(|c| c.children_recursive())) 64 | .collect() 65 | } 66 | 67 | pub fn text_len(&self) -> usize { 68 | self.green.text_len() 69 | } 70 | 71 | pub fn range(&self) -> (usize, usize) { 72 | (self.offset, self.offset + self.text_len()) 73 | } 74 | 75 | pub fn includes(&self, index: usize) -> bool { 76 | index >= self.offset && index < self.offset + self.text_len() 77 | } 78 | 79 | fn dig_child(&self, index: usize) -> Option { 80 | if !self.includes(index) { 81 | return None; 82 | } 83 | for child in self.children() { 84 | if child.includes(index) { 85 | return Some(child); 86 | } 87 | } 88 | None 89 | } 90 | 91 | /// その SyntaxNode の子要素のうち、その byte 目にある red node の列を取得する。 92 | pub fn dig(&self, index: usize) -> Vec { 93 | if let Some(n) = self.dig_child(index) { 94 | n.dig(index).into_iter().chain(Some(self.clone())).collect() 95 | } else { 96 | vec![self.clone()] 97 | } 98 | } 99 | // pub fn dig(&self, index: usize) -> impl Iterator + '_ { 100 | // self.dig_child(index) 101 | // .map(|n| n.dig(index)) 102 | // .into_iter() 103 | // .flatten() 104 | // .chain(Some(self.clone())) 105 | // // if let Some(n) = self.dig_child(index) { 106 | // // n.dig(index).into_iter().chain(Some(self.clone())).collect() 107 | // // } else { 108 | // // vec![self.clone()] 109 | // // } 110 | // } 111 | 112 | /// そのノードが表すテキストを取得する。 113 | pub fn text(&self) -> String { 114 | self.green.text() 115 | } 116 | 117 | /// 短い文字列で表示する。 118 | pub fn display_short(&self) -> String { 119 | let mut s = String::new(); 120 | let (start, end) = self.range(); 121 | if self.green.is_node() { 122 | s.push_str(&format!( 123 | r#"[{}] ({}:{})"#, 124 | self.green().kind().as_str(), 125 | start, 126 | end 127 | )); 128 | } else { 129 | s.push_str(&format!( 130 | r#"'{}' ({}:{})"#, 131 | self.green().kind().as_str(), 132 | start, 133 | end 134 | )); 135 | } 136 | if self.text_len() < 40 && !self.text().contains('\n') { 137 | s.push_str(&format!(r#" "{}""#, self.text())); 138 | } 139 | s 140 | } 141 | 142 | pub fn display(&self) -> String { 143 | let mut s = String::new(); 144 | s.push_str(&self.display_short()); 145 | for child in self.children() { 146 | s.push_str(&format!(" {}", child.display_short())); 147 | } 148 | s 149 | } 150 | 151 | pub fn display_recursive(&self) -> String { 152 | self.print_aux(0) 153 | } 154 | 155 | fn print_aux(&self, indent: usize) -> String { 156 | let mut s = String::new(); 157 | s.push_str(&format!( 158 | "{}{}\n", 159 | " ".repeat(indent * 2), 160 | self.display_short() 161 | )); 162 | for child in self.children() { 163 | s.push_str(&child.print_aux(indent + 1)); 164 | } 165 | s 166 | } 167 | } 168 | 169 | impl PartialEq for SyntaxNode { 170 | fn eq(&self, other: &Self) -> bool { 171 | self.offset == other.offset && Arc::ptr_eq(&self.green, &other.green) 172 | } 173 | } 174 | 175 | impl Eq for SyntaxNode {} 176 | 177 | impl Hash for SyntaxNode { 178 | fn hash(&self, state: &mut H) { 179 | self.0.hash(state); 180 | } 181 | } 182 | #[cfg(test)] 183 | mod tests { 184 | use super::*; 185 | 186 | fn prepare_root() -> SyntaxNode { 187 | let green = GreenNode::new_root("(A) foo".to_string()).unwrap(); 188 | SyntaxNode::new_root(green) 189 | } 190 | 191 | #[test] 192 | fn test_syntax_node() { 193 | let root = prepare_root(); 194 | assert_eq!(root.offset, 0); 195 | assert_eq!(root.parent, None); 196 | assert_eq!(root.text_len(), 7); 197 | assert_eq!(root.text(), "(A) foo".to_owned()); 198 | assert!(root.includes(3)); 199 | assert!(root.includes(0)); 200 | assert!(!root.includes(8)); 201 | } 202 | 203 | #[test] 204 | fn test_syntax_node_children() { 205 | let root = prepare_root(); 206 | let task = root.children().next().expect("expected child node 'task'."); 207 | let text = task.children().nth(2).expect("expected child node 'text'."); 208 | assert_eq!(task.offset, 0); 209 | assert_eq!(task.parent(), Some(root.clone())); 210 | assert_eq!(task.text_len(), 7); 211 | assert_eq!(task.text(), "(A) foo".to_owned()); 212 | assert_eq!(text.offset, 4); 213 | assert_eq!(text.parent(), Some(task)); 214 | assert_eq!(text.text_len(), 3); 215 | assert_eq!(text.text(), "foo".to_owned()); 216 | 217 | // for n in root.dig(2) { 218 | // println!("{}", n.display()); 219 | // } 220 | 221 | println!("{}", root.display_recursive()); 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /src/scanner.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | enum TokenType { 6 | LITERAL_STRING, 7 | INLINE_TOKEN, 8 | INLINE_TOKEN_COMPOUND, 9 | PKGNAME, 10 | MODULE_PREFIX, 11 | INLINE_CMD_PREFIX, 12 | BLOCK_CMD_PREFIX, 13 | NUMBERSIGN_AFTER_NOSPACE, 14 | DUMMY, 15 | }; 16 | 17 | void *tree_sitter_satysfi_external_scanner_create() { return NULL; } 18 | void tree_sitter_satysfi_external_scanner_destroy(void *p) {} 19 | void tree_sitter_satysfi_external_scanner_reset(void *p) {} 20 | unsigned tree_sitter_satysfi_external_scanner_serialize(void *p, char *buffer) { return 0; } 21 | void tree_sitter_satysfi_external_scanner_deserialize(void *p, const char *b, unsigned n) {} 22 | 23 | static void advance(TSLexer *lexer) { 24 | lexer->advance(lexer, false); 25 | } 26 | 27 | bool tree_sitter_satysfi_external_scanner_scan(void *payload, TSLexer *lexer, 28 | const bool *valid_symbols) { 29 | // if (valid_symbols[NO_EXTRAS]) { 30 | // lexer->result_symbol = NO_EXTRAS; 31 | // if (iswspace(lexer->lookahead) || lexer->lookahead == '#') { 32 | // return false; 33 | // } else { 34 | // return true; 35 | // } 36 | // } 37 | 38 | if (valid_symbols[NUMBERSIGN_AFTER_NOSPACE] && lexer->lookahead == '#') { 39 | lexer->result_symbol = NUMBERSIGN_AFTER_NOSPACE; 40 | advance(lexer); 41 | lexer->mark_end(lexer); 42 | if ((lexer->lookahead >= 'a' && lexer->lookahead <= 'z') 43 | || (lexer->lookahead >= 'A' && lexer->lookahead <= 'Z')) { 44 | return true; 45 | } 46 | else { 47 | return false; 48 | } 49 | } 50 | 51 | if (valid_symbols[MODULE_PREFIX] 52 | && ( 53 | (lexer->lookahead >= 'A' && lexer->lookahead <= 'Z') 54 | ) 55 | ) { 56 | lexer->result_symbol = MODULE_PREFIX; 57 | 58 | advance(lexer); 59 | for (;;) { 60 | // [-A-Za-z]*を読み切る 61 | if ((lexer->lookahead >= 'a' && lexer->lookahead <= 'z') 62 | || (lexer->lookahead >= 'A' && lexer->lookahead <= 'Z') 63 | || lexer->lookahead == '-' 64 | ) { 65 | advance(lexer); 66 | continue; 67 | } 68 | break; 69 | } 70 | 71 | // mod name として登録する部分はこれで終わり 72 | lexer->mark_end(lexer); 73 | 74 | // 次の文字は空白等を挟まずピリオドでないといけない 75 | if (lexer->lookahead != '.') { 76 | return false; 77 | } 78 | advance(lexer); 79 | 80 | // 次の文字にも空白等がきてはならない 81 | if ( 82 | (lexer->lookahead == ' ' 83 | || lexer->lookahead == '\t' 84 | || lexer->lookahead == '\n' 85 | || lexer->lookahead == '\r' 86 | || lexer->lookahead == '%' 87 | )) { 88 | return false; 89 | } 90 | return true; 91 | } 92 | 93 | if (valid_symbols[INLINE_CMD_PREFIX] && (lexer->lookahead == '\\')) { 94 | lexer->result_symbol = INLINE_CMD_PREFIX; 95 | advance(lexer); 96 | lexer->mark_end(lexer); 97 | if ( 98 | (lexer->lookahead >= 'a' && lexer->lookahead <= 'z') 99 | || (lexer->lookahead >= 'A' && lexer->lookahead <= 'Z') 100 | ) { 101 | return true; 102 | } 103 | return false; 104 | } 105 | 106 | if (valid_symbols[BLOCK_CMD_PREFIX] && (lexer->lookahead == '+')) { 107 | lexer->result_symbol = BLOCK_CMD_PREFIX; 108 | advance(lexer); 109 | lexer->mark_end(lexer); 110 | if ( 111 | (lexer->lookahead >= 'a' && lexer->lookahead <= 'z') 112 | || (lexer->lookahead >= 'A' && lexer->lookahead <= 'Z') 113 | ) { 114 | return true; 115 | } 116 | return false; 117 | } 118 | 119 | if (valid_symbols[LITERAL_STRING] 120 | && (lexer->lookahead == '#' || lexer->lookahead == '`')) { 121 | lexer->result_symbol = LITERAL_STRING; 122 | 123 | if (lexer->lookahead == '#') { 124 | advance(lexer); 125 | } 126 | 127 | unsigned opening_backquote_count = 0; 128 | while(lexer->lookahead == '`') { 129 | advance(lexer); 130 | opening_backquote_count++; 131 | } 132 | if (opening_backquote_count == 0) { 133 | // '#' しかなかった場合 134 | return false; 135 | } 136 | 137 | for(;;) { 138 | if (lexer->lookahead == 0) { 139 | return false; 140 | } else if (lexer->lookahead=='`') { 141 | advance(lexer); 142 | unsigned backquote_count = 1; 143 | while(lexer->lookahead == '`') { 144 | advance(lexer); 145 | backquote_count++; 146 | } 147 | if (backquote_count == opening_backquote_count) { 148 | // 終端 # があれば読む 149 | if (lexer->lookahead == '#') { 150 | advance(lexer); 151 | } 152 | return true; 153 | } else if (backquote_count > opening_backquote_count) { 154 | return false; 155 | } 156 | } else { 157 | advance(lexer); 158 | } 159 | } 160 | } 161 | 162 | if (valid_symbols[INLINE_TOKEN] || valid_symbols[INLINE_TOKEN_COMPOUND]) { 163 | // 文法から考えて排反 164 | if (valid_symbols[INLINE_TOKEN]) { 165 | lexer->result_symbol = INLINE_TOKEN; 166 | } else { 167 | lexer->result_symbol = INLINE_TOKEN_COMPOUND; 168 | } 169 | bool has_content = false; 170 | for (;;) { 171 | lexer->mark_end(lexer); 172 | switch(lexer->lookahead) { 173 | case '}': 174 | case '\\': 175 | case '#': 176 | case '%': 177 | case '$': 178 | case '`': 179 | return has_content; 180 | case '*': 181 | case '|': 182 | if (valid_symbols[INLINE_TOKEN]) { 183 | return false; 184 | } else { 185 | return has_content; 186 | } 187 | case ';': 188 | case '{': 189 | case '\0': 190 | return false; 191 | default: 192 | advance(lexer); 193 | } 194 | has_content = true; 195 | } 196 | } 197 | 198 | if (valid_symbols[PKGNAME]) { 199 | lexer->result_symbol = PKGNAME; 200 | // 最初の space と tab だけは無視する 201 | if (lexer->lookahead == ' ' || lexer->lookahead == '\t') { 202 | return false; 203 | } 204 | for(;;) { 205 | if (lexer->lookahead == 0) { 206 | return false; 207 | } if (lexer->lookahead=='\n') { 208 | // lexer->mark_end(lexer); 209 | return true; 210 | } 211 | advance(lexer); 212 | } 213 | } 214 | 215 | return false; 216 | } 217 | -------------------------------------------------------------------------------- /bindings/rust/syntax/green.rs: -------------------------------------------------------------------------------- 1 | //! Type definition for green node. 2 | //! 3 | //! See 4 | 5 | use itertools::Itertools; 6 | use std::{ops::Deref, sync::Arc}; 7 | use tree_sitter::{Parser, TreeCursor}; 8 | 9 | use crate::errors::TSSatysfiError; 10 | 11 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 12 | pub struct GreenNode(Arc); 13 | 14 | impl Deref for GreenNode { 15 | type Target = Arc; 16 | 17 | fn deref(&self) -> &Self::Target { 18 | &self.0 19 | } 20 | } 21 | 22 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 23 | pub enum GreenNodeData { 24 | Inner(InnerNode), 25 | Token(Token), 26 | } 27 | 28 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 29 | pub struct SyntaxKind(&'static str); 30 | 31 | impl SyntaxKind { 32 | pub fn as_str(&self) -> &'static str { 33 | self.0 34 | } 35 | } 36 | 37 | /// 子要素を持つ GreenNode。 38 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 39 | pub struct InnerNode { 40 | kind: SyntaxKind, 41 | text_len: usize, 42 | children: Vec, 43 | } 44 | 45 | /// InnerNode の子要素。 46 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 47 | pub struct NodeChild { 48 | field: Option<&'static str>, 49 | node: GreenNode, 50 | } 51 | 52 | impl NodeChild { 53 | #[must_use] 54 | pub fn node(&self) -> GreenNode { 55 | self.node.clone() 56 | } 57 | 58 | #[must_use] 59 | pub fn field(&self) -> Option<&'static str> { 60 | self.field 61 | } 62 | } 63 | 64 | impl InnerNode { 65 | /// Get a reference to the node's children. 66 | pub fn children(&self) -> &[NodeChild] { 67 | self.children.as_ref() 68 | } 69 | 70 | pub fn find_children_with_field(&self, field_name: &str) -> Vec { 71 | self.children 72 | .iter() 73 | .filter(|child| child.field == Some(field_name)) 74 | .map(|child| child.node.clone()) 75 | .collect_vec() 76 | } 77 | 78 | pub fn get_children_with_field(&self) -> Vec { 79 | self.children 80 | .iter() 81 | .filter(|child| child.field.is_some()) 82 | .map(|child| child.node.clone()) 83 | .collect_vec() 84 | } 85 | } 86 | 87 | /// トークン。子要素を持たない GreenNode のこと。 88 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 89 | pub struct Token { 90 | kind: SyntaxKind, 91 | text: String, 92 | } 93 | 94 | impl Token { 95 | /// Get a reference to the token's text. 96 | pub fn text(&self) -> &str { 97 | self.text.as_ref() 98 | } 99 | } 100 | 101 | impl GreenNode { 102 | pub fn new(data: GreenNodeData) -> GreenNode { 103 | GreenNode(Arc::new(data)) 104 | } 105 | 106 | pub fn new_root(text: String) -> Result { 107 | let language_satysfi = crate::language(); 108 | let mut parser = Parser::new(); 109 | parser.set_language(language_satysfi).expect("unreachable!"); 110 | let tree = parser 111 | .parse(text.clone(), None) 112 | .ok_or(TSSatysfiError::ParseReturnedNone)?; 113 | let node = tree.root_node(); 114 | let mut cursor = node.walk(); 115 | Ok(GreenNode::new(GreenNodeData::from_cursor( 116 | &text, 117 | &mut cursor, 118 | ))) 119 | } 120 | } 121 | 122 | impl GreenNodeData { 123 | fn from_cursor(text: &str, cursor: &mut TreeCursor) -> GreenNodeData { 124 | let node = cursor.node(); 125 | let kind = SyntaxKind(node.kind()); 126 | let children = node 127 | .children(cursor) 128 | .enumerate() 129 | .map(|(idx, child)| { 130 | let field_name = node.field_name_for_child(idx as u32); 131 | let mut cursor = child.walk(); 132 | NodeChild { 133 | field: field_name, 134 | node: GreenNode(Arc::new(GreenNodeData::from_cursor(text, &mut cursor))), 135 | } 136 | }) 137 | .collect_vec(); 138 | if children.is_empty() { 139 | GreenNodeData::Token(Token { 140 | kind, 141 | text: text[node.start_byte()..node.end_byte()].to_owned(), 142 | }) 143 | } else { 144 | let text_len = node.end_byte() - node.start_byte(); 145 | GreenNodeData::Inner(InnerNode { 146 | kind, 147 | text_len, 148 | children, 149 | }) 150 | } 151 | } 152 | 153 | pub fn text(&self) -> String { 154 | match self { 155 | GreenNodeData::Inner(InnerNode { children, .. }) => { 156 | children.iter().map(|child| child.node.text()).join("") 157 | } 158 | GreenNodeData::Token(Token { text, .. }) => text.clone(), 159 | } 160 | } 161 | 162 | pub fn kind(&self) -> SyntaxKind { 163 | match self { 164 | GreenNodeData::Inner(InnerNode { kind, .. }) => *kind, 165 | GreenNodeData::Token(Token { kind, .. }) => *kind, 166 | } 167 | } 168 | 169 | pub fn as_node(&self) -> Option<&InnerNode> { 170 | if let Self::Inner(v) = self { 171 | Some(v) 172 | } else { 173 | None 174 | } 175 | } 176 | 177 | pub fn as_token(&self) -> Option<&Token> { 178 | if let Self::Token(v) = self { 179 | Some(v) 180 | } else { 181 | None 182 | } 183 | } 184 | 185 | pub fn children(&self) -> &[NodeChild] { 186 | match self { 187 | GreenNodeData::Inner(InnerNode { children, .. }) => children.deref(), 188 | _ => &[], 189 | } 190 | } 191 | 192 | pub fn text_len(&self) -> usize { 193 | match self { 194 | GreenNodeData::Inner(InnerNode { text_len, .. }) => *text_len, 195 | GreenNodeData::Token(Token { text, .. }) => text.len(), 196 | } 197 | } 198 | 199 | /// Returns `true` if the green node is [`Branch`]. 200 | /// 201 | /// [`Branch`]: GreenNode::Branch 202 | pub fn is_node(&self) -> bool { 203 | matches!(self, Self::Inner(..)) 204 | } 205 | 206 | /// Returns `true` if the green node is [`Token`]. 207 | /// 208 | /// [`Token`]: GreenNode::Token 209 | pub fn is_token(&self) -> bool { 210 | matches!(self, Self::Token(..)) 211 | } 212 | } 213 | 214 | #[cfg(test)] 215 | mod tests { 216 | 217 | use super::*; 218 | 219 | #[test] 220 | fn test_green_node() { 221 | let root = GreenNode::new_root("foo".to_string()).unwrap(); 222 | let source_file = root.as_node().unwrap(); 223 | assert_eq!(source_file.text_len, 3); 224 | assert_eq!(source_file.kind, SyntaxKind("source_file")); 225 | let task = source_file 226 | .children() 227 | .get(0) 228 | .unwrap() 229 | .node 230 | .as_node() 231 | .unwrap(); 232 | assert_eq!(task.text_len, 3); 233 | assert_eq!(task.kind, SyntaxKind("task")); 234 | let text = task.children().get(0).unwrap().node.as_node().unwrap(); 235 | assert_eq!(text.text_len, 3); 236 | assert_eq!(text.kind, SyntaxKind("text")); 237 | let subtext = text.children().get(0).unwrap().node.as_token().unwrap(); 238 | assert_eq!(subtext.text, "foo".to_owned()); 239 | assert_eq!(subtext.kind, SyntaxKind("subtext")); 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /grammar.js: -------------------------------------------------------------------------------- 1 | // vim:sw=2:fdm=marker 2 | 3 | const PREC = { 4 | recordmember: 13, 5 | stage: 12, 6 | application: 11, 7 | constructor: 10, 8 | unary: 10, 9 | divisive: 9, 10 | multiplicative: 9, 11 | additive: 8, 12 | subtractive: 8, 13 | comparative: 7, 14 | concat: 6, 15 | and: 5, 16 | or: 4, 17 | assign: 3, 18 | lambda: 3, 19 | 20 | match: 1, 21 | 22 | typeapplication: 2, 23 | typefunc: 0, 24 | typeprod: 1, 25 | }; 26 | 27 | const tokens = { 28 | whitespace: /\s+/, 29 | cmd_name: /[A-Za-z][-A-Za-z0-9]*/, 30 | } 31 | 32 | const tokensFunc = Object.fromEntries( 33 | Object.entries(tokens).map( 34 | ([k, v]) => [k, (_) => v] 35 | ) 36 | ) 37 | 38 | const binary_operator_table = [ 39 | [PREC.and, /&[-+*/^&|=<>!:~'.?]+/], 40 | [PREC.or, /\|[-+*/^&|=<>!:~'.?]+/], 41 | [PREC.comparative, /=[-+*/^&|=<>!:~'.?]+/], 42 | // <- は許されない 43 | [PREC.comparative, /<[+*/^&|=<>!:~'.?]?/], 44 | [PREC.comparative, /<[-+*/^&|=<>!:~'.?]{2,}/], 45 | [PREC.comparative, />[+*/^&|=<>!:~'.?]*/], 46 | [PREC.concat, /\^[-+*/^&|=<>!:~'.?]*/], 47 | [PREC.concat, "::"], 48 | [PREC.additive, /\+[-+*/^&|=<>!:~'.?]*/], 49 | // -> は許されない 50 | [PREC.subtractive, /-[+*/^&|=!:~'.?]{2,}/], 52 | [PREC.multiplicative, /\*[-+*/^&|=<>!:~'.?]*/], 53 | [PREC.divisive, /\/[-+*/^&|=<>!:~'.?]*/], 54 | [PREC.divisive, "mod"], 55 | ]; 56 | 57 | 58 | module.exports = grammar({ 59 | name: "satysfi", 60 | 61 | extras: ($) => [ 62 | $.whitespace, 63 | $.comment 64 | ], 65 | 66 | word: ($) => $.identifier, 67 | 68 | supertype: ($) => [ 69 | $._literal, 70 | $._expr, 71 | ], 72 | 73 | conflicts: ($) => [ 74 | [$.binary_operator, $.unary_operator], 75 | ], 76 | 77 | externals: ($) => [ 78 | $.literal_string, 79 | // {} の中に入っているインラインテキスト。 80 | $.inline_token, 81 | // {||} や {* } の中に入っているインラインテキスト。 82 | $._inline_token_compound, 83 | // パッケージ名。 84 | $.pkgname, 85 | // +Mod.alpha や Mod.(1 + 2) などの Mod. の部分。ピリオド前後のスペースが許されない。 86 | $._module_prefix, 87 | // "\" の直後に空白が入ってはならないような"\"。 88 | $._inline_cmd_prefix, 89 | // "+" の直後に空白が入ってはならないような"+"。 90 | $._block_cmd_prefix, 91 | // 空白やコメントが入らないことを保証するが、 Lexer は進めない。 92 | $._numbersign_after_nospace, 93 | // $.no_extras, 94 | // 決してマッチしないダミーパターン。 95 | $._dummy, 96 | ], 97 | 98 | rules: { 99 | // program {{{ 100 | source_file: ($) => choice($.program_saty, $.program_satyh), 101 | 102 | comment: (_) => token(seq("%", /.*/)), 103 | 104 | program_saty: ($) => 105 | seq( 106 | optional(field("stage", $.header_stage)), 107 | optional(field("headers", $.headers)), 108 | optional(seq(field("preamble", $.preamble), "in")), 109 | field("expr", $._expr), 110 | ), 111 | 112 | program_satyh: ($) => 113 | seq( 114 | optional(field("stage", $.header_stage)), 115 | optional(field("headers", $.headers)), 116 | field("preamble", $.preamble), 117 | ), 118 | 119 | // }}} 120 | 121 | // header {{{ 122 | headers: ($) => seq(repeat1($._header)), 123 | 124 | _header: ($) => choice( 125 | $.header_require, 126 | $.header_import, 127 | ), 128 | 129 | header_require: $ => seq("@require:", optional($.whitespace), field("require", $.pkgname)), 130 | header_import: $ => seq("@import:", optional($.whitespace), field("import", $.pkgname)), 131 | 132 | header_stage: ($) => 133 | seq( 134 | "@stage:", 135 | choice( 136 | field("0", "0"), 137 | field("1", "1"), 138 | field("persistent", "persistent"), 139 | ), 140 | // "\n", 141 | ), 142 | 143 | // pkgname: (_) => /[^\n\r]+/, 144 | 145 | // }}} 146 | 147 | // statement {{{ 148 | 149 | preamble: ($) => repeat1($._statement), 150 | 151 | _statement: ($) => 152 | prec.left( 153 | 0, 154 | choice( 155 | $.let_stmt, 156 | $.let_rec_stmt, 157 | $.let_inline_stmt, 158 | $.let_block_stmt, 159 | $.let_math_stmt, 160 | $.let_mutable_stmt, 161 | $.type_stmt, 162 | $.module_stmt, 163 | $.open_stmt, 164 | ), 165 | ), 166 | 167 | let_stmt: ($) => 168 | seq( 169 | "let", 170 | field("pattern", $._pattern), 171 | optional($._let_stmt_argument), 172 | "=", 173 | field("expr", $._expr), 174 | ), 175 | 176 | _let_stmt_argument: ($) => 177 | choice( 178 | seq(":", field("signiture", $._type_expr), "|", repeat1($._arg)), 179 | seq(":", field("signiture", $._type_expr)), 180 | seq(optional("|"), repeat1($._arg)), 181 | ), 182 | 183 | let_rec_stmt: ($) => 184 | seq( 185 | "let-rec", 186 | sep1("and", $.let_rec_inner), 187 | ), 188 | 189 | let_rec_inner: ($) => 190 | choice( 191 | seq( 192 | field("pattern", $._pattern), 193 | optional($._let_rec_stmt_argument), 194 | "=", 195 | field("expr", $._expr), 196 | ), 197 | seq( 198 | field("pattern", $._pattern), 199 | repeat(seq("|", field("arm", $.let_rec_matcharm))), 200 | ), 201 | ), 202 | 203 | _let_rec_stmt_argument: ($) => 204 | choice( 205 | seq(":", field("signiture", $._type_expr), "|", repeat1($._arg)), 206 | seq(":", field("signiture", $._type_expr)), 207 | repeat1($._arg), 208 | ), 209 | 210 | let_rec_matcharm: ($) => seq(repeat($._arg), "=", field("expr", $._expr)), 211 | 212 | let_inline_stmt: ($) => 213 | choice( 214 | seq( 215 | "let-inline", 216 | field("ctx", $.identifier), 217 | field("name", $.inline_cmd_name), 218 | repeat($._arg), 219 | "=", 220 | field("expr", $._expr), 221 | ), 222 | seq( 223 | "let-inline", 224 | field("name", $.inline_cmd_name), 225 | repeat(field("arg", $._pattern)), 226 | "=", 227 | field("expr", $._expr), 228 | ), 229 | ), 230 | 231 | let_block_stmt: ($) => 232 | choice( 233 | seq( 234 | "let-block", 235 | field("ctx", $.identifier), 236 | field("name", $.block_cmd_name), 237 | repeat($._arg), 238 | "=", 239 | field("expr", $._expr), 240 | ), 241 | seq( 242 | "let-block", 243 | field("name", $.block_cmd_name), 244 | repeat(field("arg", $._pattern)), 245 | "=", 246 | field("expr", $._expr), 247 | ), 248 | ), 249 | 250 | let_math_stmt: ($) => 251 | seq( 252 | "let-math", 253 | field("name", $.math_cmd_name), 254 | repeat($._arg), 255 | "=", 256 | field("expr", $._expr), 257 | ), 258 | 259 | let_mutable_stmt: ($) => 260 | seq( 261 | "let-mutable", 262 | field("name", $.identifier), 263 | "<-", 264 | field("expr", $._expr), 265 | ), 266 | 267 | type_stmt: ($) => 268 | seq( 269 | "type", 270 | sep1("and", $.type_inner), 271 | ), 272 | 273 | type_inner: ($) => 274 | choice( 275 | seq( 276 | repeat(field("param", $.type_param)), 277 | field("name", $.type_name), 278 | "=", 279 | repeat1(seq("|", field("variant", $.type_variant))), 280 | repeat(field("constraint", $.constraint)), 281 | ), 282 | seq( 283 | repeat(field("param", $.type_param)), 284 | field("name", $.type_name), 285 | "=", 286 | sep1("|", field("variant", $.type_variant)), 287 | repeat(field("constraint", $.constraint)), 288 | ), 289 | seq( 290 | repeat(field("param", $.type_param)), 291 | field("name", $.type_name), 292 | "=", 293 | field("expr", $._type_expr), 294 | repeat(field("constraint", $.constraint)), 295 | ), 296 | ), 297 | 298 | type_variant: ($) => 299 | seq( 300 | field("name", $.variant_name), 301 | optional(seq("of", field("expr", $._type_expr))), 302 | ), 303 | 304 | open_stmt: ($) => seq("open", $.module_name), 305 | 306 | _arg: ($) => 307 | choice( 308 | field("arg", $._pattern), 309 | seq("?:", field("optarg", $._pattern)), 310 | ), 311 | 312 | // }}} 313 | 314 | // module {{{ 315 | module_stmt: ($) => 316 | seq( 317 | "module", 318 | field("name", $.module_name), 319 | ":", 320 | field("sig", $.sig_stmt), 321 | "=", 322 | field("struct", $.struct_stmt), 323 | ), 324 | 325 | sig_stmt: ($) => 326 | seq( 327 | "sig", 328 | repeat($._sig_inner), 329 | "end", 330 | ), 331 | 332 | struct_stmt: ($) => 333 | seq( 334 | "struct", 335 | repeat($._statement), 336 | "end", 337 | ), 338 | 339 | _sig_inner: ($) => 340 | choice( 341 | $.sig_type_stmt, 342 | $.sig_val_stmt, 343 | $.sig_direct_stmt, 344 | ), 345 | 346 | sig_type_stmt: ($) => 347 | seq( 348 | "type", 349 | repeat(field("param", $.type_param)), 350 | field("name", $.identifier), 351 | repeat(field("constraint", $.constraint)), 352 | ), 353 | 354 | sig_val_stmt: ($) => 355 | seq( 356 | "val", 357 | choice( 358 | field("name", $.identifier), 359 | seq("(", field("name", $.binary_operator), ")"), 360 | field("name", $.inline_cmd_name), 361 | field("name", $.block_cmd_name), 362 | ), 363 | ":", 364 | field("signature", $._type_expr), 365 | repeat(field("constraint", $.constraint)), 366 | ), 367 | 368 | sig_direct_stmt: ($) => 369 | seq( 370 | "direct", 371 | choice( 372 | field("name", $.inline_cmd_name), 373 | field("name", $.block_cmd_name), 374 | ), 375 | ":", 376 | field("signature", $._type_expr), 377 | repeat(field("constraint", $.constraint)), 378 | ), 379 | 380 | // }}} 381 | 382 | // types {{{ 383 | _type_expr: ($) => 384 | choice( 385 | $.type_fun, 386 | $.type_prod, 387 | $.type_inline_cmd, 388 | $.type_block_cmd, 389 | $.type_math_cmd, 390 | $.type_application, 391 | $.type_record, 392 | $.type_param, 393 | $.type_name, 394 | seq("(", $._type_expr, ")"), 395 | ), 396 | 397 | type_fun: ($) => 398 | prec.right( 399 | PREC.typefunc, 400 | seq( 401 | choice( 402 | seq(field("optarg", $._type_expr), "?->"), 403 | seq(field("arg", $._type_expr), "->"), 404 | ), 405 | field("return", $._type_expr), 406 | ), 407 | ), 408 | 409 | type_prod: ($) => 410 | prec.left( 411 | PREC.typeprod, 412 | seq( 413 | $._type_expr, 414 | "*", 415 | $._type_expr, 416 | ), 417 | ), 418 | 419 | type_inline_cmd: ($) => seq($.type_list, "inline-cmd"), 420 | 421 | type_block_cmd: ($) => seq($.type_list, "block-cmd"), 422 | 423 | type_math_cmd: ($) => seq($.type_list, "math-cmd"), 424 | 425 | type_list: ($) => 426 | seq( 427 | "[", 428 | sep( 429 | ";", 430 | choice( 431 | seq(field("optarg", $._type_expr), "?"), 432 | seq(field("arg", $._type_expr)), 433 | ), 434 | ), 435 | optional(";"), 436 | "]", 437 | ), 438 | 439 | type_record: ($) => 440 | seq("(|", sep(";", $.type_record_unit), optional(";"), "|)"), 441 | 442 | type_record_unit: ($) => seq($.identifier, ":", $._type_expr), 443 | 444 | type_application: ($) => 445 | prec.left(PREC.typeapplication, seq($._type_expr, $._type_expr)), 446 | 447 | type_param: (_) => token.immediate(seq("'", /[a-z][-A-Za-z0-9]*/)), 448 | 449 | type_name: ($) => choice($.identifier, $.modvar), 450 | // type_name: ($) => $.identifier, 451 | 452 | constraint: ($) => seq("constraint", $.type_param, "::", $.type_record), 453 | 454 | // }}} 455 | 456 | // pattern {{{ 457 | pat_as: ($) => 458 | prec.left(0, seq($._pat_cons, optional(seq("as", $.identifier)))), 459 | 460 | _pat_cons: ($) => 461 | choice( 462 | seq($._pattern, "::", $.pat_as), 463 | $.pat_variant, 464 | $._pattern, 465 | ), 466 | 467 | _pattern: ($) => 468 | choice( 469 | $.pat_list, 470 | seq("(", $.binary_operator, ")"), 471 | seq("(", $.unary_operator, ")"), 472 | seq("(", $.pat_as, ")"), 473 | $.pat_tuple, 474 | "_", 475 | $.identifier, 476 | $._literal, 477 | ), 478 | 479 | pat_variant: ($) => seq($.variant_name, optional($._pattern)), 480 | 481 | pat_list: ($) => seq("[", sep(";", $.pat_as), optional(";"), "]"), 482 | 483 | pat_tuple: ($) => seq("(", sep2(",", $.pat_as), ")"), 484 | 485 | // }}} 486 | 487 | // expr {{{ 488 | _expr: ($) => 489 | choice( 490 | $.match_expr, 491 | $.bind_stmt, 492 | $.ctrl_while, 493 | $.ctrl_if, 494 | $.lambda, 495 | $.assignment, 496 | $.binary_expr, 497 | $.application, 498 | $.unary_operator_expr, 499 | $.command_application, 500 | $.variant_constructor, 501 | $.record_member, 502 | $._unary, 503 | ), 504 | 505 | match_expr: ($) => 506 | prec.left( 507 | PREC.match, 508 | seq( 509 | "match", 510 | field("expr", $._expr), 511 | "with", 512 | optional("|"), 513 | sep1("|", $.match_arm), 514 | ), 515 | ), 516 | 517 | match_arm: ($) => 518 | seq( 519 | field("pattern", $.pat_as), 520 | optional(field("guard", $.match_guard)), 521 | "->", 522 | field("expr", $._expr,) 523 | ), 524 | 525 | match_guard: ($) => seq("when", $._expr), 526 | 527 | bind_stmt: ($) => 528 | seq( 529 | choice( 530 | $.let_stmt, 531 | $.let_rec_stmt, 532 | $.let_math_stmt, 533 | $.let_mutable_stmt, 534 | $.open_stmt, 535 | ), 536 | "in", 537 | field("expr", $._expr), 538 | ), 539 | 540 | ctrl_while: ($) => seq("while", $._expr, "do", $._expr), 541 | 542 | ctrl_if: ($) => seq( 543 | "if", 544 | field("cond", $._expr), 545 | "then", 546 | field("true_clause", $._expr), 547 | "else", 548 | field("false_clause", $._expr), 549 | ), 550 | 551 | lambda: ($) => 552 | prec.right(PREC.lambda, seq("fun", repeat1(field('arg', $._pattern)), "->", $._expr)), 553 | 554 | assignment: ($) => 555 | prec.right(PREC.assign, seq($.identifier, "<-", $._expr)), 556 | 557 | binary_expr: ($) => 558 | choice( 559 | ...binary_operator_table.map(([precedence, operator]) => 560 | prec.left( 561 | precedence, 562 | seq( 563 | field("left", $._expr), 564 | field("operator", alias(operator, $.binary_operator)), 565 | field("right", $._expr), 566 | ), 567 | ) 568 | ), 569 | ), 570 | 571 | binary_operator: (_) => choice( 572 | ...binary_operator_table.map(([precedence, operator]) => operator) 573 | ), 574 | 575 | unary_operator_expr: ($) => 576 | choice( 577 | prec.right(PREC.unary, seq($.unary_operator, $._expr)), 578 | prec.right(PREC.stage, seq($.unary_prefix, $._expr)), 579 | ), 580 | 581 | unary_operator: (_) => choice("-", "not", "!"), 582 | 583 | unary_prefix: (_) => /[&!~]/, 584 | 585 | application: ($) => 586 | prec.left( 587 | PREC.application, 588 | seq( 589 | field("function", choice( 590 | $.application, 591 | $.unary_operator_expr, 592 | $.variant_constructor, 593 | $.record_member, 594 | $._unary, 595 | )), 596 | choice( 597 | field("arg", $._application_args), 598 | field("opt", $._application_args_opt), 599 | ), 600 | ), 601 | ), 602 | 603 | // TODO: 本当は unary ではない 604 | _application_args: ($) => choice($.unary_operator_expr, $.variant_constructor, $.record_member, $._unary), 605 | 606 | _application_args_opt: ($) => seq("?:", $._application_args), 607 | 608 | command_application: ($) => 609 | prec.left(PREC.application, seq("command", $.inline_cmd_name)), 610 | 611 | variant_constructor: ($) => 612 | prec.left(PREC.constructor, seq($.variant_name, optional($._unary))), 613 | 614 | record_member: $ => 615 | seq($._unary, "#", $.identifier), 616 | 617 | // }}} 618 | 619 | // unary {{{ 620 | _unary: ($) => 621 | seq( 622 | choice( 623 | $.block_text, 624 | $.inline_text, 625 | $.inline_text_list, 626 | $.inline_text_bullet_list, 627 | $.math_text, 628 | $.math_list, 629 | $.record, 630 | $.list, 631 | $.tuple, 632 | $.parened_expr, 633 | $.expr_with_mod, 634 | $.modvar, 635 | $._literal, 636 | $.identifier, 637 | ), 638 | ), 639 | 640 | record: ($) => 641 | choice( 642 | seq("(|", $._unary, "with", $._record_inner, "|)"), 643 | seq("(|", optional($._record_inner), "|)"), 644 | ), 645 | 646 | _record_inner: ($) => seq(sep1(";", $.record_unit), optional(";")), 647 | 648 | record_unit: ($) => seq($.identifier, "=", $._expr), 649 | 650 | list: ($) => 651 | choice( 652 | seq("[", sep(";", $._expr), optional(";"), "]"), 653 | ), 654 | 655 | tuple: ($) => 656 | seq( 657 | "(", 658 | sep2(",", $._expr), 659 | ")", 660 | ), 661 | 662 | parened_expr: $ => seq( 663 | "(", 664 | choice( 665 | $.binary_operator, 666 | $._expr, 667 | ), 668 | ")" 669 | ), 670 | 671 | expr_with_mod: ($) => seq(alias($._module_prefix, $.module_name), ".(", $._expr, ")"), 672 | 673 | modvar: ($) => seq(alias($._module_prefix, $.module_name), ".", $.identifier), 674 | 675 | _mod_cmd_name: ($) => seq(alias($._module_prefix, $.module_name), ".", $.cmd_name), 676 | 677 | module_name: (_) => /[A-Z][-A-Za-z0-9]*/, 678 | 679 | variant_name: ($) => /[A-Z][-A-Za-z0-9]*/, 680 | 681 | // }}} 682 | 683 | // literal {{{ 684 | _literal: ($) => 685 | choice( 686 | $.literal_unit, 687 | $.literal_bool, 688 | $.literal_length, 689 | $.literal_int, 690 | $.literal_string, 691 | $.literal_float, 692 | ), 693 | 694 | identifier: (_) => /[a-z][-a-zA-Z0-9]*/, 695 | 696 | literal_unit: (_) => seq("(", ")"), 697 | 698 | literal_bool: (_) => choice("true", "false"), 699 | 700 | literal_length: (_) => { 701 | const digits = /[0-9]+/; 702 | return token(choice( 703 | seq(optional("-"), digits, /[a-z]+/), 704 | seq(optional("-"), digits, ".", optional(digits), /[a-z]+/), 705 | seq(optional("-"), optional(digits), ".", digits, /[a-z]+/), 706 | )); 707 | }, 708 | 709 | literal_int: (_) => 710 | token(choice( 711 | seq( 712 | choice("0x", "0X"), 713 | repeat1(/[A-F0-9]/), 714 | ), 715 | repeat1(/[0-9]/), 716 | )), 717 | 718 | literal_float: (_) => { 719 | const digits = repeat1(/[0-9]/); 720 | 721 | return token( 722 | choice( 723 | seq(digits, ".", optional(digits)), 724 | seq(optional(digits), ".", digits), 725 | ), 726 | ); 727 | }, 728 | // }}} 729 | 730 | // command {{{ 731 | 732 | inline_cmd: ($) => 733 | seq( 734 | field("name", $.inline_cmd_name), 735 | repeat( 736 | choice(field("arg", $.cmd_expr_arg), field("opt", $.cmd_expr_option)), 737 | ), 738 | choice(repeat1(field("arg", $.cmd_text_arg)), ";"), 739 | ), 740 | 741 | inline_cmd_name: ($) => seq( 742 | alias($._inline_cmd_prefix, "\\"), 743 | choice( 744 | $._mod_cmd_name, 745 | $.cmd_name, 746 | ) 747 | ), 748 | 749 | block_cmd: ($) => 750 | seq( 751 | field("name", $.block_cmd_name), 752 | repeat( 753 | choice(field("arg", $.cmd_expr_arg), field("opt", $.cmd_expr_option)), 754 | ), 755 | choice(repeat1(field("arg", $.cmd_text_arg)), ";"), 756 | ), 757 | 758 | block_cmd_name: ($) => seq( 759 | alias($._block_cmd_prefix, "+"), 760 | choice( 761 | $._mod_cmd_name, 762 | $.cmd_name, 763 | ) 764 | ), 765 | 766 | 767 | cmd_expr_arg: ($) => $._cmd_expr_arg_inner, 768 | cmd_expr_option: ($) => seq("?:", $._cmd_expr_arg_inner), 769 | _cmd_expr_arg_inner: ($) => choice( 770 | seq("(", $._expr, ")"), 771 | $.list, 772 | $.record, 773 | ), 774 | 775 | cmd_text_arg: ($) => 776 | choice( 777 | $.inline_text, 778 | $.inline_text_list, 779 | $.inline_text_bullet_list, 780 | alias($._cmd_text_arg_block, $.block_text), 781 | // seq("<", optional($.vertical), ">"), 782 | ), 783 | _cmd_text_arg_block: $ => seq("<", optional($.vertical), ">"), 784 | 785 | math_cmd: ($) => 786 | prec.left( 787 | 1, 788 | seq( 789 | field("name", $.math_cmd_name), 790 | repeat( 791 | choice( 792 | field("arg", $.math_cmd_expr_arg), 793 | field("opt", $.math_cmd_expr_option), 794 | ), 795 | ), 796 | ), 797 | ), 798 | 799 | math_cmd_name: ($) => seq( 800 | alias($._inline_cmd_prefix, "\\"), 801 | choice( 802 | $._mod_cmd_name, 803 | $.cmd_name, 804 | ) 805 | ), 806 | 807 | math_cmd_expr_arg: ($) => seq($._math_cmd_expr_arg_inner), 808 | 809 | math_cmd_expr_option: ($) => seq("?:", $._math_cmd_expr_arg_inner), 810 | 811 | _math_cmd_expr_arg_inner: ($) => 812 | choice( 813 | seq("{", $.math, "}"), 814 | seq("!", $.inline_text), 815 | seq("!", $.inline_text_list), 816 | seq("!", $.inline_text_bullet_list), 817 | seq("!", "<", $.vertical, ">"), 818 | seq("!", "(", $._expr, ")"), 819 | seq("!", $.list), 820 | seq("!", $.record), 821 | ), 822 | 823 | // }}} 824 | 825 | // horizontal mode {{{ 826 | inline_text: ($) => seq("{", optional($.horizontal), "}"), 827 | 828 | inline_text_list: ($) => 829 | choice( 830 | seq( 831 | "{", 832 | "|", 833 | optional(alias($._horizontal_compound, $.horizontal)), 834 | repeat( 835 | seq("|", optional(alias($._horizontal_compound, $.horizontal))), 836 | ), 837 | // /\|\s*\}/, 838 | "|", 839 | "}", 840 | ), 841 | ), 842 | 843 | inline_text_bullet_list: ($) => 844 | seq( 845 | "{", 846 | repeat1($.inline_text_bullet_item), 847 | "}", 848 | ), 849 | 850 | horizontal: ($) => 851 | repeat1(choice( 852 | $.inline_literal_escaped, 853 | $.inline_text_embedding, 854 | $.math_text, 855 | $.literal_string, 856 | $.inline_cmd, 857 | $.inline_token, 858 | )), 859 | 860 | _horizontal_compound: ($) => 861 | repeat1(choice( 862 | $.inline_literal_escaped, 863 | $.inline_text_embedding, 864 | $.math_text, 865 | $.literal_string, 866 | $.inline_cmd, 867 | alias($._inline_token_compound, $.inline_token), 868 | )), 869 | 870 | inline_text_bullet_item: ($) => 871 | seq( 872 | $.inline_text_bullet_star, 873 | optional(alias($._horizontal_compound, $.horizontal)), 874 | ), 875 | inline_text_bullet_star: (_) => /\*+/, 876 | 877 | inline_literal_escaped: (_) => 878 | choice( 879 | "\\@", 880 | "\\`", 881 | "\\\\", 882 | "\\{", 883 | "\\}", 884 | "\\%", 885 | "\\|", 886 | "\\*", 887 | "\\$", 888 | "\\#", 889 | "\\;", 890 | "\\ ", 891 | '\\"', 892 | ), 893 | 894 | inline_text_embedding: ($) => 895 | seq($._numbersign_after_nospace, $.identifier, ";"), 896 | 897 | // }}} 898 | 899 | // vertical mode {{{ 900 | block_text: ($) => seq("'<", optional($.vertical), ">"), 901 | 902 | vertical: ($) => 903 | repeat1(choice( 904 | $.block_cmd, 905 | $.block_text_embedding, 906 | )), 907 | 908 | block_text_embedding: ($) => 909 | seq($._numbersign_after_nospace, $.identifier, ";"), 910 | 911 | // }}} 912 | 913 | // math mode {{{ 914 | math_text: ($) => seq("${", optional($.math), "}"), 915 | 916 | math_list: ($) => 917 | choice( 918 | seq("${", "|", "|", "}"), 919 | seq("${", "|", repeat(seq($.math, "|")), "}"), 920 | ), 921 | 922 | math: ($) => prec.left(0, repeat1(choice($.math_token, $.math_unary))), 923 | 924 | math_token: ($) => 925 | prec.left( 926 | 0, 927 | choice( 928 | seq( 929 | $.math_unary, 930 | field("sup", $._math_sup), 931 | field("sub", $._math_sub), 932 | ), 933 | seq( 934 | $.math_unary, 935 | field("sub", $._math_sub), 936 | field("sup", $._math_sup), 937 | ), 938 | seq($.math_unary, field("sup", $._math_sup)), 939 | seq($.math_unary, field("sub", $._math_sub)), 940 | ), 941 | ), 942 | 943 | _math_sup: ($) => seq("^", $._math_group), 944 | 945 | _math_sub: ($) => seq("_", $._math_group), 946 | _math_group: ($) => 947 | choice( 948 | $.math_unary, 949 | seq("{", $.math, "}"), 950 | ), 951 | 952 | math_unary: ($) => 953 | choice( 954 | /[A-Za-z0-9]/, 955 | /\\[!"#$%&'()*+,./0-9:;<=>?@^_`{|}~-]/, 956 | "\\\\", 957 | "\\ ", 958 | /[+*/:=<>~'.,?`-]/, 959 | $.math_cmd, 960 | $.math_embedding, 961 | ), 962 | 963 | math_embedding: ($) => seq($._numbersign_after_nospace, $.identifier), 964 | // }}} 965 | 966 | ...tokensFunc 967 | }, 968 | }); 969 | 970 | function sep(delimiter, rule) { 971 | return optional(sep1(delimiter, rule)); 972 | } 973 | 974 | function sep1(delimiter, rule) { 975 | return seq(rule, repeat(seq(delimiter, rule))); 976 | } 977 | 978 | function sep2(delimiter, rule) { 979 | return seq(rule, repeat1(seq(delimiter, rule))); 980 | } 981 | -------------------------------------------------------------------------------- /src/grammar.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "satysfi", 3 | "word": "identifier", 4 | "rules": { 5 | "source_file": { 6 | "type": "CHOICE", 7 | "members": [ 8 | { 9 | "type": "SYMBOL", 10 | "name": "program_saty" 11 | }, 12 | { 13 | "type": "SYMBOL", 14 | "name": "program_satyh" 15 | } 16 | ] 17 | }, 18 | "comment": { 19 | "type": "TOKEN", 20 | "content": { 21 | "type": "SEQ", 22 | "members": [ 23 | { 24 | "type": "STRING", 25 | "value": "%" 26 | }, 27 | { 28 | "type": "PATTERN", 29 | "value": ".*" 30 | } 31 | ] 32 | } 33 | }, 34 | "program_saty": { 35 | "type": "SEQ", 36 | "members": [ 37 | { 38 | "type": "CHOICE", 39 | "members": [ 40 | { 41 | "type": "FIELD", 42 | "name": "stage", 43 | "content": { 44 | "type": "SYMBOL", 45 | "name": "header_stage" 46 | } 47 | }, 48 | { 49 | "type": "BLANK" 50 | } 51 | ] 52 | }, 53 | { 54 | "type": "CHOICE", 55 | "members": [ 56 | { 57 | "type": "FIELD", 58 | "name": "headers", 59 | "content": { 60 | "type": "SYMBOL", 61 | "name": "headers" 62 | } 63 | }, 64 | { 65 | "type": "BLANK" 66 | } 67 | ] 68 | }, 69 | { 70 | "type": "CHOICE", 71 | "members": [ 72 | { 73 | "type": "SEQ", 74 | "members": [ 75 | { 76 | "type": "FIELD", 77 | "name": "preamble", 78 | "content": { 79 | "type": "SYMBOL", 80 | "name": "preamble" 81 | } 82 | }, 83 | { 84 | "type": "STRING", 85 | "value": "in" 86 | } 87 | ] 88 | }, 89 | { 90 | "type": "BLANK" 91 | } 92 | ] 93 | }, 94 | { 95 | "type": "FIELD", 96 | "name": "expr", 97 | "content": { 98 | "type": "SYMBOL", 99 | "name": "_expr" 100 | } 101 | } 102 | ] 103 | }, 104 | "program_satyh": { 105 | "type": "SEQ", 106 | "members": [ 107 | { 108 | "type": "CHOICE", 109 | "members": [ 110 | { 111 | "type": "FIELD", 112 | "name": "stage", 113 | "content": { 114 | "type": "SYMBOL", 115 | "name": "header_stage" 116 | } 117 | }, 118 | { 119 | "type": "BLANK" 120 | } 121 | ] 122 | }, 123 | { 124 | "type": "CHOICE", 125 | "members": [ 126 | { 127 | "type": "FIELD", 128 | "name": "headers", 129 | "content": { 130 | "type": "SYMBOL", 131 | "name": "headers" 132 | } 133 | }, 134 | { 135 | "type": "BLANK" 136 | } 137 | ] 138 | }, 139 | { 140 | "type": "FIELD", 141 | "name": "preamble", 142 | "content": { 143 | "type": "SYMBOL", 144 | "name": "preamble" 145 | } 146 | } 147 | ] 148 | }, 149 | "headers": { 150 | "type": "SEQ", 151 | "members": [ 152 | { 153 | "type": "REPEAT1", 154 | "content": { 155 | "type": "SYMBOL", 156 | "name": "_header" 157 | } 158 | } 159 | ] 160 | }, 161 | "_header": { 162 | "type": "CHOICE", 163 | "members": [ 164 | { 165 | "type": "SYMBOL", 166 | "name": "header_require" 167 | }, 168 | { 169 | "type": "SYMBOL", 170 | "name": "header_import" 171 | } 172 | ] 173 | }, 174 | "header_require": { 175 | "type": "SEQ", 176 | "members": [ 177 | { 178 | "type": "STRING", 179 | "value": "@require:" 180 | }, 181 | { 182 | "type": "CHOICE", 183 | "members": [ 184 | { 185 | "type": "SYMBOL", 186 | "name": "whitespace" 187 | }, 188 | { 189 | "type": "BLANK" 190 | } 191 | ] 192 | }, 193 | { 194 | "type": "FIELD", 195 | "name": "require", 196 | "content": { 197 | "type": "SYMBOL", 198 | "name": "pkgname" 199 | } 200 | } 201 | ] 202 | }, 203 | "header_import": { 204 | "type": "SEQ", 205 | "members": [ 206 | { 207 | "type": "STRING", 208 | "value": "@import:" 209 | }, 210 | { 211 | "type": "CHOICE", 212 | "members": [ 213 | { 214 | "type": "SYMBOL", 215 | "name": "whitespace" 216 | }, 217 | { 218 | "type": "BLANK" 219 | } 220 | ] 221 | }, 222 | { 223 | "type": "FIELD", 224 | "name": "import", 225 | "content": { 226 | "type": "SYMBOL", 227 | "name": "pkgname" 228 | } 229 | } 230 | ] 231 | }, 232 | "header_stage": { 233 | "type": "SEQ", 234 | "members": [ 235 | { 236 | "type": "STRING", 237 | "value": "@stage:" 238 | }, 239 | { 240 | "type": "CHOICE", 241 | "members": [ 242 | { 243 | "type": "FIELD", 244 | "name": "0", 245 | "content": { 246 | "type": "STRING", 247 | "value": "0" 248 | } 249 | }, 250 | { 251 | "type": "FIELD", 252 | "name": "1", 253 | "content": { 254 | "type": "STRING", 255 | "value": "1" 256 | } 257 | }, 258 | { 259 | "type": "FIELD", 260 | "name": "persistent", 261 | "content": { 262 | "type": "STRING", 263 | "value": "persistent" 264 | } 265 | } 266 | ] 267 | } 268 | ] 269 | }, 270 | "preamble": { 271 | "type": "REPEAT1", 272 | "content": { 273 | "type": "SYMBOL", 274 | "name": "_statement" 275 | } 276 | }, 277 | "_statement": { 278 | "type": "PREC_LEFT", 279 | "value": 0, 280 | "content": { 281 | "type": "CHOICE", 282 | "members": [ 283 | { 284 | "type": "SYMBOL", 285 | "name": "let_stmt" 286 | }, 287 | { 288 | "type": "SYMBOL", 289 | "name": "let_rec_stmt" 290 | }, 291 | { 292 | "type": "SYMBOL", 293 | "name": "let_inline_stmt" 294 | }, 295 | { 296 | "type": "SYMBOL", 297 | "name": "let_block_stmt" 298 | }, 299 | { 300 | "type": "SYMBOL", 301 | "name": "let_math_stmt" 302 | }, 303 | { 304 | "type": "SYMBOL", 305 | "name": "let_mutable_stmt" 306 | }, 307 | { 308 | "type": "SYMBOL", 309 | "name": "type_stmt" 310 | }, 311 | { 312 | "type": "SYMBOL", 313 | "name": "module_stmt" 314 | }, 315 | { 316 | "type": "SYMBOL", 317 | "name": "open_stmt" 318 | } 319 | ] 320 | } 321 | }, 322 | "let_stmt": { 323 | "type": "SEQ", 324 | "members": [ 325 | { 326 | "type": "STRING", 327 | "value": "let" 328 | }, 329 | { 330 | "type": "FIELD", 331 | "name": "pattern", 332 | "content": { 333 | "type": "SYMBOL", 334 | "name": "_pattern" 335 | } 336 | }, 337 | { 338 | "type": "CHOICE", 339 | "members": [ 340 | { 341 | "type": "SYMBOL", 342 | "name": "_let_stmt_argument" 343 | }, 344 | { 345 | "type": "BLANK" 346 | } 347 | ] 348 | }, 349 | { 350 | "type": "STRING", 351 | "value": "=" 352 | }, 353 | { 354 | "type": "FIELD", 355 | "name": "expr", 356 | "content": { 357 | "type": "SYMBOL", 358 | "name": "_expr" 359 | } 360 | } 361 | ] 362 | }, 363 | "_let_stmt_argument": { 364 | "type": "CHOICE", 365 | "members": [ 366 | { 367 | "type": "SEQ", 368 | "members": [ 369 | { 370 | "type": "STRING", 371 | "value": ":" 372 | }, 373 | { 374 | "type": "FIELD", 375 | "name": "signiture", 376 | "content": { 377 | "type": "SYMBOL", 378 | "name": "_type_expr" 379 | } 380 | }, 381 | { 382 | "type": "STRING", 383 | "value": "|" 384 | }, 385 | { 386 | "type": "REPEAT1", 387 | "content": { 388 | "type": "SYMBOL", 389 | "name": "_arg" 390 | } 391 | } 392 | ] 393 | }, 394 | { 395 | "type": "SEQ", 396 | "members": [ 397 | { 398 | "type": "STRING", 399 | "value": ":" 400 | }, 401 | { 402 | "type": "FIELD", 403 | "name": "signiture", 404 | "content": { 405 | "type": "SYMBOL", 406 | "name": "_type_expr" 407 | } 408 | } 409 | ] 410 | }, 411 | { 412 | "type": "SEQ", 413 | "members": [ 414 | { 415 | "type": "CHOICE", 416 | "members": [ 417 | { 418 | "type": "STRING", 419 | "value": "|" 420 | }, 421 | { 422 | "type": "BLANK" 423 | } 424 | ] 425 | }, 426 | { 427 | "type": "REPEAT1", 428 | "content": { 429 | "type": "SYMBOL", 430 | "name": "_arg" 431 | } 432 | } 433 | ] 434 | } 435 | ] 436 | }, 437 | "let_rec_stmt": { 438 | "type": "SEQ", 439 | "members": [ 440 | { 441 | "type": "STRING", 442 | "value": "let-rec" 443 | }, 444 | { 445 | "type": "SEQ", 446 | "members": [ 447 | { 448 | "type": "SYMBOL", 449 | "name": "let_rec_inner" 450 | }, 451 | { 452 | "type": "REPEAT", 453 | "content": { 454 | "type": "SEQ", 455 | "members": [ 456 | { 457 | "type": "STRING", 458 | "value": "and" 459 | }, 460 | { 461 | "type": "SYMBOL", 462 | "name": "let_rec_inner" 463 | } 464 | ] 465 | } 466 | } 467 | ] 468 | } 469 | ] 470 | }, 471 | "let_rec_inner": { 472 | "type": "CHOICE", 473 | "members": [ 474 | { 475 | "type": "SEQ", 476 | "members": [ 477 | { 478 | "type": "FIELD", 479 | "name": "pattern", 480 | "content": { 481 | "type": "SYMBOL", 482 | "name": "_pattern" 483 | } 484 | }, 485 | { 486 | "type": "CHOICE", 487 | "members": [ 488 | { 489 | "type": "SYMBOL", 490 | "name": "_let_rec_stmt_argument" 491 | }, 492 | { 493 | "type": "BLANK" 494 | } 495 | ] 496 | }, 497 | { 498 | "type": "STRING", 499 | "value": "=" 500 | }, 501 | { 502 | "type": "FIELD", 503 | "name": "expr", 504 | "content": { 505 | "type": "SYMBOL", 506 | "name": "_expr" 507 | } 508 | } 509 | ] 510 | }, 511 | { 512 | "type": "SEQ", 513 | "members": [ 514 | { 515 | "type": "FIELD", 516 | "name": "pattern", 517 | "content": { 518 | "type": "SYMBOL", 519 | "name": "_pattern" 520 | } 521 | }, 522 | { 523 | "type": "REPEAT", 524 | "content": { 525 | "type": "SEQ", 526 | "members": [ 527 | { 528 | "type": "STRING", 529 | "value": "|" 530 | }, 531 | { 532 | "type": "FIELD", 533 | "name": "arm", 534 | "content": { 535 | "type": "SYMBOL", 536 | "name": "let_rec_matcharm" 537 | } 538 | } 539 | ] 540 | } 541 | } 542 | ] 543 | } 544 | ] 545 | }, 546 | "_let_rec_stmt_argument": { 547 | "type": "CHOICE", 548 | "members": [ 549 | { 550 | "type": "SEQ", 551 | "members": [ 552 | { 553 | "type": "STRING", 554 | "value": ":" 555 | }, 556 | { 557 | "type": "FIELD", 558 | "name": "signiture", 559 | "content": { 560 | "type": "SYMBOL", 561 | "name": "_type_expr" 562 | } 563 | }, 564 | { 565 | "type": "STRING", 566 | "value": "|" 567 | }, 568 | { 569 | "type": "REPEAT1", 570 | "content": { 571 | "type": "SYMBOL", 572 | "name": "_arg" 573 | } 574 | } 575 | ] 576 | }, 577 | { 578 | "type": "SEQ", 579 | "members": [ 580 | { 581 | "type": "STRING", 582 | "value": ":" 583 | }, 584 | { 585 | "type": "FIELD", 586 | "name": "signiture", 587 | "content": { 588 | "type": "SYMBOL", 589 | "name": "_type_expr" 590 | } 591 | } 592 | ] 593 | }, 594 | { 595 | "type": "REPEAT1", 596 | "content": { 597 | "type": "SYMBOL", 598 | "name": "_arg" 599 | } 600 | } 601 | ] 602 | }, 603 | "let_rec_matcharm": { 604 | "type": "SEQ", 605 | "members": [ 606 | { 607 | "type": "REPEAT", 608 | "content": { 609 | "type": "SYMBOL", 610 | "name": "_arg" 611 | } 612 | }, 613 | { 614 | "type": "STRING", 615 | "value": "=" 616 | }, 617 | { 618 | "type": "FIELD", 619 | "name": "expr", 620 | "content": { 621 | "type": "SYMBOL", 622 | "name": "_expr" 623 | } 624 | } 625 | ] 626 | }, 627 | "let_inline_stmt": { 628 | "type": "CHOICE", 629 | "members": [ 630 | { 631 | "type": "SEQ", 632 | "members": [ 633 | { 634 | "type": "STRING", 635 | "value": "let-inline" 636 | }, 637 | { 638 | "type": "FIELD", 639 | "name": "ctx", 640 | "content": { 641 | "type": "SYMBOL", 642 | "name": "identifier" 643 | } 644 | }, 645 | { 646 | "type": "FIELD", 647 | "name": "name", 648 | "content": { 649 | "type": "SYMBOL", 650 | "name": "inline_cmd_name" 651 | } 652 | }, 653 | { 654 | "type": "REPEAT", 655 | "content": { 656 | "type": "SYMBOL", 657 | "name": "_arg" 658 | } 659 | }, 660 | { 661 | "type": "STRING", 662 | "value": "=" 663 | }, 664 | { 665 | "type": "FIELD", 666 | "name": "expr", 667 | "content": { 668 | "type": "SYMBOL", 669 | "name": "_expr" 670 | } 671 | } 672 | ] 673 | }, 674 | { 675 | "type": "SEQ", 676 | "members": [ 677 | { 678 | "type": "STRING", 679 | "value": "let-inline" 680 | }, 681 | { 682 | "type": "FIELD", 683 | "name": "name", 684 | "content": { 685 | "type": "SYMBOL", 686 | "name": "inline_cmd_name" 687 | } 688 | }, 689 | { 690 | "type": "REPEAT", 691 | "content": { 692 | "type": "FIELD", 693 | "name": "arg", 694 | "content": { 695 | "type": "SYMBOL", 696 | "name": "_pattern" 697 | } 698 | } 699 | }, 700 | { 701 | "type": "STRING", 702 | "value": "=" 703 | }, 704 | { 705 | "type": "FIELD", 706 | "name": "expr", 707 | "content": { 708 | "type": "SYMBOL", 709 | "name": "_expr" 710 | } 711 | } 712 | ] 713 | } 714 | ] 715 | }, 716 | "let_block_stmt": { 717 | "type": "CHOICE", 718 | "members": [ 719 | { 720 | "type": "SEQ", 721 | "members": [ 722 | { 723 | "type": "STRING", 724 | "value": "let-block" 725 | }, 726 | { 727 | "type": "FIELD", 728 | "name": "ctx", 729 | "content": { 730 | "type": "SYMBOL", 731 | "name": "identifier" 732 | } 733 | }, 734 | { 735 | "type": "FIELD", 736 | "name": "name", 737 | "content": { 738 | "type": "SYMBOL", 739 | "name": "block_cmd_name" 740 | } 741 | }, 742 | { 743 | "type": "REPEAT", 744 | "content": { 745 | "type": "SYMBOL", 746 | "name": "_arg" 747 | } 748 | }, 749 | { 750 | "type": "STRING", 751 | "value": "=" 752 | }, 753 | { 754 | "type": "FIELD", 755 | "name": "expr", 756 | "content": { 757 | "type": "SYMBOL", 758 | "name": "_expr" 759 | } 760 | } 761 | ] 762 | }, 763 | { 764 | "type": "SEQ", 765 | "members": [ 766 | { 767 | "type": "STRING", 768 | "value": "let-block" 769 | }, 770 | { 771 | "type": "FIELD", 772 | "name": "name", 773 | "content": { 774 | "type": "SYMBOL", 775 | "name": "block_cmd_name" 776 | } 777 | }, 778 | { 779 | "type": "REPEAT", 780 | "content": { 781 | "type": "FIELD", 782 | "name": "arg", 783 | "content": { 784 | "type": "SYMBOL", 785 | "name": "_pattern" 786 | } 787 | } 788 | }, 789 | { 790 | "type": "STRING", 791 | "value": "=" 792 | }, 793 | { 794 | "type": "FIELD", 795 | "name": "expr", 796 | "content": { 797 | "type": "SYMBOL", 798 | "name": "_expr" 799 | } 800 | } 801 | ] 802 | } 803 | ] 804 | }, 805 | "let_math_stmt": { 806 | "type": "SEQ", 807 | "members": [ 808 | { 809 | "type": "STRING", 810 | "value": "let-math" 811 | }, 812 | { 813 | "type": "FIELD", 814 | "name": "name", 815 | "content": { 816 | "type": "SYMBOL", 817 | "name": "math_cmd_name" 818 | } 819 | }, 820 | { 821 | "type": "REPEAT", 822 | "content": { 823 | "type": "SYMBOL", 824 | "name": "_arg" 825 | } 826 | }, 827 | { 828 | "type": "STRING", 829 | "value": "=" 830 | }, 831 | { 832 | "type": "FIELD", 833 | "name": "expr", 834 | "content": { 835 | "type": "SYMBOL", 836 | "name": "_expr" 837 | } 838 | } 839 | ] 840 | }, 841 | "let_mutable_stmt": { 842 | "type": "SEQ", 843 | "members": [ 844 | { 845 | "type": "STRING", 846 | "value": "let-mutable" 847 | }, 848 | { 849 | "type": "FIELD", 850 | "name": "name", 851 | "content": { 852 | "type": "SYMBOL", 853 | "name": "identifier" 854 | } 855 | }, 856 | { 857 | "type": "STRING", 858 | "value": "<-" 859 | }, 860 | { 861 | "type": "FIELD", 862 | "name": "expr", 863 | "content": { 864 | "type": "SYMBOL", 865 | "name": "_expr" 866 | } 867 | } 868 | ] 869 | }, 870 | "type_stmt": { 871 | "type": "SEQ", 872 | "members": [ 873 | { 874 | "type": "STRING", 875 | "value": "type" 876 | }, 877 | { 878 | "type": "SEQ", 879 | "members": [ 880 | { 881 | "type": "SYMBOL", 882 | "name": "type_inner" 883 | }, 884 | { 885 | "type": "REPEAT", 886 | "content": { 887 | "type": "SEQ", 888 | "members": [ 889 | { 890 | "type": "STRING", 891 | "value": "and" 892 | }, 893 | { 894 | "type": "SYMBOL", 895 | "name": "type_inner" 896 | } 897 | ] 898 | } 899 | } 900 | ] 901 | } 902 | ] 903 | }, 904 | "type_inner": { 905 | "type": "CHOICE", 906 | "members": [ 907 | { 908 | "type": "SEQ", 909 | "members": [ 910 | { 911 | "type": "REPEAT", 912 | "content": { 913 | "type": "FIELD", 914 | "name": "param", 915 | "content": { 916 | "type": "SYMBOL", 917 | "name": "type_param" 918 | } 919 | } 920 | }, 921 | { 922 | "type": "FIELD", 923 | "name": "name", 924 | "content": { 925 | "type": "SYMBOL", 926 | "name": "type_name" 927 | } 928 | }, 929 | { 930 | "type": "STRING", 931 | "value": "=" 932 | }, 933 | { 934 | "type": "REPEAT1", 935 | "content": { 936 | "type": "SEQ", 937 | "members": [ 938 | { 939 | "type": "STRING", 940 | "value": "|" 941 | }, 942 | { 943 | "type": "FIELD", 944 | "name": "variant", 945 | "content": { 946 | "type": "SYMBOL", 947 | "name": "type_variant" 948 | } 949 | } 950 | ] 951 | } 952 | }, 953 | { 954 | "type": "REPEAT", 955 | "content": { 956 | "type": "FIELD", 957 | "name": "constraint", 958 | "content": { 959 | "type": "SYMBOL", 960 | "name": "constraint" 961 | } 962 | } 963 | } 964 | ] 965 | }, 966 | { 967 | "type": "SEQ", 968 | "members": [ 969 | { 970 | "type": "REPEAT", 971 | "content": { 972 | "type": "FIELD", 973 | "name": "param", 974 | "content": { 975 | "type": "SYMBOL", 976 | "name": "type_param" 977 | } 978 | } 979 | }, 980 | { 981 | "type": "FIELD", 982 | "name": "name", 983 | "content": { 984 | "type": "SYMBOL", 985 | "name": "type_name" 986 | } 987 | }, 988 | { 989 | "type": "STRING", 990 | "value": "=" 991 | }, 992 | { 993 | "type": "SEQ", 994 | "members": [ 995 | { 996 | "type": "FIELD", 997 | "name": "variant", 998 | "content": { 999 | "type": "SYMBOL", 1000 | "name": "type_variant" 1001 | } 1002 | }, 1003 | { 1004 | "type": "REPEAT", 1005 | "content": { 1006 | "type": "SEQ", 1007 | "members": [ 1008 | { 1009 | "type": "STRING", 1010 | "value": "|" 1011 | }, 1012 | { 1013 | "type": "FIELD", 1014 | "name": "variant", 1015 | "content": { 1016 | "type": "SYMBOL", 1017 | "name": "type_variant" 1018 | } 1019 | } 1020 | ] 1021 | } 1022 | } 1023 | ] 1024 | }, 1025 | { 1026 | "type": "REPEAT", 1027 | "content": { 1028 | "type": "FIELD", 1029 | "name": "constraint", 1030 | "content": { 1031 | "type": "SYMBOL", 1032 | "name": "constraint" 1033 | } 1034 | } 1035 | } 1036 | ] 1037 | }, 1038 | { 1039 | "type": "SEQ", 1040 | "members": [ 1041 | { 1042 | "type": "REPEAT", 1043 | "content": { 1044 | "type": "FIELD", 1045 | "name": "param", 1046 | "content": { 1047 | "type": "SYMBOL", 1048 | "name": "type_param" 1049 | } 1050 | } 1051 | }, 1052 | { 1053 | "type": "FIELD", 1054 | "name": "name", 1055 | "content": { 1056 | "type": "SYMBOL", 1057 | "name": "type_name" 1058 | } 1059 | }, 1060 | { 1061 | "type": "STRING", 1062 | "value": "=" 1063 | }, 1064 | { 1065 | "type": "FIELD", 1066 | "name": "expr", 1067 | "content": { 1068 | "type": "SYMBOL", 1069 | "name": "_type_expr" 1070 | } 1071 | }, 1072 | { 1073 | "type": "REPEAT", 1074 | "content": { 1075 | "type": "FIELD", 1076 | "name": "constraint", 1077 | "content": { 1078 | "type": "SYMBOL", 1079 | "name": "constraint" 1080 | } 1081 | } 1082 | } 1083 | ] 1084 | } 1085 | ] 1086 | }, 1087 | "type_variant": { 1088 | "type": "SEQ", 1089 | "members": [ 1090 | { 1091 | "type": "FIELD", 1092 | "name": "name", 1093 | "content": { 1094 | "type": "SYMBOL", 1095 | "name": "variant_name" 1096 | } 1097 | }, 1098 | { 1099 | "type": "CHOICE", 1100 | "members": [ 1101 | { 1102 | "type": "SEQ", 1103 | "members": [ 1104 | { 1105 | "type": "STRING", 1106 | "value": "of" 1107 | }, 1108 | { 1109 | "type": "FIELD", 1110 | "name": "expr", 1111 | "content": { 1112 | "type": "SYMBOL", 1113 | "name": "_type_expr" 1114 | } 1115 | } 1116 | ] 1117 | }, 1118 | { 1119 | "type": "BLANK" 1120 | } 1121 | ] 1122 | } 1123 | ] 1124 | }, 1125 | "open_stmt": { 1126 | "type": "SEQ", 1127 | "members": [ 1128 | { 1129 | "type": "STRING", 1130 | "value": "open" 1131 | }, 1132 | { 1133 | "type": "SYMBOL", 1134 | "name": "module_name" 1135 | } 1136 | ] 1137 | }, 1138 | "_arg": { 1139 | "type": "CHOICE", 1140 | "members": [ 1141 | { 1142 | "type": "FIELD", 1143 | "name": "arg", 1144 | "content": { 1145 | "type": "SYMBOL", 1146 | "name": "_pattern" 1147 | } 1148 | }, 1149 | { 1150 | "type": "SEQ", 1151 | "members": [ 1152 | { 1153 | "type": "STRING", 1154 | "value": "?:" 1155 | }, 1156 | { 1157 | "type": "FIELD", 1158 | "name": "optarg", 1159 | "content": { 1160 | "type": "SYMBOL", 1161 | "name": "_pattern" 1162 | } 1163 | } 1164 | ] 1165 | } 1166 | ] 1167 | }, 1168 | "module_stmt": { 1169 | "type": "SEQ", 1170 | "members": [ 1171 | { 1172 | "type": "STRING", 1173 | "value": "module" 1174 | }, 1175 | { 1176 | "type": "FIELD", 1177 | "name": "name", 1178 | "content": { 1179 | "type": "SYMBOL", 1180 | "name": "module_name" 1181 | } 1182 | }, 1183 | { 1184 | "type": "STRING", 1185 | "value": ":" 1186 | }, 1187 | { 1188 | "type": "FIELD", 1189 | "name": "sig", 1190 | "content": { 1191 | "type": "SYMBOL", 1192 | "name": "sig_stmt" 1193 | } 1194 | }, 1195 | { 1196 | "type": "STRING", 1197 | "value": "=" 1198 | }, 1199 | { 1200 | "type": "FIELD", 1201 | "name": "struct", 1202 | "content": { 1203 | "type": "SYMBOL", 1204 | "name": "struct_stmt" 1205 | } 1206 | } 1207 | ] 1208 | }, 1209 | "sig_stmt": { 1210 | "type": "SEQ", 1211 | "members": [ 1212 | { 1213 | "type": "STRING", 1214 | "value": "sig" 1215 | }, 1216 | { 1217 | "type": "REPEAT", 1218 | "content": { 1219 | "type": "SYMBOL", 1220 | "name": "_sig_inner" 1221 | } 1222 | }, 1223 | { 1224 | "type": "STRING", 1225 | "value": "end" 1226 | } 1227 | ] 1228 | }, 1229 | "struct_stmt": { 1230 | "type": "SEQ", 1231 | "members": [ 1232 | { 1233 | "type": "STRING", 1234 | "value": "struct" 1235 | }, 1236 | { 1237 | "type": "REPEAT", 1238 | "content": { 1239 | "type": "SYMBOL", 1240 | "name": "_statement" 1241 | } 1242 | }, 1243 | { 1244 | "type": "STRING", 1245 | "value": "end" 1246 | } 1247 | ] 1248 | }, 1249 | "_sig_inner": { 1250 | "type": "CHOICE", 1251 | "members": [ 1252 | { 1253 | "type": "SYMBOL", 1254 | "name": "sig_type_stmt" 1255 | }, 1256 | { 1257 | "type": "SYMBOL", 1258 | "name": "sig_val_stmt" 1259 | }, 1260 | { 1261 | "type": "SYMBOL", 1262 | "name": "sig_direct_stmt" 1263 | } 1264 | ] 1265 | }, 1266 | "sig_type_stmt": { 1267 | "type": "SEQ", 1268 | "members": [ 1269 | { 1270 | "type": "STRING", 1271 | "value": "type" 1272 | }, 1273 | { 1274 | "type": "REPEAT", 1275 | "content": { 1276 | "type": "FIELD", 1277 | "name": "param", 1278 | "content": { 1279 | "type": "SYMBOL", 1280 | "name": "type_param" 1281 | } 1282 | } 1283 | }, 1284 | { 1285 | "type": "FIELD", 1286 | "name": "name", 1287 | "content": { 1288 | "type": "SYMBOL", 1289 | "name": "identifier" 1290 | } 1291 | }, 1292 | { 1293 | "type": "REPEAT", 1294 | "content": { 1295 | "type": "FIELD", 1296 | "name": "constraint", 1297 | "content": { 1298 | "type": "SYMBOL", 1299 | "name": "constraint" 1300 | } 1301 | } 1302 | } 1303 | ] 1304 | }, 1305 | "sig_val_stmt": { 1306 | "type": "SEQ", 1307 | "members": [ 1308 | { 1309 | "type": "STRING", 1310 | "value": "val" 1311 | }, 1312 | { 1313 | "type": "CHOICE", 1314 | "members": [ 1315 | { 1316 | "type": "FIELD", 1317 | "name": "name", 1318 | "content": { 1319 | "type": "SYMBOL", 1320 | "name": "identifier" 1321 | } 1322 | }, 1323 | { 1324 | "type": "SEQ", 1325 | "members": [ 1326 | { 1327 | "type": "STRING", 1328 | "value": "(" 1329 | }, 1330 | { 1331 | "type": "FIELD", 1332 | "name": "name", 1333 | "content": { 1334 | "type": "SYMBOL", 1335 | "name": "binary_operator" 1336 | } 1337 | }, 1338 | { 1339 | "type": "STRING", 1340 | "value": ")" 1341 | } 1342 | ] 1343 | }, 1344 | { 1345 | "type": "FIELD", 1346 | "name": "name", 1347 | "content": { 1348 | "type": "SYMBOL", 1349 | "name": "inline_cmd_name" 1350 | } 1351 | }, 1352 | { 1353 | "type": "FIELD", 1354 | "name": "name", 1355 | "content": { 1356 | "type": "SYMBOL", 1357 | "name": "block_cmd_name" 1358 | } 1359 | } 1360 | ] 1361 | }, 1362 | { 1363 | "type": "STRING", 1364 | "value": ":" 1365 | }, 1366 | { 1367 | "type": "FIELD", 1368 | "name": "signature", 1369 | "content": { 1370 | "type": "SYMBOL", 1371 | "name": "_type_expr" 1372 | } 1373 | }, 1374 | { 1375 | "type": "REPEAT", 1376 | "content": { 1377 | "type": "FIELD", 1378 | "name": "constraint", 1379 | "content": { 1380 | "type": "SYMBOL", 1381 | "name": "constraint" 1382 | } 1383 | } 1384 | } 1385 | ] 1386 | }, 1387 | "sig_direct_stmt": { 1388 | "type": "SEQ", 1389 | "members": [ 1390 | { 1391 | "type": "STRING", 1392 | "value": "direct" 1393 | }, 1394 | { 1395 | "type": "CHOICE", 1396 | "members": [ 1397 | { 1398 | "type": "FIELD", 1399 | "name": "name", 1400 | "content": { 1401 | "type": "SYMBOL", 1402 | "name": "inline_cmd_name" 1403 | } 1404 | }, 1405 | { 1406 | "type": "FIELD", 1407 | "name": "name", 1408 | "content": { 1409 | "type": "SYMBOL", 1410 | "name": "block_cmd_name" 1411 | } 1412 | } 1413 | ] 1414 | }, 1415 | { 1416 | "type": "STRING", 1417 | "value": ":" 1418 | }, 1419 | { 1420 | "type": "FIELD", 1421 | "name": "signature", 1422 | "content": { 1423 | "type": "SYMBOL", 1424 | "name": "_type_expr" 1425 | } 1426 | }, 1427 | { 1428 | "type": "REPEAT", 1429 | "content": { 1430 | "type": "FIELD", 1431 | "name": "constraint", 1432 | "content": { 1433 | "type": "SYMBOL", 1434 | "name": "constraint" 1435 | } 1436 | } 1437 | } 1438 | ] 1439 | }, 1440 | "_type_expr": { 1441 | "type": "CHOICE", 1442 | "members": [ 1443 | { 1444 | "type": "SYMBOL", 1445 | "name": "type_fun" 1446 | }, 1447 | { 1448 | "type": "SYMBOL", 1449 | "name": "type_prod" 1450 | }, 1451 | { 1452 | "type": "SYMBOL", 1453 | "name": "type_inline_cmd" 1454 | }, 1455 | { 1456 | "type": "SYMBOL", 1457 | "name": "type_block_cmd" 1458 | }, 1459 | { 1460 | "type": "SYMBOL", 1461 | "name": "type_math_cmd" 1462 | }, 1463 | { 1464 | "type": "SYMBOL", 1465 | "name": "type_application" 1466 | }, 1467 | { 1468 | "type": "SYMBOL", 1469 | "name": "type_record" 1470 | }, 1471 | { 1472 | "type": "SYMBOL", 1473 | "name": "type_param" 1474 | }, 1475 | { 1476 | "type": "SYMBOL", 1477 | "name": "type_name" 1478 | }, 1479 | { 1480 | "type": "SEQ", 1481 | "members": [ 1482 | { 1483 | "type": "STRING", 1484 | "value": "(" 1485 | }, 1486 | { 1487 | "type": "SYMBOL", 1488 | "name": "_type_expr" 1489 | }, 1490 | { 1491 | "type": "STRING", 1492 | "value": ")" 1493 | } 1494 | ] 1495 | } 1496 | ] 1497 | }, 1498 | "type_fun": { 1499 | "type": "PREC_RIGHT", 1500 | "value": 0, 1501 | "content": { 1502 | "type": "SEQ", 1503 | "members": [ 1504 | { 1505 | "type": "CHOICE", 1506 | "members": [ 1507 | { 1508 | "type": "SEQ", 1509 | "members": [ 1510 | { 1511 | "type": "FIELD", 1512 | "name": "optarg", 1513 | "content": { 1514 | "type": "SYMBOL", 1515 | "name": "_type_expr" 1516 | } 1517 | }, 1518 | { 1519 | "type": "STRING", 1520 | "value": "?->" 1521 | } 1522 | ] 1523 | }, 1524 | { 1525 | "type": "SEQ", 1526 | "members": [ 1527 | { 1528 | "type": "FIELD", 1529 | "name": "arg", 1530 | "content": { 1531 | "type": "SYMBOL", 1532 | "name": "_type_expr" 1533 | } 1534 | }, 1535 | { 1536 | "type": "STRING", 1537 | "value": "->" 1538 | } 1539 | ] 1540 | } 1541 | ] 1542 | }, 1543 | { 1544 | "type": "FIELD", 1545 | "name": "return", 1546 | "content": { 1547 | "type": "SYMBOL", 1548 | "name": "_type_expr" 1549 | } 1550 | } 1551 | ] 1552 | } 1553 | }, 1554 | "type_prod": { 1555 | "type": "PREC_LEFT", 1556 | "value": 1, 1557 | "content": { 1558 | "type": "SEQ", 1559 | "members": [ 1560 | { 1561 | "type": "SYMBOL", 1562 | "name": "_type_expr" 1563 | }, 1564 | { 1565 | "type": "STRING", 1566 | "value": "*" 1567 | }, 1568 | { 1569 | "type": "SYMBOL", 1570 | "name": "_type_expr" 1571 | } 1572 | ] 1573 | } 1574 | }, 1575 | "type_inline_cmd": { 1576 | "type": "SEQ", 1577 | "members": [ 1578 | { 1579 | "type": "SYMBOL", 1580 | "name": "type_list" 1581 | }, 1582 | { 1583 | "type": "STRING", 1584 | "value": "inline-cmd" 1585 | } 1586 | ] 1587 | }, 1588 | "type_block_cmd": { 1589 | "type": "SEQ", 1590 | "members": [ 1591 | { 1592 | "type": "SYMBOL", 1593 | "name": "type_list" 1594 | }, 1595 | { 1596 | "type": "STRING", 1597 | "value": "block-cmd" 1598 | } 1599 | ] 1600 | }, 1601 | "type_math_cmd": { 1602 | "type": "SEQ", 1603 | "members": [ 1604 | { 1605 | "type": "SYMBOL", 1606 | "name": "type_list" 1607 | }, 1608 | { 1609 | "type": "STRING", 1610 | "value": "math-cmd" 1611 | } 1612 | ] 1613 | }, 1614 | "type_list": { 1615 | "type": "SEQ", 1616 | "members": [ 1617 | { 1618 | "type": "STRING", 1619 | "value": "[" 1620 | }, 1621 | { 1622 | "type": "CHOICE", 1623 | "members": [ 1624 | { 1625 | "type": "SEQ", 1626 | "members": [ 1627 | { 1628 | "type": "CHOICE", 1629 | "members": [ 1630 | { 1631 | "type": "SEQ", 1632 | "members": [ 1633 | { 1634 | "type": "FIELD", 1635 | "name": "optarg", 1636 | "content": { 1637 | "type": "SYMBOL", 1638 | "name": "_type_expr" 1639 | } 1640 | }, 1641 | { 1642 | "type": "STRING", 1643 | "value": "?" 1644 | } 1645 | ] 1646 | }, 1647 | { 1648 | "type": "SEQ", 1649 | "members": [ 1650 | { 1651 | "type": "FIELD", 1652 | "name": "arg", 1653 | "content": { 1654 | "type": "SYMBOL", 1655 | "name": "_type_expr" 1656 | } 1657 | } 1658 | ] 1659 | } 1660 | ] 1661 | }, 1662 | { 1663 | "type": "REPEAT", 1664 | "content": { 1665 | "type": "SEQ", 1666 | "members": [ 1667 | { 1668 | "type": "STRING", 1669 | "value": ";" 1670 | }, 1671 | { 1672 | "type": "CHOICE", 1673 | "members": [ 1674 | { 1675 | "type": "SEQ", 1676 | "members": [ 1677 | { 1678 | "type": "FIELD", 1679 | "name": "optarg", 1680 | "content": { 1681 | "type": "SYMBOL", 1682 | "name": "_type_expr" 1683 | } 1684 | }, 1685 | { 1686 | "type": "STRING", 1687 | "value": "?" 1688 | } 1689 | ] 1690 | }, 1691 | { 1692 | "type": "SEQ", 1693 | "members": [ 1694 | { 1695 | "type": "FIELD", 1696 | "name": "arg", 1697 | "content": { 1698 | "type": "SYMBOL", 1699 | "name": "_type_expr" 1700 | } 1701 | } 1702 | ] 1703 | } 1704 | ] 1705 | } 1706 | ] 1707 | } 1708 | } 1709 | ] 1710 | }, 1711 | { 1712 | "type": "BLANK" 1713 | } 1714 | ] 1715 | }, 1716 | { 1717 | "type": "CHOICE", 1718 | "members": [ 1719 | { 1720 | "type": "STRING", 1721 | "value": ";" 1722 | }, 1723 | { 1724 | "type": "BLANK" 1725 | } 1726 | ] 1727 | }, 1728 | { 1729 | "type": "STRING", 1730 | "value": "]" 1731 | } 1732 | ] 1733 | }, 1734 | "type_record": { 1735 | "type": "SEQ", 1736 | "members": [ 1737 | { 1738 | "type": "STRING", 1739 | "value": "(|" 1740 | }, 1741 | { 1742 | "type": "CHOICE", 1743 | "members": [ 1744 | { 1745 | "type": "SEQ", 1746 | "members": [ 1747 | { 1748 | "type": "SYMBOL", 1749 | "name": "type_record_unit" 1750 | }, 1751 | { 1752 | "type": "REPEAT", 1753 | "content": { 1754 | "type": "SEQ", 1755 | "members": [ 1756 | { 1757 | "type": "STRING", 1758 | "value": ";" 1759 | }, 1760 | { 1761 | "type": "SYMBOL", 1762 | "name": "type_record_unit" 1763 | } 1764 | ] 1765 | } 1766 | } 1767 | ] 1768 | }, 1769 | { 1770 | "type": "BLANK" 1771 | } 1772 | ] 1773 | }, 1774 | { 1775 | "type": "CHOICE", 1776 | "members": [ 1777 | { 1778 | "type": "STRING", 1779 | "value": ";" 1780 | }, 1781 | { 1782 | "type": "BLANK" 1783 | } 1784 | ] 1785 | }, 1786 | { 1787 | "type": "STRING", 1788 | "value": "|)" 1789 | } 1790 | ] 1791 | }, 1792 | "type_record_unit": { 1793 | "type": "SEQ", 1794 | "members": [ 1795 | { 1796 | "type": "SYMBOL", 1797 | "name": "identifier" 1798 | }, 1799 | { 1800 | "type": "STRING", 1801 | "value": ":" 1802 | }, 1803 | { 1804 | "type": "SYMBOL", 1805 | "name": "_type_expr" 1806 | } 1807 | ] 1808 | }, 1809 | "type_application": { 1810 | "type": "PREC_LEFT", 1811 | "value": 2, 1812 | "content": { 1813 | "type": "SEQ", 1814 | "members": [ 1815 | { 1816 | "type": "SYMBOL", 1817 | "name": "_type_expr" 1818 | }, 1819 | { 1820 | "type": "SYMBOL", 1821 | "name": "_type_expr" 1822 | } 1823 | ] 1824 | } 1825 | }, 1826 | "type_param": { 1827 | "type": "IMMEDIATE_TOKEN", 1828 | "content": { 1829 | "type": "SEQ", 1830 | "members": [ 1831 | { 1832 | "type": "STRING", 1833 | "value": "'" 1834 | }, 1835 | { 1836 | "type": "PATTERN", 1837 | "value": "[a-z][-A-Za-z0-9]*" 1838 | } 1839 | ] 1840 | } 1841 | }, 1842 | "type_name": { 1843 | "type": "CHOICE", 1844 | "members": [ 1845 | { 1846 | "type": "SYMBOL", 1847 | "name": "identifier" 1848 | }, 1849 | { 1850 | "type": "SYMBOL", 1851 | "name": "modvar" 1852 | } 1853 | ] 1854 | }, 1855 | "constraint": { 1856 | "type": "SEQ", 1857 | "members": [ 1858 | { 1859 | "type": "STRING", 1860 | "value": "constraint" 1861 | }, 1862 | { 1863 | "type": "SYMBOL", 1864 | "name": "type_param" 1865 | }, 1866 | { 1867 | "type": "STRING", 1868 | "value": "::" 1869 | }, 1870 | { 1871 | "type": "SYMBOL", 1872 | "name": "type_record" 1873 | } 1874 | ] 1875 | }, 1876 | "pat_as": { 1877 | "type": "PREC_LEFT", 1878 | "value": 0, 1879 | "content": { 1880 | "type": "SEQ", 1881 | "members": [ 1882 | { 1883 | "type": "SYMBOL", 1884 | "name": "_pat_cons" 1885 | }, 1886 | { 1887 | "type": "CHOICE", 1888 | "members": [ 1889 | { 1890 | "type": "SEQ", 1891 | "members": [ 1892 | { 1893 | "type": "STRING", 1894 | "value": "as" 1895 | }, 1896 | { 1897 | "type": "SYMBOL", 1898 | "name": "identifier" 1899 | } 1900 | ] 1901 | }, 1902 | { 1903 | "type": "BLANK" 1904 | } 1905 | ] 1906 | } 1907 | ] 1908 | } 1909 | }, 1910 | "_pat_cons": { 1911 | "type": "CHOICE", 1912 | "members": [ 1913 | { 1914 | "type": "SEQ", 1915 | "members": [ 1916 | { 1917 | "type": "SYMBOL", 1918 | "name": "_pattern" 1919 | }, 1920 | { 1921 | "type": "STRING", 1922 | "value": "::" 1923 | }, 1924 | { 1925 | "type": "SYMBOL", 1926 | "name": "pat_as" 1927 | } 1928 | ] 1929 | }, 1930 | { 1931 | "type": "SYMBOL", 1932 | "name": "pat_variant" 1933 | }, 1934 | { 1935 | "type": "SYMBOL", 1936 | "name": "_pattern" 1937 | } 1938 | ] 1939 | }, 1940 | "_pattern": { 1941 | "type": "CHOICE", 1942 | "members": [ 1943 | { 1944 | "type": "SYMBOL", 1945 | "name": "pat_list" 1946 | }, 1947 | { 1948 | "type": "SEQ", 1949 | "members": [ 1950 | { 1951 | "type": "STRING", 1952 | "value": "(" 1953 | }, 1954 | { 1955 | "type": "SYMBOL", 1956 | "name": "binary_operator" 1957 | }, 1958 | { 1959 | "type": "STRING", 1960 | "value": ")" 1961 | } 1962 | ] 1963 | }, 1964 | { 1965 | "type": "SEQ", 1966 | "members": [ 1967 | { 1968 | "type": "STRING", 1969 | "value": "(" 1970 | }, 1971 | { 1972 | "type": "SYMBOL", 1973 | "name": "unary_operator" 1974 | }, 1975 | { 1976 | "type": "STRING", 1977 | "value": ")" 1978 | } 1979 | ] 1980 | }, 1981 | { 1982 | "type": "SEQ", 1983 | "members": [ 1984 | { 1985 | "type": "STRING", 1986 | "value": "(" 1987 | }, 1988 | { 1989 | "type": "SYMBOL", 1990 | "name": "pat_as" 1991 | }, 1992 | { 1993 | "type": "STRING", 1994 | "value": ")" 1995 | } 1996 | ] 1997 | }, 1998 | { 1999 | "type": "SYMBOL", 2000 | "name": "pat_tuple" 2001 | }, 2002 | { 2003 | "type": "STRING", 2004 | "value": "_" 2005 | }, 2006 | { 2007 | "type": "SYMBOL", 2008 | "name": "identifier" 2009 | }, 2010 | { 2011 | "type": "SYMBOL", 2012 | "name": "_literal" 2013 | } 2014 | ] 2015 | }, 2016 | "pat_variant": { 2017 | "type": "SEQ", 2018 | "members": [ 2019 | { 2020 | "type": "SYMBOL", 2021 | "name": "variant_name" 2022 | }, 2023 | { 2024 | "type": "CHOICE", 2025 | "members": [ 2026 | { 2027 | "type": "SYMBOL", 2028 | "name": "_pattern" 2029 | }, 2030 | { 2031 | "type": "BLANK" 2032 | } 2033 | ] 2034 | } 2035 | ] 2036 | }, 2037 | "pat_list": { 2038 | "type": "SEQ", 2039 | "members": [ 2040 | { 2041 | "type": "STRING", 2042 | "value": "[" 2043 | }, 2044 | { 2045 | "type": "CHOICE", 2046 | "members": [ 2047 | { 2048 | "type": "SEQ", 2049 | "members": [ 2050 | { 2051 | "type": "SYMBOL", 2052 | "name": "pat_as" 2053 | }, 2054 | { 2055 | "type": "REPEAT", 2056 | "content": { 2057 | "type": "SEQ", 2058 | "members": [ 2059 | { 2060 | "type": "STRING", 2061 | "value": ";" 2062 | }, 2063 | { 2064 | "type": "SYMBOL", 2065 | "name": "pat_as" 2066 | } 2067 | ] 2068 | } 2069 | } 2070 | ] 2071 | }, 2072 | { 2073 | "type": "BLANK" 2074 | } 2075 | ] 2076 | }, 2077 | { 2078 | "type": "CHOICE", 2079 | "members": [ 2080 | { 2081 | "type": "STRING", 2082 | "value": ";" 2083 | }, 2084 | { 2085 | "type": "BLANK" 2086 | } 2087 | ] 2088 | }, 2089 | { 2090 | "type": "STRING", 2091 | "value": "]" 2092 | } 2093 | ] 2094 | }, 2095 | "pat_tuple": { 2096 | "type": "SEQ", 2097 | "members": [ 2098 | { 2099 | "type": "STRING", 2100 | "value": "(" 2101 | }, 2102 | { 2103 | "type": "SEQ", 2104 | "members": [ 2105 | { 2106 | "type": "SYMBOL", 2107 | "name": "pat_as" 2108 | }, 2109 | { 2110 | "type": "REPEAT1", 2111 | "content": { 2112 | "type": "SEQ", 2113 | "members": [ 2114 | { 2115 | "type": "STRING", 2116 | "value": "," 2117 | }, 2118 | { 2119 | "type": "SYMBOL", 2120 | "name": "pat_as" 2121 | } 2122 | ] 2123 | } 2124 | } 2125 | ] 2126 | }, 2127 | { 2128 | "type": "STRING", 2129 | "value": ")" 2130 | } 2131 | ] 2132 | }, 2133 | "_expr": { 2134 | "type": "CHOICE", 2135 | "members": [ 2136 | { 2137 | "type": "SYMBOL", 2138 | "name": "match_expr" 2139 | }, 2140 | { 2141 | "type": "SYMBOL", 2142 | "name": "bind_stmt" 2143 | }, 2144 | { 2145 | "type": "SYMBOL", 2146 | "name": "ctrl_while" 2147 | }, 2148 | { 2149 | "type": "SYMBOL", 2150 | "name": "ctrl_if" 2151 | }, 2152 | { 2153 | "type": "SYMBOL", 2154 | "name": "lambda" 2155 | }, 2156 | { 2157 | "type": "SYMBOL", 2158 | "name": "assignment" 2159 | }, 2160 | { 2161 | "type": "SYMBOL", 2162 | "name": "binary_expr" 2163 | }, 2164 | { 2165 | "type": "SYMBOL", 2166 | "name": "application" 2167 | }, 2168 | { 2169 | "type": "SYMBOL", 2170 | "name": "unary_operator_expr" 2171 | }, 2172 | { 2173 | "type": "SYMBOL", 2174 | "name": "command_application" 2175 | }, 2176 | { 2177 | "type": "SYMBOL", 2178 | "name": "variant_constructor" 2179 | }, 2180 | { 2181 | "type": "SYMBOL", 2182 | "name": "record_member" 2183 | }, 2184 | { 2185 | "type": "SYMBOL", 2186 | "name": "_unary" 2187 | } 2188 | ] 2189 | }, 2190 | "match_expr": { 2191 | "type": "PREC_LEFT", 2192 | "value": 1, 2193 | "content": { 2194 | "type": "SEQ", 2195 | "members": [ 2196 | { 2197 | "type": "STRING", 2198 | "value": "match" 2199 | }, 2200 | { 2201 | "type": "FIELD", 2202 | "name": "expr", 2203 | "content": { 2204 | "type": "SYMBOL", 2205 | "name": "_expr" 2206 | } 2207 | }, 2208 | { 2209 | "type": "STRING", 2210 | "value": "with" 2211 | }, 2212 | { 2213 | "type": "CHOICE", 2214 | "members": [ 2215 | { 2216 | "type": "STRING", 2217 | "value": "|" 2218 | }, 2219 | { 2220 | "type": "BLANK" 2221 | } 2222 | ] 2223 | }, 2224 | { 2225 | "type": "SEQ", 2226 | "members": [ 2227 | { 2228 | "type": "SYMBOL", 2229 | "name": "match_arm" 2230 | }, 2231 | { 2232 | "type": "REPEAT", 2233 | "content": { 2234 | "type": "SEQ", 2235 | "members": [ 2236 | { 2237 | "type": "STRING", 2238 | "value": "|" 2239 | }, 2240 | { 2241 | "type": "SYMBOL", 2242 | "name": "match_arm" 2243 | } 2244 | ] 2245 | } 2246 | } 2247 | ] 2248 | } 2249 | ] 2250 | } 2251 | }, 2252 | "match_arm": { 2253 | "type": "SEQ", 2254 | "members": [ 2255 | { 2256 | "type": "FIELD", 2257 | "name": "pattern", 2258 | "content": { 2259 | "type": "SYMBOL", 2260 | "name": "pat_as" 2261 | } 2262 | }, 2263 | { 2264 | "type": "CHOICE", 2265 | "members": [ 2266 | { 2267 | "type": "FIELD", 2268 | "name": "guard", 2269 | "content": { 2270 | "type": "SYMBOL", 2271 | "name": "match_guard" 2272 | } 2273 | }, 2274 | { 2275 | "type": "BLANK" 2276 | } 2277 | ] 2278 | }, 2279 | { 2280 | "type": "STRING", 2281 | "value": "->" 2282 | }, 2283 | { 2284 | "type": "FIELD", 2285 | "name": "expr", 2286 | "content": { 2287 | "type": "SYMBOL", 2288 | "name": "_expr" 2289 | } 2290 | } 2291 | ] 2292 | }, 2293 | "match_guard": { 2294 | "type": "SEQ", 2295 | "members": [ 2296 | { 2297 | "type": "STRING", 2298 | "value": "when" 2299 | }, 2300 | { 2301 | "type": "SYMBOL", 2302 | "name": "_expr" 2303 | } 2304 | ] 2305 | }, 2306 | "bind_stmt": { 2307 | "type": "SEQ", 2308 | "members": [ 2309 | { 2310 | "type": "CHOICE", 2311 | "members": [ 2312 | { 2313 | "type": "SYMBOL", 2314 | "name": "let_stmt" 2315 | }, 2316 | { 2317 | "type": "SYMBOL", 2318 | "name": "let_rec_stmt" 2319 | }, 2320 | { 2321 | "type": "SYMBOL", 2322 | "name": "let_math_stmt" 2323 | }, 2324 | { 2325 | "type": "SYMBOL", 2326 | "name": "let_mutable_stmt" 2327 | }, 2328 | { 2329 | "type": "SYMBOL", 2330 | "name": "open_stmt" 2331 | } 2332 | ] 2333 | }, 2334 | { 2335 | "type": "STRING", 2336 | "value": "in" 2337 | }, 2338 | { 2339 | "type": "FIELD", 2340 | "name": "expr", 2341 | "content": { 2342 | "type": "SYMBOL", 2343 | "name": "_expr" 2344 | } 2345 | } 2346 | ] 2347 | }, 2348 | "ctrl_while": { 2349 | "type": "SEQ", 2350 | "members": [ 2351 | { 2352 | "type": "STRING", 2353 | "value": "while" 2354 | }, 2355 | { 2356 | "type": "SYMBOL", 2357 | "name": "_expr" 2358 | }, 2359 | { 2360 | "type": "STRING", 2361 | "value": "do" 2362 | }, 2363 | { 2364 | "type": "SYMBOL", 2365 | "name": "_expr" 2366 | } 2367 | ] 2368 | }, 2369 | "ctrl_if": { 2370 | "type": "SEQ", 2371 | "members": [ 2372 | { 2373 | "type": "STRING", 2374 | "value": "if" 2375 | }, 2376 | { 2377 | "type": "FIELD", 2378 | "name": "cond", 2379 | "content": { 2380 | "type": "SYMBOL", 2381 | "name": "_expr" 2382 | } 2383 | }, 2384 | { 2385 | "type": "STRING", 2386 | "value": "then" 2387 | }, 2388 | { 2389 | "type": "FIELD", 2390 | "name": "true_clause", 2391 | "content": { 2392 | "type": "SYMBOL", 2393 | "name": "_expr" 2394 | } 2395 | }, 2396 | { 2397 | "type": "STRING", 2398 | "value": "else" 2399 | }, 2400 | { 2401 | "type": "FIELD", 2402 | "name": "false_clause", 2403 | "content": { 2404 | "type": "SYMBOL", 2405 | "name": "_expr" 2406 | } 2407 | } 2408 | ] 2409 | }, 2410 | "lambda": { 2411 | "type": "PREC_RIGHT", 2412 | "value": 3, 2413 | "content": { 2414 | "type": "SEQ", 2415 | "members": [ 2416 | { 2417 | "type": "STRING", 2418 | "value": "fun" 2419 | }, 2420 | { 2421 | "type": "REPEAT1", 2422 | "content": { 2423 | "type": "FIELD", 2424 | "name": "arg", 2425 | "content": { 2426 | "type": "SYMBOL", 2427 | "name": "_pattern" 2428 | } 2429 | } 2430 | }, 2431 | { 2432 | "type": "STRING", 2433 | "value": "->" 2434 | }, 2435 | { 2436 | "type": "SYMBOL", 2437 | "name": "_expr" 2438 | } 2439 | ] 2440 | } 2441 | }, 2442 | "assignment": { 2443 | "type": "PREC_RIGHT", 2444 | "value": 3, 2445 | "content": { 2446 | "type": "SEQ", 2447 | "members": [ 2448 | { 2449 | "type": "SYMBOL", 2450 | "name": "identifier" 2451 | }, 2452 | { 2453 | "type": "STRING", 2454 | "value": "<-" 2455 | }, 2456 | { 2457 | "type": "SYMBOL", 2458 | "name": "_expr" 2459 | } 2460 | ] 2461 | } 2462 | }, 2463 | "binary_expr": { 2464 | "type": "CHOICE", 2465 | "members": [ 2466 | { 2467 | "type": "PREC_LEFT", 2468 | "value": 5, 2469 | "content": { 2470 | "type": "SEQ", 2471 | "members": [ 2472 | { 2473 | "type": "FIELD", 2474 | "name": "left", 2475 | "content": { 2476 | "type": "SYMBOL", 2477 | "name": "_expr" 2478 | } 2479 | }, 2480 | { 2481 | "type": "FIELD", 2482 | "name": "operator", 2483 | "content": { 2484 | "type": "ALIAS", 2485 | "content": { 2486 | "type": "PATTERN", 2487 | "value": "&[-+*/^&|=<>!:~'.?]+" 2488 | }, 2489 | "named": true, 2490 | "value": "binary_operator" 2491 | } 2492 | }, 2493 | { 2494 | "type": "FIELD", 2495 | "name": "right", 2496 | "content": { 2497 | "type": "SYMBOL", 2498 | "name": "_expr" 2499 | } 2500 | } 2501 | ] 2502 | } 2503 | }, 2504 | { 2505 | "type": "PREC_LEFT", 2506 | "value": 4, 2507 | "content": { 2508 | "type": "SEQ", 2509 | "members": [ 2510 | { 2511 | "type": "FIELD", 2512 | "name": "left", 2513 | "content": { 2514 | "type": "SYMBOL", 2515 | "name": "_expr" 2516 | } 2517 | }, 2518 | { 2519 | "type": "FIELD", 2520 | "name": "operator", 2521 | "content": { 2522 | "type": "ALIAS", 2523 | "content": { 2524 | "type": "PATTERN", 2525 | "value": "\\|[-+*/^&|=<>!:~'.?]+" 2526 | }, 2527 | "named": true, 2528 | "value": "binary_operator" 2529 | } 2530 | }, 2531 | { 2532 | "type": "FIELD", 2533 | "name": "right", 2534 | "content": { 2535 | "type": "SYMBOL", 2536 | "name": "_expr" 2537 | } 2538 | } 2539 | ] 2540 | } 2541 | }, 2542 | { 2543 | "type": "PREC_LEFT", 2544 | "value": 7, 2545 | "content": { 2546 | "type": "SEQ", 2547 | "members": [ 2548 | { 2549 | "type": "FIELD", 2550 | "name": "left", 2551 | "content": { 2552 | "type": "SYMBOL", 2553 | "name": "_expr" 2554 | } 2555 | }, 2556 | { 2557 | "type": "FIELD", 2558 | "name": "operator", 2559 | "content": { 2560 | "type": "ALIAS", 2561 | "content": { 2562 | "type": "PATTERN", 2563 | "value": "=[-+*/^&|=<>!:~'.?]+" 2564 | }, 2565 | "named": true, 2566 | "value": "binary_operator" 2567 | } 2568 | }, 2569 | { 2570 | "type": "FIELD", 2571 | "name": "right", 2572 | "content": { 2573 | "type": "SYMBOL", 2574 | "name": "_expr" 2575 | } 2576 | } 2577 | ] 2578 | } 2579 | }, 2580 | { 2581 | "type": "PREC_LEFT", 2582 | "value": 7, 2583 | "content": { 2584 | "type": "SEQ", 2585 | "members": [ 2586 | { 2587 | "type": "FIELD", 2588 | "name": "left", 2589 | "content": { 2590 | "type": "SYMBOL", 2591 | "name": "_expr" 2592 | } 2593 | }, 2594 | { 2595 | "type": "FIELD", 2596 | "name": "operator", 2597 | "content": { 2598 | "type": "ALIAS", 2599 | "content": { 2600 | "type": "PATTERN", 2601 | "value": "<[+*/^&|=<>!:~'.?]?" 2602 | }, 2603 | "named": true, 2604 | "value": "binary_operator" 2605 | } 2606 | }, 2607 | { 2608 | "type": "FIELD", 2609 | "name": "right", 2610 | "content": { 2611 | "type": "SYMBOL", 2612 | "name": "_expr" 2613 | } 2614 | } 2615 | ] 2616 | } 2617 | }, 2618 | { 2619 | "type": "PREC_LEFT", 2620 | "value": 7, 2621 | "content": { 2622 | "type": "SEQ", 2623 | "members": [ 2624 | { 2625 | "type": "FIELD", 2626 | "name": "left", 2627 | "content": { 2628 | "type": "SYMBOL", 2629 | "name": "_expr" 2630 | } 2631 | }, 2632 | { 2633 | "type": "FIELD", 2634 | "name": "operator", 2635 | "content": { 2636 | "type": "ALIAS", 2637 | "content": { 2638 | "type": "PATTERN", 2639 | "value": "<[-+*/^&|=<>!:~'.?]{2,}" 2640 | }, 2641 | "named": true, 2642 | "value": "binary_operator" 2643 | } 2644 | }, 2645 | { 2646 | "type": "FIELD", 2647 | "name": "right", 2648 | "content": { 2649 | "type": "SYMBOL", 2650 | "name": "_expr" 2651 | } 2652 | } 2653 | ] 2654 | } 2655 | }, 2656 | { 2657 | "type": "PREC_LEFT", 2658 | "value": 7, 2659 | "content": { 2660 | "type": "SEQ", 2661 | "members": [ 2662 | { 2663 | "type": "FIELD", 2664 | "name": "left", 2665 | "content": { 2666 | "type": "SYMBOL", 2667 | "name": "_expr" 2668 | } 2669 | }, 2670 | { 2671 | "type": "FIELD", 2672 | "name": "operator", 2673 | "content": { 2674 | "type": "ALIAS", 2675 | "content": { 2676 | "type": "PATTERN", 2677 | "value": ">[+*/^&|=<>!:~'.?]*" 2678 | }, 2679 | "named": true, 2680 | "value": "binary_operator" 2681 | } 2682 | }, 2683 | { 2684 | "type": "FIELD", 2685 | "name": "right", 2686 | "content": { 2687 | "type": "SYMBOL", 2688 | "name": "_expr" 2689 | } 2690 | } 2691 | ] 2692 | } 2693 | }, 2694 | { 2695 | "type": "PREC_LEFT", 2696 | "value": 6, 2697 | "content": { 2698 | "type": "SEQ", 2699 | "members": [ 2700 | { 2701 | "type": "FIELD", 2702 | "name": "left", 2703 | "content": { 2704 | "type": "SYMBOL", 2705 | "name": "_expr" 2706 | } 2707 | }, 2708 | { 2709 | "type": "FIELD", 2710 | "name": "operator", 2711 | "content": { 2712 | "type": "ALIAS", 2713 | "content": { 2714 | "type": "PATTERN", 2715 | "value": "\\^[-+*/^&|=<>!:~'.?]*" 2716 | }, 2717 | "named": true, 2718 | "value": "binary_operator" 2719 | } 2720 | }, 2721 | { 2722 | "type": "FIELD", 2723 | "name": "right", 2724 | "content": { 2725 | "type": "SYMBOL", 2726 | "name": "_expr" 2727 | } 2728 | } 2729 | ] 2730 | } 2731 | }, 2732 | { 2733 | "type": "PREC_LEFT", 2734 | "value": 6, 2735 | "content": { 2736 | "type": "SEQ", 2737 | "members": [ 2738 | { 2739 | "type": "FIELD", 2740 | "name": "left", 2741 | "content": { 2742 | "type": "SYMBOL", 2743 | "name": "_expr" 2744 | } 2745 | }, 2746 | { 2747 | "type": "FIELD", 2748 | "name": "operator", 2749 | "content": { 2750 | "type": "ALIAS", 2751 | "content": { 2752 | "type": "STRING", 2753 | "value": "::" 2754 | }, 2755 | "named": true, 2756 | "value": "binary_operator" 2757 | } 2758 | }, 2759 | { 2760 | "type": "FIELD", 2761 | "name": "right", 2762 | "content": { 2763 | "type": "SYMBOL", 2764 | "name": "_expr" 2765 | } 2766 | } 2767 | ] 2768 | } 2769 | }, 2770 | { 2771 | "type": "PREC_LEFT", 2772 | "value": 8, 2773 | "content": { 2774 | "type": "SEQ", 2775 | "members": [ 2776 | { 2777 | "type": "FIELD", 2778 | "name": "left", 2779 | "content": { 2780 | "type": "SYMBOL", 2781 | "name": "_expr" 2782 | } 2783 | }, 2784 | { 2785 | "type": "FIELD", 2786 | "name": "operator", 2787 | "content": { 2788 | "type": "ALIAS", 2789 | "content": { 2790 | "type": "PATTERN", 2791 | "value": "\\+[-+*/^&|=<>!:~'.?]*" 2792 | }, 2793 | "named": true, 2794 | "value": "binary_operator" 2795 | } 2796 | }, 2797 | { 2798 | "type": "FIELD", 2799 | "name": "right", 2800 | "content": { 2801 | "type": "SYMBOL", 2802 | "name": "_expr" 2803 | } 2804 | } 2805 | ] 2806 | } 2807 | }, 2808 | { 2809 | "type": "PREC_LEFT", 2810 | "value": 8, 2811 | "content": { 2812 | "type": "SEQ", 2813 | "members": [ 2814 | { 2815 | "type": "FIELD", 2816 | "name": "left", 2817 | "content": { 2818 | "type": "SYMBOL", 2819 | "name": "_expr" 2820 | } 2821 | }, 2822 | { 2823 | "type": "FIELD", 2824 | "name": "operator", 2825 | "content": { 2826 | "type": "ALIAS", 2827 | "content": { 2828 | "type": "PATTERN", 2829 | "value": "-[+*/^&|=!:~'.?]{2,}" 2868 | }, 2869 | "named": true, 2870 | "value": "binary_operator" 2871 | } 2872 | }, 2873 | { 2874 | "type": "FIELD", 2875 | "name": "right", 2876 | "content": { 2877 | "type": "SYMBOL", 2878 | "name": "_expr" 2879 | } 2880 | } 2881 | ] 2882 | } 2883 | }, 2884 | { 2885 | "type": "PREC_LEFT", 2886 | "value": 9, 2887 | "content": { 2888 | "type": "SEQ", 2889 | "members": [ 2890 | { 2891 | "type": "FIELD", 2892 | "name": "left", 2893 | "content": { 2894 | "type": "SYMBOL", 2895 | "name": "_expr" 2896 | } 2897 | }, 2898 | { 2899 | "type": "FIELD", 2900 | "name": "operator", 2901 | "content": { 2902 | "type": "ALIAS", 2903 | "content": { 2904 | "type": "PATTERN", 2905 | "value": "\\*[-+*/^&|=<>!:~'.?]*" 2906 | }, 2907 | "named": true, 2908 | "value": "binary_operator" 2909 | } 2910 | }, 2911 | { 2912 | "type": "FIELD", 2913 | "name": "right", 2914 | "content": { 2915 | "type": "SYMBOL", 2916 | "name": "_expr" 2917 | } 2918 | } 2919 | ] 2920 | } 2921 | }, 2922 | { 2923 | "type": "PREC_LEFT", 2924 | "value": 9, 2925 | "content": { 2926 | "type": "SEQ", 2927 | "members": [ 2928 | { 2929 | "type": "FIELD", 2930 | "name": "left", 2931 | "content": { 2932 | "type": "SYMBOL", 2933 | "name": "_expr" 2934 | } 2935 | }, 2936 | { 2937 | "type": "FIELD", 2938 | "name": "operator", 2939 | "content": { 2940 | "type": "ALIAS", 2941 | "content": { 2942 | "type": "PATTERN", 2943 | "value": "\\/[-+*/^&|=<>!:~'.?]*" 2944 | }, 2945 | "named": true, 2946 | "value": "binary_operator" 2947 | } 2948 | }, 2949 | { 2950 | "type": "FIELD", 2951 | "name": "right", 2952 | "content": { 2953 | "type": "SYMBOL", 2954 | "name": "_expr" 2955 | } 2956 | } 2957 | ] 2958 | } 2959 | }, 2960 | { 2961 | "type": "PREC_LEFT", 2962 | "value": 9, 2963 | "content": { 2964 | "type": "SEQ", 2965 | "members": [ 2966 | { 2967 | "type": "FIELD", 2968 | "name": "left", 2969 | "content": { 2970 | "type": "SYMBOL", 2971 | "name": "_expr" 2972 | } 2973 | }, 2974 | { 2975 | "type": "FIELD", 2976 | "name": "operator", 2977 | "content": { 2978 | "type": "ALIAS", 2979 | "content": { 2980 | "type": "STRING", 2981 | "value": "mod" 2982 | }, 2983 | "named": true, 2984 | "value": "binary_operator" 2985 | } 2986 | }, 2987 | { 2988 | "type": "FIELD", 2989 | "name": "right", 2990 | "content": { 2991 | "type": "SYMBOL", 2992 | "name": "_expr" 2993 | } 2994 | } 2995 | ] 2996 | } 2997 | } 2998 | ] 2999 | }, 3000 | "binary_operator": { 3001 | "type": "CHOICE", 3002 | "members": [ 3003 | { 3004 | "type": "PATTERN", 3005 | "value": "&[-+*/^&|=<>!:~'.?]+" 3006 | }, 3007 | { 3008 | "type": "PATTERN", 3009 | "value": "\\|[-+*/^&|=<>!:~'.?]+" 3010 | }, 3011 | { 3012 | "type": "PATTERN", 3013 | "value": "=[-+*/^&|=<>!:~'.?]+" 3014 | }, 3015 | { 3016 | "type": "PATTERN", 3017 | "value": "<[+*/^&|=<>!:~'.?]?" 3018 | }, 3019 | { 3020 | "type": "PATTERN", 3021 | "value": "<[-+*/^&|=<>!:~'.?]{2,}" 3022 | }, 3023 | { 3024 | "type": "PATTERN", 3025 | "value": ">[+*/^&|=<>!:~'.?]*" 3026 | }, 3027 | { 3028 | "type": "PATTERN", 3029 | "value": "\\^[-+*/^&|=<>!:~'.?]*" 3030 | }, 3031 | { 3032 | "type": "STRING", 3033 | "value": "::" 3034 | }, 3035 | { 3036 | "type": "PATTERN", 3037 | "value": "\\+[-+*/^&|=<>!:~'.?]*" 3038 | }, 3039 | { 3040 | "type": "PATTERN", 3041 | "value": "-[+*/^&|=!:~'.?]{2,}" 3046 | }, 3047 | { 3048 | "type": "PATTERN", 3049 | "value": "\\*[-+*/^&|=<>!:~'.?]*" 3050 | }, 3051 | { 3052 | "type": "PATTERN", 3053 | "value": "\\/[-+*/^&|=<>!:~'.?]*" 3054 | }, 3055 | { 3056 | "type": "STRING", 3057 | "value": "mod" 3058 | } 3059 | ] 3060 | }, 3061 | "unary_operator_expr": { 3062 | "type": "CHOICE", 3063 | "members": [ 3064 | { 3065 | "type": "PREC_RIGHT", 3066 | "value": 10, 3067 | "content": { 3068 | "type": "SEQ", 3069 | "members": [ 3070 | { 3071 | "type": "SYMBOL", 3072 | "name": "unary_operator" 3073 | }, 3074 | { 3075 | "type": "SYMBOL", 3076 | "name": "_expr" 3077 | } 3078 | ] 3079 | } 3080 | }, 3081 | { 3082 | "type": "PREC_RIGHT", 3083 | "value": 12, 3084 | "content": { 3085 | "type": "SEQ", 3086 | "members": [ 3087 | { 3088 | "type": "SYMBOL", 3089 | "name": "unary_prefix" 3090 | }, 3091 | { 3092 | "type": "SYMBOL", 3093 | "name": "_expr" 3094 | } 3095 | ] 3096 | } 3097 | } 3098 | ] 3099 | }, 3100 | "unary_operator": { 3101 | "type": "CHOICE", 3102 | "members": [ 3103 | { 3104 | "type": "STRING", 3105 | "value": "-" 3106 | }, 3107 | { 3108 | "type": "STRING", 3109 | "value": "not" 3110 | }, 3111 | { 3112 | "type": "STRING", 3113 | "value": "!" 3114 | } 3115 | ] 3116 | }, 3117 | "unary_prefix": { 3118 | "type": "PATTERN", 3119 | "value": "[&!~]" 3120 | }, 3121 | "application": { 3122 | "type": "PREC_LEFT", 3123 | "value": 11, 3124 | "content": { 3125 | "type": "SEQ", 3126 | "members": [ 3127 | { 3128 | "type": "FIELD", 3129 | "name": "function", 3130 | "content": { 3131 | "type": "CHOICE", 3132 | "members": [ 3133 | { 3134 | "type": "SYMBOL", 3135 | "name": "application" 3136 | }, 3137 | { 3138 | "type": "SYMBOL", 3139 | "name": "unary_operator_expr" 3140 | }, 3141 | { 3142 | "type": "SYMBOL", 3143 | "name": "variant_constructor" 3144 | }, 3145 | { 3146 | "type": "SYMBOL", 3147 | "name": "record_member" 3148 | }, 3149 | { 3150 | "type": "SYMBOL", 3151 | "name": "_unary" 3152 | } 3153 | ] 3154 | } 3155 | }, 3156 | { 3157 | "type": "CHOICE", 3158 | "members": [ 3159 | { 3160 | "type": "FIELD", 3161 | "name": "arg", 3162 | "content": { 3163 | "type": "SYMBOL", 3164 | "name": "_application_args" 3165 | } 3166 | }, 3167 | { 3168 | "type": "FIELD", 3169 | "name": "opt", 3170 | "content": { 3171 | "type": "SYMBOL", 3172 | "name": "_application_args_opt" 3173 | } 3174 | } 3175 | ] 3176 | } 3177 | ] 3178 | } 3179 | }, 3180 | "_application_args": { 3181 | "type": "CHOICE", 3182 | "members": [ 3183 | { 3184 | "type": "SYMBOL", 3185 | "name": "unary_operator_expr" 3186 | }, 3187 | { 3188 | "type": "SYMBOL", 3189 | "name": "variant_constructor" 3190 | }, 3191 | { 3192 | "type": "SYMBOL", 3193 | "name": "record_member" 3194 | }, 3195 | { 3196 | "type": "SYMBOL", 3197 | "name": "_unary" 3198 | } 3199 | ] 3200 | }, 3201 | "_application_args_opt": { 3202 | "type": "SEQ", 3203 | "members": [ 3204 | { 3205 | "type": "STRING", 3206 | "value": "?:" 3207 | }, 3208 | { 3209 | "type": "SYMBOL", 3210 | "name": "_application_args" 3211 | } 3212 | ] 3213 | }, 3214 | "command_application": { 3215 | "type": "PREC_LEFT", 3216 | "value": 11, 3217 | "content": { 3218 | "type": "SEQ", 3219 | "members": [ 3220 | { 3221 | "type": "STRING", 3222 | "value": "command" 3223 | }, 3224 | { 3225 | "type": "SYMBOL", 3226 | "name": "inline_cmd_name" 3227 | } 3228 | ] 3229 | } 3230 | }, 3231 | "variant_constructor": { 3232 | "type": "PREC_LEFT", 3233 | "value": 10, 3234 | "content": { 3235 | "type": "SEQ", 3236 | "members": [ 3237 | { 3238 | "type": "SYMBOL", 3239 | "name": "variant_name" 3240 | }, 3241 | { 3242 | "type": "CHOICE", 3243 | "members": [ 3244 | { 3245 | "type": "SYMBOL", 3246 | "name": "_unary" 3247 | }, 3248 | { 3249 | "type": "BLANK" 3250 | } 3251 | ] 3252 | } 3253 | ] 3254 | } 3255 | }, 3256 | "record_member": { 3257 | "type": "SEQ", 3258 | "members": [ 3259 | { 3260 | "type": "SYMBOL", 3261 | "name": "_unary" 3262 | }, 3263 | { 3264 | "type": "STRING", 3265 | "value": "#" 3266 | }, 3267 | { 3268 | "type": "SYMBOL", 3269 | "name": "identifier" 3270 | } 3271 | ] 3272 | }, 3273 | "_unary": { 3274 | "type": "SEQ", 3275 | "members": [ 3276 | { 3277 | "type": "CHOICE", 3278 | "members": [ 3279 | { 3280 | "type": "SYMBOL", 3281 | "name": "block_text" 3282 | }, 3283 | { 3284 | "type": "SYMBOL", 3285 | "name": "inline_text" 3286 | }, 3287 | { 3288 | "type": "SYMBOL", 3289 | "name": "inline_text_list" 3290 | }, 3291 | { 3292 | "type": "SYMBOL", 3293 | "name": "inline_text_bullet_list" 3294 | }, 3295 | { 3296 | "type": "SYMBOL", 3297 | "name": "math_text" 3298 | }, 3299 | { 3300 | "type": "SYMBOL", 3301 | "name": "math_list" 3302 | }, 3303 | { 3304 | "type": "SYMBOL", 3305 | "name": "record" 3306 | }, 3307 | { 3308 | "type": "SYMBOL", 3309 | "name": "list" 3310 | }, 3311 | { 3312 | "type": "SYMBOL", 3313 | "name": "tuple" 3314 | }, 3315 | { 3316 | "type": "SYMBOL", 3317 | "name": "parened_expr" 3318 | }, 3319 | { 3320 | "type": "SYMBOL", 3321 | "name": "expr_with_mod" 3322 | }, 3323 | { 3324 | "type": "SYMBOL", 3325 | "name": "modvar" 3326 | }, 3327 | { 3328 | "type": "SYMBOL", 3329 | "name": "_literal" 3330 | }, 3331 | { 3332 | "type": "SYMBOL", 3333 | "name": "identifier" 3334 | } 3335 | ] 3336 | } 3337 | ] 3338 | }, 3339 | "record": { 3340 | "type": "CHOICE", 3341 | "members": [ 3342 | { 3343 | "type": "SEQ", 3344 | "members": [ 3345 | { 3346 | "type": "STRING", 3347 | "value": "(|" 3348 | }, 3349 | { 3350 | "type": "SYMBOL", 3351 | "name": "_unary" 3352 | }, 3353 | { 3354 | "type": "STRING", 3355 | "value": "with" 3356 | }, 3357 | { 3358 | "type": "SYMBOL", 3359 | "name": "_record_inner" 3360 | }, 3361 | { 3362 | "type": "STRING", 3363 | "value": "|)" 3364 | } 3365 | ] 3366 | }, 3367 | { 3368 | "type": "SEQ", 3369 | "members": [ 3370 | { 3371 | "type": "STRING", 3372 | "value": "(|" 3373 | }, 3374 | { 3375 | "type": "CHOICE", 3376 | "members": [ 3377 | { 3378 | "type": "SYMBOL", 3379 | "name": "_record_inner" 3380 | }, 3381 | { 3382 | "type": "BLANK" 3383 | } 3384 | ] 3385 | }, 3386 | { 3387 | "type": "STRING", 3388 | "value": "|)" 3389 | } 3390 | ] 3391 | } 3392 | ] 3393 | }, 3394 | "_record_inner": { 3395 | "type": "SEQ", 3396 | "members": [ 3397 | { 3398 | "type": "SEQ", 3399 | "members": [ 3400 | { 3401 | "type": "SYMBOL", 3402 | "name": "record_unit" 3403 | }, 3404 | { 3405 | "type": "REPEAT", 3406 | "content": { 3407 | "type": "SEQ", 3408 | "members": [ 3409 | { 3410 | "type": "STRING", 3411 | "value": ";" 3412 | }, 3413 | { 3414 | "type": "SYMBOL", 3415 | "name": "record_unit" 3416 | } 3417 | ] 3418 | } 3419 | } 3420 | ] 3421 | }, 3422 | { 3423 | "type": "CHOICE", 3424 | "members": [ 3425 | { 3426 | "type": "STRING", 3427 | "value": ";" 3428 | }, 3429 | { 3430 | "type": "BLANK" 3431 | } 3432 | ] 3433 | } 3434 | ] 3435 | }, 3436 | "record_unit": { 3437 | "type": "SEQ", 3438 | "members": [ 3439 | { 3440 | "type": "SYMBOL", 3441 | "name": "identifier" 3442 | }, 3443 | { 3444 | "type": "STRING", 3445 | "value": "=" 3446 | }, 3447 | { 3448 | "type": "SYMBOL", 3449 | "name": "_expr" 3450 | } 3451 | ] 3452 | }, 3453 | "list": { 3454 | "type": "CHOICE", 3455 | "members": [ 3456 | { 3457 | "type": "SEQ", 3458 | "members": [ 3459 | { 3460 | "type": "STRING", 3461 | "value": "[" 3462 | }, 3463 | { 3464 | "type": "CHOICE", 3465 | "members": [ 3466 | { 3467 | "type": "SEQ", 3468 | "members": [ 3469 | { 3470 | "type": "SYMBOL", 3471 | "name": "_expr" 3472 | }, 3473 | { 3474 | "type": "REPEAT", 3475 | "content": { 3476 | "type": "SEQ", 3477 | "members": [ 3478 | { 3479 | "type": "STRING", 3480 | "value": ";" 3481 | }, 3482 | { 3483 | "type": "SYMBOL", 3484 | "name": "_expr" 3485 | } 3486 | ] 3487 | } 3488 | } 3489 | ] 3490 | }, 3491 | { 3492 | "type": "BLANK" 3493 | } 3494 | ] 3495 | }, 3496 | { 3497 | "type": "CHOICE", 3498 | "members": [ 3499 | { 3500 | "type": "STRING", 3501 | "value": ";" 3502 | }, 3503 | { 3504 | "type": "BLANK" 3505 | } 3506 | ] 3507 | }, 3508 | { 3509 | "type": "STRING", 3510 | "value": "]" 3511 | } 3512 | ] 3513 | } 3514 | ] 3515 | }, 3516 | "tuple": { 3517 | "type": "SEQ", 3518 | "members": [ 3519 | { 3520 | "type": "STRING", 3521 | "value": "(" 3522 | }, 3523 | { 3524 | "type": "SEQ", 3525 | "members": [ 3526 | { 3527 | "type": "SYMBOL", 3528 | "name": "_expr" 3529 | }, 3530 | { 3531 | "type": "REPEAT1", 3532 | "content": { 3533 | "type": "SEQ", 3534 | "members": [ 3535 | { 3536 | "type": "STRING", 3537 | "value": "," 3538 | }, 3539 | { 3540 | "type": "SYMBOL", 3541 | "name": "_expr" 3542 | } 3543 | ] 3544 | } 3545 | } 3546 | ] 3547 | }, 3548 | { 3549 | "type": "STRING", 3550 | "value": ")" 3551 | } 3552 | ] 3553 | }, 3554 | "parened_expr": { 3555 | "type": "SEQ", 3556 | "members": [ 3557 | { 3558 | "type": "STRING", 3559 | "value": "(" 3560 | }, 3561 | { 3562 | "type": "CHOICE", 3563 | "members": [ 3564 | { 3565 | "type": "SYMBOL", 3566 | "name": "binary_operator" 3567 | }, 3568 | { 3569 | "type": "SYMBOL", 3570 | "name": "_expr" 3571 | } 3572 | ] 3573 | }, 3574 | { 3575 | "type": "STRING", 3576 | "value": ")" 3577 | } 3578 | ] 3579 | }, 3580 | "expr_with_mod": { 3581 | "type": "SEQ", 3582 | "members": [ 3583 | { 3584 | "type": "ALIAS", 3585 | "content": { 3586 | "type": "SYMBOL", 3587 | "name": "_module_prefix" 3588 | }, 3589 | "named": true, 3590 | "value": "module_name" 3591 | }, 3592 | { 3593 | "type": "STRING", 3594 | "value": ".(" 3595 | }, 3596 | { 3597 | "type": "SYMBOL", 3598 | "name": "_expr" 3599 | }, 3600 | { 3601 | "type": "STRING", 3602 | "value": ")" 3603 | } 3604 | ] 3605 | }, 3606 | "modvar": { 3607 | "type": "SEQ", 3608 | "members": [ 3609 | { 3610 | "type": "ALIAS", 3611 | "content": { 3612 | "type": "SYMBOL", 3613 | "name": "_module_prefix" 3614 | }, 3615 | "named": true, 3616 | "value": "module_name" 3617 | }, 3618 | { 3619 | "type": "STRING", 3620 | "value": "." 3621 | }, 3622 | { 3623 | "type": "SYMBOL", 3624 | "name": "identifier" 3625 | } 3626 | ] 3627 | }, 3628 | "_mod_cmd_name": { 3629 | "type": "SEQ", 3630 | "members": [ 3631 | { 3632 | "type": "ALIAS", 3633 | "content": { 3634 | "type": "SYMBOL", 3635 | "name": "_module_prefix" 3636 | }, 3637 | "named": true, 3638 | "value": "module_name" 3639 | }, 3640 | { 3641 | "type": "STRING", 3642 | "value": "." 3643 | }, 3644 | { 3645 | "type": "SYMBOL", 3646 | "name": "cmd_name" 3647 | } 3648 | ] 3649 | }, 3650 | "module_name": { 3651 | "type": "PATTERN", 3652 | "value": "[A-Z][-A-Za-z0-9]*" 3653 | }, 3654 | "variant_name": { 3655 | "type": "PATTERN", 3656 | "value": "[A-Z][-A-Za-z0-9]*" 3657 | }, 3658 | "_literal": { 3659 | "type": "CHOICE", 3660 | "members": [ 3661 | { 3662 | "type": "SYMBOL", 3663 | "name": "literal_unit" 3664 | }, 3665 | { 3666 | "type": "SYMBOL", 3667 | "name": "literal_bool" 3668 | }, 3669 | { 3670 | "type": "SYMBOL", 3671 | "name": "literal_length" 3672 | }, 3673 | { 3674 | "type": "SYMBOL", 3675 | "name": "literal_int" 3676 | }, 3677 | { 3678 | "type": "SYMBOL", 3679 | "name": "literal_string" 3680 | }, 3681 | { 3682 | "type": "SYMBOL", 3683 | "name": "literal_float" 3684 | } 3685 | ] 3686 | }, 3687 | "identifier": { 3688 | "type": "PATTERN", 3689 | "value": "[a-z][-a-zA-Z0-9]*" 3690 | }, 3691 | "literal_unit": { 3692 | "type": "SEQ", 3693 | "members": [ 3694 | { 3695 | "type": "STRING", 3696 | "value": "(" 3697 | }, 3698 | { 3699 | "type": "STRING", 3700 | "value": ")" 3701 | } 3702 | ] 3703 | }, 3704 | "literal_bool": { 3705 | "type": "CHOICE", 3706 | "members": [ 3707 | { 3708 | "type": "STRING", 3709 | "value": "true" 3710 | }, 3711 | { 3712 | "type": "STRING", 3713 | "value": "false" 3714 | } 3715 | ] 3716 | }, 3717 | "literal_length": { 3718 | "type": "TOKEN", 3719 | "content": { 3720 | "type": "CHOICE", 3721 | "members": [ 3722 | { 3723 | "type": "SEQ", 3724 | "members": [ 3725 | { 3726 | "type": "CHOICE", 3727 | "members": [ 3728 | { 3729 | "type": "STRING", 3730 | "value": "-" 3731 | }, 3732 | { 3733 | "type": "BLANK" 3734 | } 3735 | ] 3736 | }, 3737 | { 3738 | "type": "PATTERN", 3739 | "value": "[0-9]+" 3740 | }, 3741 | { 3742 | "type": "PATTERN", 3743 | "value": "[a-z]+" 3744 | } 3745 | ] 3746 | }, 3747 | { 3748 | "type": "SEQ", 3749 | "members": [ 3750 | { 3751 | "type": "CHOICE", 3752 | "members": [ 3753 | { 3754 | "type": "STRING", 3755 | "value": "-" 3756 | }, 3757 | { 3758 | "type": "BLANK" 3759 | } 3760 | ] 3761 | }, 3762 | { 3763 | "type": "PATTERN", 3764 | "value": "[0-9]+" 3765 | }, 3766 | { 3767 | "type": "STRING", 3768 | "value": "." 3769 | }, 3770 | { 3771 | "type": "CHOICE", 3772 | "members": [ 3773 | { 3774 | "type": "PATTERN", 3775 | "value": "[0-9]+" 3776 | }, 3777 | { 3778 | "type": "BLANK" 3779 | } 3780 | ] 3781 | }, 3782 | { 3783 | "type": "PATTERN", 3784 | "value": "[a-z]+" 3785 | } 3786 | ] 3787 | }, 3788 | { 3789 | "type": "SEQ", 3790 | "members": [ 3791 | { 3792 | "type": "CHOICE", 3793 | "members": [ 3794 | { 3795 | "type": "STRING", 3796 | "value": "-" 3797 | }, 3798 | { 3799 | "type": "BLANK" 3800 | } 3801 | ] 3802 | }, 3803 | { 3804 | "type": "CHOICE", 3805 | "members": [ 3806 | { 3807 | "type": "PATTERN", 3808 | "value": "[0-9]+" 3809 | }, 3810 | { 3811 | "type": "BLANK" 3812 | } 3813 | ] 3814 | }, 3815 | { 3816 | "type": "STRING", 3817 | "value": "." 3818 | }, 3819 | { 3820 | "type": "PATTERN", 3821 | "value": "[0-9]+" 3822 | }, 3823 | { 3824 | "type": "PATTERN", 3825 | "value": "[a-z]+" 3826 | } 3827 | ] 3828 | } 3829 | ] 3830 | } 3831 | }, 3832 | "literal_int": { 3833 | "type": "TOKEN", 3834 | "content": { 3835 | "type": "CHOICE", 3836 | "members": [ 3837 | { 3838 | "type": "SEQ", 3839 | "members": [ 3840 | { 3841 | "type": "CHOICE", 3842 | "members": [ 3843 | { 3844 | "type": "STRING", 3845 | "value": "0x" 3846 | }, 3847 | { 3848 | "type": "STRING", 3849 | "value": "0X" 3850 | } 3851 | ] 3852 | }, 3853 | { 3854 | "type": "REPEAT1", 3855 | "content": { 3856 | "type": "PATTERN", 3857 | "value": "[A-F0-9]" 3858 | } 3859 | } 3860 | ] 3861 | }, 3862 | { 3863 | "type": "REPEAT1", 3864 | "content": { 3865 | "type": "PATTERN", 3866 | "value": "[0-9]" 3867 | } 3868 | } 3869 | ] 3870 | } 3871 | }, 3872 | "literal_float": { 3873 | "type": "TOKEN", 3874 | "content": { 3875 | "type": "CHOICE", 3876 | "members": [ 3877 | { 3878 | "type": "SEQ", 3879 | "members": [ 3880 | { 3881 | "type": "REPEAT1", 3882 | "content": { 3883 | "type": "PATTERN", 3884 | "value": "[0-9]" 3885 | } 3886 | }, 3887 | { 3888 | "type": "STRING", 3889 | "value": "." 3890 | }, 3891 | { 3892 | "type": "CHOICE", 3893 | "members": [ 3894 | { 3895 | "type": "REPEAT1", 3896 | "content": { 3897 | "type": "PATTERN", 3898 | "value": "[0-9]" 3899 | } 3900 | }, 3901 | { 3902 | "type": "BLANK" 3903 | } 3904 | ] 3905 | } 3906 | ] 3907 | }, 3908 | { 3909 | "type": "SEQ", 3910 | "members": [ 3911 | { 3912 | "type": "CHOICE", 3913 | "members": [ 3914 | { 3915 | "type": "REPEAT1", 3916 | "content": { 3917 | "type": "PATTERN", 3918 | "value": "[0-9]" 3919 | } 3920 | }, 3921 | { 3922 | "type": "BLANK" 3923 | } 3924 | ] 3925 | }, 3926 | { 3927 | "type": "STRING", 3928 | "value": "." 3929 | }, 3930 | { 3931 | "type": "REPEAT1", 3932 | "content": { 3933 | "type": "PATTERN", 3934 | "value": "[0-9]" 3935 | } 3936 | } 3937 | ] 3938 | } 3939 | ] 3940 | } 3941 | }, 3942 | "inline_cmd": { 3943 | "type": "SEQ", 3944 | "members": [ 3945 | { 3946 | "type": "FIELD", 3947 | "name": "name", 3948 | "content": { 3949 | "type": "SYMBOL", 3950 | "name": "inline_cmd_name" 3951 | } 3952 | }, 3953 | { 3954 | "type": "REPEAT", 3955 | "content": { 3956 | "type": "CHOICE", 3957 | "members": [ 3958 | { 3959 | "type": "FIELD", 3960 | "name": "arg", 3961 | "content": { 3962 | "type": "SYMBOL", 3963 | "name": "cmd_expr_arg" 3964 | } 3965 | }, 3966 | { 3967 | "type": "FIELD", 3968 | "name": "opt", 3969 | "content": { 3970 | "type": "SYMBOL", 3971 | "name": "cmd_expr_option" 3972 | } 3973 | } 3974 | ] 3975 | } 3976 | }, 3977 | { 3978 | "type": "CHOICE", 3979 | "members": [ 3980 | { 3981 | "type": "REPEAT1", 3982 | "content": { 3983 | "type": "FIELD", 3984 | "name": "arg", 3985 | "content": { 3986 | "type": "SYMBOL", 3987 | "name": "cmd_text_arg" 3988 | } 3989 | } 3990 | }, 3991 | { 3992 | "type": "STRING", 3993 | "value": ";" 3994 | } 3995 | ] 3996 | } 3997 | ] 3998 | }, 3999 | "inline_cmd_name": { 4000 | "type": "SEQ", 4001 | "members": [ 4002 | { 4003 | "type": "ALIAS", 4004 | "content": { 4005 | "type": "SYMBOL", 4006 | "name": "_inline_cmd_prefix" 4007 | }, 4008 | "named": false, 4009 | "value": "\\" 4010 | }, 4011 | { 4012 | "type": "CHOICE", 4013 | "members": [ 4014 | { 4015 | "type": "SYMBOL", 4016 | "name": "_mod_cmd_name" 4017 | }, 4018 | { 4019 | "type": "SYMBOL", 4020 | "name": "cmd_name" 4021 | } 4022 | ] 4023 | } 4024 | ] 4025 | }, 4026 | "block_cmd": { 4027 | "type": "SEQ", 4028 | "members": [ 4029 | { 4030 | "type": "FIELD", 4031 | "name": "name", 4032 | "content": { 4033 | "type": "SYMBOL", 4034 | "name": "block_cmd_name" 4035 | } 4036 | }, 4037 | { 4038 | "type": "REPEAT", 4039 | "content": { 4040 | "type": "CHOICE", 4041 | "members": [ 4042 | { 4043 | "type": "FIELD", 4044 | "name": "arg", 4045 | "content": { 4046 | "type": "SYMBOL", 4047 | "name": "cmd_expr_arg" 4048 | } 4049 | }, 4050 | { 4051 | "type": "FIELD", 4052 | "name": "opt", 4053 | "content": { 4054 | "type": "SYMBOL", 4055 | "name": "cmd_expr_option" 4056 | } 4057 | } 4058 | ] 4059 | } 4060 | }, 4061 | { 4062 | "type": "CHOICE", 4063 | "members": [ 4064 | { 4065 | "type": "REPEAT1", 4066 | "content": { 4067 | "type": "FIELD", 4068 | "name": "arg", 4069 | "content": { 4070 | "type": "SYMBOL", 4071 | "name": "cmd_text_arg" 4072 | } 4073 | } 4074 | }, 4075 | { 4076 | "type": "STRING", 4077 | "value": ";" 4078 | } 4079 | ] 4080 | } 4081 | ] 4082 | }, 4083 | "block_cmd_name": { 4084 | "type": "SEQ", 4085 | "members": [ 4086 | { 4087 | "type": "ALIAS", 4088 | "content": { 4089 | "type": "SYMBOL", 4090 | "name": "_block_cmd_prefix" 4091 | }, 4092 | "named": false, 4093 | "value": "+" 4094 | }, 4095 | { 4096 | "type": "CHOICE", 4097 | "members": [ 4098 | { 4099 | "type": "SYMBOL", 4100 | "name": "_mod_cmd_name" 4101 | }, 4102 | { 4103 | "type": "SYMBOL", 4104 | "name": "cmd_name" 4105 | } 4106 | ] 4107 | } 4108 | ] 4109 | }, 4110 | "cmd_expr_arg": { 4111 | "type": "SYMBOL", 4112 | "name": "_cmd_expr_arg_inner" 4113 | }, 4114 | "cmd_expr_option": { 4115 | "type": "SEQ", 4116 | "members": [ 4117 | { 4118 | "type": "STRING", 4119 | "value": "?:" 4120 | }, 4121 | { 4122 | "type": "SYMBOL", 4123 | "name": "_cmd_expr_arg_inner" 4124 | } 4125 | ] 4126 | }, 4127 | "_cmd_expr_arg_inner": { 4128 | "type": "CHOICE", 4129 | "members": [ 4130 | { 4131 | "type": "SEQ", 4132 | "members": [ 4133 | { 4134 | "type": "STRING", 4135 | "value": "(" 4136 | }, 4137 | { 4138 | "type": "SYMBOL", 4139 | "name": "_expr" 4140 | }, 4141 | { 4142 | "type": "STRING", 4143 | "value": ")" 4144 | } 4145 | ] 4146 | }, 4147 | { 4148 | "type": "SYMBOL", 4149 | "name": "list" 4150 | }, 4151 | { 4152 | "type": "SYMBOL", 4153 | "name": "record" 4154 | } 4155 | ] 4156 | }, 4157 | "cmd_text_arg": { 4158 | "type": "CHOICE", 4159 | "members": [ 4160 | { 4161 | "type": "SYMBOL", 4162 | "name": "inline_text" 4163 | }, 4164 | { 4165 | "type": "SYMBOL", 4166 | "name": "inline_text_list" 4167 | }, 4168 | { 4169 | "type": "SYMBOL", 4170 | "name": "inline_text_bullet_list" 4171 | }, 4172 | { 4173 | "type": "ALIAS", 4174 | "content": { 4175 | "type": "SYMBOL", 4176 | "name": "_cmd_text_arg_block" 4177 | }, 4178 | "named": true, 4179 | "value": "block_text" 4180 | } 4181 | ] 4182 | }, 4183 | "_cmd_text_arg_block": { 4184 | "type": "SEQ", 4185 | "members": [ 4186 | { 4187 | "type": "STRING", 4188 | "value": "<" 4189 | }, 4190 | { 4191 | "type": "CHOICE", 4192 | "members": [ 4193 | { 4194 | "type": "SYMBOL", 4195 | "name": "vertical" 4196 | }, 4197 | { 4198 | "type": "BLANK" 4199 | } 4200 | ] 4201 | }, 4202 | { 4203 | "type": "STRING", 4204 | "value": ">" 4205 | } 4206 | ] 4207 | }, 4208 | "math_cmd": { 4209 | "type": "PREC_LEFT", 4210 | "value": 1, 4211 | "content": { 4212 | "type": "SEQ", 4213 | "members": [ 4214 | { 4215 | "type": "FIELD", 4216 | "name": "name", 4217 | "content": { 4218 | "type": "SYMBOL", 4219 | "name": "math_cmd_name" 4220 | } 4221 | }, 4222 | { 4223 | "type": "REPEAT", 4224 | "content": { 4225 | "type": "CHOICE", 4226 | "members": [ 4227 | { 4228 | "type": "FIELD", 4229 | "name": "arg", 4230 | "content": { 4231 | "type": "SYMBOL", 4232 | "name": "math_cmd_expr_arg" 4233 | } 4234 | }, 4235 | { 4236 | "type": "FIELD", 4237 | "name": "opt", 4238 | "content": { 4239 | "type": "SYMBOL", 4240 | "name": "math_cmd_expr_option" 4241 | } 4242 | } 4243 | ] 4244 | } 4245 | } 4246 | ] 4247 | } 4248 | }, 4249 | "math_cmd_name": { 4250 | "type": "SEQ", 4251 | "members": [ 4252 | { 4253 | "type": "ALIAS", 4254 | "content": { 4255 | "type": "SYMBOL", 4256 | "name": "_inline_cmd_prefix" 4257 | }, 4258 | "named": false, 4259 | "value": "\\" 4260 | }, 4261 | { 4262 | "type": "CHOICE", 4263 | "members": [ 4264 | { 4265 | "type": "SYMBOL", 4266 | "name": "_mod_cmd_name" 4267 | }, 4268 | { 4269 | "type": "SYMBOL", 4270 | "name": "cmd_name" 4271 | } 4272 | ] 4273 | } 4274 | ] 4275 | }, 4276 | "math_cmd_expr_arg": { 4277 | "type": "SEQ", 4278 | "members": [ 4279 | { 4280 | "type": "SYMBOL", 4281 | "name": "_math_cmd_expr_arg_inner" 4282 | } 4283 | ] 4284 | }, 4285 | "math_cmd_expr_option": { 4286 | "type": "SEQ", 4287 | "members": [ 4288 | { 4289 | "type": "STRING", 4290 | "value": "?:" 4291 | }, 4292 | { 4293 | "type": "SYMBOL", 4294 | "name": "_math_cmd_expr_arg_inner" 4295 | } 4296 | ] 4297 | }, 4298 | "_math_cmd_expr_arg_inner": { 4299 | "type": "CHOICE", 4300 | "members": [ 4301 | { 4302 | "type": "SEQ", 4303 | "members": [ 4304 | { 4305 | "type": "STRING", 4306 | "value": "{" 4307 | }, 4308 | { 4309 | "type": "SYMBOL", 4310 | "name": "math" 4311 | }, 4312 | { 4313 | "type": "STRING", 4314 | "value": "}" 4315 | } 4316 | ] 4317 | }, 4318 | { 4319 | "type": "SEQ", 4320 | "members": [ 4321 | { 4322 | "type": "STRING", 4323 | "value": "!" 4324 | }, 4325 | { 4326 | "type": "SYMBOL", 4327 | "name": "inline_text" 4328 | } 4329 | ] 4330 | }, 4331 | { 4332 | "type": "SEQ", 4333 | "members": [ 4334 | { 4335 | "type": "STRING", 4336 | "value": "!" 4337 | }, 4338 | { 4339 | "type": "SYMBOL", 4340 | "name": "inline_text_list" 4341 | } 4342 | ] 4343 | }, 4344 | { 4345 | "type": "SEQ", 4346 | "members": [ 4347 | { 4348 | "type": "STRING", 4349 | "value": "!" 4350 | }, 4351 | { 4352 | "type": "SYMBOL", 4353 | "name": "inline_text_bullet_list" 4354 | } 4355 | ] 4356 | }, 4357 | { 4358 | "type": "SEQ", 4359 | "members": [ 4360 | { 4361 | "type": "STRING", 4362 | "value": "!" 4363 | }, 4364 | { 4365 | "type": "STRING", 4366 | "value": "<" 4367 | }, 4368 | { 4369 | "type": "SYMBOL", 4370 | "name": "vertical" 4371 | }, 4372 | { 4373 | "type": "STRING", 4374 | "value": ">" 4375 | } 4376 | ] 4377 | }, 4378 | { 4379 | "type": "SEQ", 4380 | "members": [ 4381 | { 4382 | "type": "STRING", 4383 | "value": "!" 4384 | }, 4385 | { 4386 | "type": "STRING", 4387 | "value": "(" 4388 | }, 4389 | { 4390 | "type": "SYMBOL", 4391 | "name": "_expr" 4392 | }, 4393 | { 4394 | "type": "STRING", 4395 | "value": ")" 4396 | } 4397 | ] 4398 | }, 4399 | { 4400 | "type": "SEQ", 4401 | "members": [ 4402 | { 4403 | "type": "STRING", 4404 | "value": "!" 4405 | }, 4406 | { 4407 | "type": "SYMBOL", 4408 | "name": "list" 4409 | } 4410 | ] 4411 | }, 4412 | { 4413 | "type": "SEQ", 4414 | "members": [ 4415 | { 4416 | "type": "STRING", 4417 | "value": "!" 4418 | }, 4419 | { 4420 | "type": "SYMBOL", 4421 | "name": "record" 4422 | } 4423 | ] 4424 | } 4425 | ] 4426 | }, 4427 | "inline_text": { 4428 | "type": "SEQ", 4429 | "members": [ 4430 | { 4431 | "type": "STRING", 4432 | "value": "{" 4433 | }, 4434 | { 4435 | "type": "CHOICE", 4436 | "members": [ 4437 | { 4438 | "type": "SYMBOL", 4439 | "name": "horizontal" 4440 | }, 4441 | { 4442 | "type": "BLANK" 4443 | } 4444 | ] 4445 | }, 4446 | { 4447 | "type": "STRING", 4448 | "value": "}" 4449 | } 4450 | ] 4451 | }, 4452 | "inline_text_list": { 4453 | "type": "CHOICE", 4454 | "members": [ 4455 | { 4456 | "type": "SEQ", 4457 | "members": [ 4458 | { 4459 | "type": "STRING", 4460 | "value": "{" 4461 | }, 4462 | { 4463 | "type": "STRING", 4464 | "value": "|" 4465 | }, 4466 | { 4467 | "type": "CHOICE", 4468 | "members": [ 4469 | { 4470 | "type": "ALIAS", 4471 | "content": { 4472 | "type": "SYMBOL", 4473 | "name": "_horizontal_compound" 4474 | }, 4475 | "named": true, 4476 | "value": "horizontal" 4477 | }, 4478 | { 4479 | "type": "BLANK" 4480 | } 4481 | ] 4482 | }, 4483 | { 4484 | "type": "REPEAT", 4485 | "content": { 4486 | "type": "SEQ", 4487 | "members": [ 4488 | { 4489 | "type": "STRING", 4490 | "value": "|" 4491 | }, 4492 | { 4493 | "type": "CHOICE", 4494 | "members": [ 4495 | { 4496 | "type": "ALIAS", 4497 | "content": { 4498 | "type": "SYMBOL", 4499 | "name": "_horizontal_compound" 4500 | }, 4501 | "named": true, 4502 | "value": "horizontal" 4503 | }, 4504 | { 4505 | "type": "BLANK" 4506 | } 4507 | ] 4508 | } 4509 | ] 4510 | } 4511 | }, 4512 | { 4513 | "type": "STRING", 4514 | "value": "|" 4515 | }, 4516 | { 4517 | "type": "STRING", 4518 | "value": "}" 4519 | } 4520 | ] 4521 | } 4522 | ] 4523 | }, 4524 | "inline_text_bullet_list": { 4525 | "type": "SEQ", 4526 | "members": [ 4527 | { 4528 | "type": "STRING", 4529 | "value": "{" 4530 | }, 4531 | { 4532 | "type": "REPEAT1", 4533 | "content": { 4534 | "type": "SYMBOL", 4535 | "name": "inline_text_bullet_item" 4536 | } 4537 | }, 4538 | { 4539 | "type": "STRING", 4540 | "value": "}" 4541 | } 4542 | ] 4543 | }, 4544 | "horizontal": { 4545 | "type": "REPEAT1", 4546 | "content": { 4547 | "type": "CHOICE", 4548 | "members": [ 4549 | { 4550 | "type": "SYMBOL", 4551 | "name": "inline_literal_escaped" 4552 | }, 4553 | { 4554 | "type": "SYMBOL", 4555 | "name": "inline_text_embedding" 4556 | }, 4557 | { 4558 | "type": "SYMBOL", 4559 | "name": "math_text" 4560 | }, 4561 | { 4562 | "type": "SYMBOL", 4563 | "name": "literal_string" 4564 | }, 4565 | { 4566 | "type": "SYMBOL", 4567 | "name": "inline_cmd" 4568 | }, 4569 | { 4570 | "type": "SYMBOL", 4571 | "name": "inline_token" 4572 | } 4573 | ] 4574 | } 4575 | }, 4576 | "_horizontal_compound": { 4577 | "type": "REPEAT1", 4578 | "content": { 4579 | "type": "CHOICE", 4580 | "members": [ 4581 | { 4582 | "type": "SYMBOL", 4583 | "name": "inline_literal_escaped" 4584 | }, 4585 | { 4586 | "type": "SYMBOL", 4587 | "name": "inline_text_embedding" 4588 | }, 4589 | { 4590 | "type": "SYMBOL", 4591 | "name": "math_text" 4592 | }, 4593 | { 4594 | "type": "SYMBOL", 4595 | "name": "literal_string" 4596 | }, 4597 | { 4598 | "type": "SYMBOL", 4599 | "name": "inline_cmd" 4600 | }, 4601 | { 4602 | "type": "ALIAS", 4603 | "content": { 4604 | "type": "SYMBOL", 4605 | "name": "_inline_token_compound" 4606 | }, 4607 | "named": true, 4608 | "value": "inline_token" 4609 | } 4610 | ] 4611 | } 4612 | }, 4613 | "inline_text_bullet_item": { 4614 | "type": "SEQ", 4615 | "members": [ 4616 | { 4617 | "type": "SYMBOL", 4618 | "name": "inline_text_bullet_star" 4619 | }, 4620 | { 4621 | "type": "CHOICE", 4622 | "members": [ 4623 | { 4624 | "type": "ALIAS", 4625 | "content": { 4626 | "type": "SYMBOL", 4627 | "name": "_horizontal_compound" 4628 | }, 4629 | "named": true, 4630 | "value": "horizontal" 4631 | }, 4632 | { 4633 | "type": "BLANK" 4634 | } 4635 | ] 4636 | } 4637 | ] 4638 | }, 4639 | "inline_text_bullet_star": { 4640 | "type": "PATTERN", 4641 | "value": "\\*+" 4642 | }, 4643 | "inline_literal_escaped": { 4644 | "type": "CHOICE", 4645 | "members": [ 4646 | { 4647 | "type": "STRING", 4648 | "value": "\\@" 4649 | }, 4650 | { 4651 | "type": "STRING", 4652 | "value": "\\`" 4653 | }, 4654 | { 4655 | "type": "STRING", 4656 | "value": "\\\\" 4657 | }, 4658 | { 4659 | "type": "STRING", 4660 | "value": "\\{" 4661 | }, 4662 | { 4663 | "type": "STRING", 4664 | "value": "\\}" 4665 | }, 4666 | { 4667 | "type": "STRING", 4668 | "value": "\\%" 4669 | }, 4670 | { 4671 | "type": "STRING", 4672 | "value": "\\|" 4673 | }, 4674 | { 4675 | "type": "STRING", 4676 | "value": "\\*" 4677 | }, 4678 | { 4679 | "type": "STRING", 4680 | "value": "\\$" 4681 | }, 4682 | { 4683 | "type": "STRING", 4684 | "value": "\\#" 4685 | }, 4686 | { 4687 | "type": "STRING", 4688 | "value": "\\;" 4689 | }, 4690 | { 4691 | "type": "STRING", 4692 | "value": "\\ " 4693 | }, 4694 | { 4695 | "type": "STRING", 4696 | "value": "\\\"" 4697 | } 4698 | ] 4699 | }, 4700 | "inline_text_embedding": { 4701 | "type": "SEQ", 4702 | "members": [ 4703 | { 4704 | "type": "SYMBOL", 4705 | "name": "_numbersign_after_nospace" 4706 | }, 4707 | { 4708 | "type": "SYMBOL", 4709 | "name": "identifier" 4710 | }, 4711 | { 4712 | "type": "STRING", 4713 | "value": ";" 4714 | } 4715 | ] 4716 | }, 4717 | "block_text": { 4718 | "type": "SEQ", 4719 | "members": [ 4720 | { 4721 | "type": "STRING", 4722 | "value": "'<" 4723 | }, 4724 | { 4725 | "type": "CHOICE", 4726 | "members": [ 4727 | { 4728 | "type": "SYMBOL", 4729 | "name": "vertical" 4730 | }, 4731 | { 4732 | "type": "BLANK" 4733 | } 4734 | ] 4735 | }, 4736 | { 4737 | "type": "STRING", 4738 | "value": ">" 4739 | } 4740 | ] 4741 | }, 4742 | "vertical": { 4743 | "type": "REPEAT1", 4744 | "content": { 4745 | "type": "CHOICE", 4746 | "members": [ 4747 | { 4748 | "type": "SYMBOL", 4749 | "name": "block_cmd" 4750 | }, 4751 | { 4752 | "type": "SYMBOL", 4753 | "name": "block_text_embedding" 4754 | } 4755 | ] 4756 | } 4757 | }, 4758 | "block_text_embedding": { 4759 | "type": "SEQ", 4760 | "members": [ 4761 | { 4762 | "type": "SYMBOL", 4763 | "name": "_numbersign_after_nospace" 4764 | }, 4765 | { 4766 | "type": "SYMBOL", 4767 | "name": "identifier" 4768 | }, 4769 | { 4770 | "type": "STRING", 4771 | "value": ";" 4772 | } 4773 | ] 4774 | }, 4775 | "math_text": { 4776 | "type": "SEQ", 4777 | "members": [ 4778 | { 4779 | "type": "STRING", 4780 | "value": "${" 4781 | }, 4782 | { 4783 | "type": "CHOICE", 4784 | "members": [ 4785 | { 4786 | "type": "SYMBOL", 4787 | "name": "math" 4788 | }, 4789 | { 4790 | "type": "BLANK" 4791 | } 4792 | ] 4793 | }, 4794 | { 4795 | "type": "STRING", 4796 | "value": "}" 4797 | } 4798 | ] 4799 | }, 4800 | "math_list": { 4801 | "type": "CHOICE", 4802 | "members": [ 4803 | { 4804 | "type": "SEQ", 4805 | "members": [ 4806 | { 4807 | "type": "STRING", 4808 | "value": "${" 4809 | }, 4810 | { 4811 | "type": "STRING", 4812 | "value": "|" 4813 | }, 4814 | { 4815 | "type": "STRING", 4816 | "value": "|" 4817 | }, 4818 | { 4819 | "type": "STRING", 4820 | "value": "}" 4821 | } 4822 | ] 4823 | }, 4824 | { 4825 | "type": "SEQ", 4826 | "members": [ 4827 | { 4828 | "type": "STRING", 4829 | "value": "${" 4830 | }, 4831 | { 4832 | "type": "STRING", 4833 | "value": "|" 4834 | }, 4835 | { 4836 | "type": "REPEAT", 4837 | "content": { 4838 | "type": "SEQ", 4839 | "members": [ 4840 | { 4841 | "type": "SYMBOL", 4842 | "name": "math" 4843 | }, 4844 | { 4845 | "type": "STRING", 4846 | "value": "|" 4847 | } 4848 | ] 4849 | } 4850 | }, 4851 | { 4852 | "type": "STRING", 4853 | "value": "}" 4854 | } 4855 | ] 4856 | } 4857 | ] 4858 | }, 4859 | "math": { 4860 | "type": "PREC_LEFT", 4861 | "value": 0, 4862 | "content": { 4863 | "type": "REPEAT1", 4864 | "content": { 4865 | "type": "CHOICE", 4866 | "members": [ 4867 | { 4868 | "type": "SYMBOL", 4869 | "name": "math_token" 4870 | }, 4871 | { 4872 | "type": "SYMBOL", 4873 | "name": "math_unary" 4874 | } 4875 | ] 4876 | } 4877 | } 4878 | }, 4879 | "math_token": { 4880 | "type": "PREC_LEFT", 4881 | "value": 0, 4882 | "content": { 4883 | "type": "CHOICE", 4884 | "members": [ 4885 | { 4886 | "type": "SEQ", 4887 | "members": [ 4888 | { 4889 | "type": "SYMBOL", 4890 | "name": "math_unary" 4891 | }, 4892 | { 4893 | "type": "FIELD", 4894 | "name": "sup", 4895 | "content": { 4896 | "type": "SYMBOL", 4897 | "name": "_math_sup" 4898 | } 4899 | }, 4900 | { 4901 | "type": "FIELD", 4902 | "name": "sub", 4903 | "content": { 4904 | "type": "SYMBOL", 4905 | "name": "_math_sub" 4906 | } 4907 | } 4908 | ] 4909 | }, 4910 | { 4911 | "type": "SEQ", 4912 | "members": [ 4913 | { 4914 | "type": "SYMBOL", 4915 | "name": "math_unary" 4916 | }, 4917 | { 4918 | "type": "FIELD", 4919 | "name": "sub", 4920 | "content": { 4921 | "type": "SYMBOL", 4922 | "name": "_math_sub" 4923 | } 4924 | }, 4925 | { 4926 | "type": "FIELD", 4927 | "name": "sup", 4928 | "content": { 4929 | "type": "SYMBOL", 4930 | "name": "_math_sup" 4931 | } 4932 | } 4933 | ] 4934 | }, 4935 | { 4936 | "type": "SEQ", 4937 | "members": [ 4938 | { 4939 | "type": "SYMBOL", 4940 | "name": "math_unary" 4941 | }, 4942 | { 4943 | "type": "FIELD", 4944 | "name": "sup", 4945 | "content": { 4946 | "type": "SYMBOL", 4947 | "name": "_math_sup" 4948 | } 4949 | } 4950 | ] 4951 | }, 4952 | { 4953 | "type": "SEQ", 4954 | "members": [ 4955 | { 4956 | "type": "SYMBOL", 4957 | "name": "math_unary" 4958 | }, 4959 | { 4960 | "type": "FIELD", 4961 | "name": "sub", 4962 | "content": { 4963 | "type": "SYMBOL", 4964 | "name": "_math_sub" 4965 | } 4966 | } 4967 | ] 4968 | } 4969 | ] 4970 | } 4971 | }, 4972 | "_math_sup": { 4973 | "type": "SEQ", 4974 | "members": [ 4975 | { 4976 | "type": "STRING", 4977 | "value": "^" 4978 | }, 4979 | { 4980 | "type": "SYMBOL", 4981 | "name": "_math_group" 4982 | } 4983 | ] 4984 | }, 4985 | "_math_sub": { 4986 | "type": "SEQ", 4987 | "members": [ 4988 | { 4989 | "type": "STRING", 4990 | "value": "_" 4991 | }, 4992 | { 4993 | "type": "SYMBOL", 4994 | "name": "_math_group" 4995 | } 4996 | ] 4997 | }, 4998 | "_math_group": { 4999 | "type": "CHOICE", 5000 | "members": [ 5001 | { 5002 | "type": "SYMBOL", 5003 | "name": "math_unary" 5004 | }, 5005 | { 5006 | "type": "SEQ", 5007 | "members": [ 5008 | { 5009 | "type": "STRING", 5010 | "value": "{" 5011 | }, 5012 | { 5013 | "type": "SYMBOL", 5014 | "name": "math" 5015 | }, 5016 | { 5017 | "type": "STRING", 5018 | "value": "}" 5019 | } 5020 | ] 5021 | } 5022 | ] 5023 | }, 5024 | "math_unary": { 5025 | "type": "CHOICE", 5026 | "members": [ 5027 | { 5028 | "type": "PATTERN", 5029 | "value": "[A-Za-z0-9]" 5030 | }, 5031 | { 5032 | "type": "PATTERN", 5033 | "value": "\\\\[!\"#$%&'()*+,./0-9:;<=>?@^_`{|}~-]" 5034 | }, 5035 | { 5036 | "type": "STRING", 5037 | "value": "\\\\" 5038 | }, 5039 | { 5040 | "type": "STRING", 5041 | "value": "\\ " 5042 | }, 5043 | { 5044 | "type": "PATTERN", 5045 | "value": "[+*/:=<>~'.,?`-]" 5046 | }, 5047 | { 5048 | "type": "SYMBOL", 5049 | "name": "math_cmd" 5050 | }, 5051 | { 5052 | "type": "SYMBOL", 5053 | "name": "math_embedding" 5054 | } 5055 | ] 5056 | }, 5057 | "math_embedding": { 5058 | "type": "SEQ", 5059 | "members": [ 5060 | { 5061 | "type": "SYMBOL", 5062 | "name": "_numbersign_after_nospace" 5063 | }, 5064 | { 5065 | "type": "SYMBOL", 5066 | "name": "identifier" 5067 | } 5068 | ] 5069 | }, 5070 | "whitespace": { 5071 | "type": "PATTERN", 5072 | "value": "\\s+" 5073 | }, 5074 | "cmd_name": { 5075 | "type": "PATTERN", 5076 | "value": "[A-Za-z][-A-Za-z0-9]*" 5077 | } 5078 | }, 5079 | "extras": [ 5080 | { 5081 | "type": "SYMBOL", 5082 | "name": "whitespace" 5083 | }, 5084 | { 5085 | "type": "SYMBOL", 5086 | "name": "comment" 5087 | } 5088 | ], 5089 | "conflicts": [ 5090 | [ 5091 | "binary_operator", 5092 | "unary_operator" 5093 | ] 5094 | ], 5095 | "precedences": [], 5096 | "externals": [ 5097 | { 5098 | "type": "SYMBOL", 5099 | "name": "literal_string" 5100 | }, 5101 | { 5102 | "type": "SYMBOL", 5103 | "name": "inline_token" 5104 | }, 5105 | { 5106 | "type": "SYMBOL", 5107 | "name": "_inline_token_compound" 5108 | }, 5109 | { 5110 | "type": "SYMBOL", 5111 | "name": "pkgname" 5112 | }, 5113 | { 5114 | "type": "SYMBOL", 5115 | "name": "_module_prefix" 5116 | }, 5117 | { 5118 | "type": "SYMBOL", 5119 | "name": "_inline_cmd_prefix" 5120 | }, 5121 | { 5122 | "type": "SYMBOL", 5123 | "name": "_block_cmd_prefix" 5124 | }, 5125 | { 5126 | "type": "SYMBOL", 5127 | "name": "_numbersign_after_nospace" 5128 | }, 5129 | { 5130 | "type": "SYMBOL", 5131 | "name": "_dummy" 5132 | } 5133 | ], 5134 | "inline": [], 5135 | "supertypes": [] 5136 | } 5137 | 5138 | --------------------------------------------------------------------------------