├── .github └── workflows │ └── build.yml ├── .gitignore ├── CONTRIBUTING.md ├── Cargo.toml ├── LICENSE ├── Makefile ├── README.md ├── binding.gyp ├── bindings ├── node │ ├── binding.cc │ └── index.js └── rust │ ├── build.rs │ └── lib.rs ├── docs ├── clip.mp4 ├── index.html ├── playground.js ├── playground.png ├── tree-sitter-erlang.wasm ├── tree-sitter.js └── tree-sitter.wasm ├── grammar.js ├── package.json ├── src ├── grammar.json ├── node-types.json ├── parser.c └── tree_sitter │ └── parser.h ├── test └── corpus │ ├── advent_of_code_2020.txt │ ├── comments.txt │ ├── expr_arithmetic.txt │ ├── expr_bit_string.txt │ ├── expr_block.txt │ ├── expr_case.txt │ ├── expr_exceptions.txt │ ├── expr_function_call.txt │ ├── expr_if.txt │ ├── expr_list.txt │ ├── expr_map.txt │ ├── expr_match.txt │ ├── expr_operators.txt │ ├── expr_receive.txt │ ├── expr_send.txt │ ├── expr_variable.txt │ ├── incomplete.txt │ ├── macros.txt │ ├── module_attribute.txt │ ├── module_function.txt │ ├── otp_lists.txt │ ├── playground.txt │ ├── term_atom.txt │ ├── term_binary_string.txt │ ├── term_char.txt │ ├── term_float.txt │ ├── term_fun.txt │ ├── term_integer.txt │ ├── term_list.txt │ ├── term_map.txt │ ├── term_record.txt │ ├── term_string.txt │ ├── term_tuple.txt │ └── types.txt └── yarn.lock /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | pull_request: 6 | branches: 7 | - "**:**" # For forks 8 | 9 | jobs: 10 | test: 11 | name: Run tests 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout code 15 | uses: actions/checkout@v2 16 | 17 | - name: Setup Node 18 | uses: actions/setup-node@v2-beta 19 | with: 20 | node-version: "12" 21 | 22 | - name: Display Node versions 23 | run: | 24 | node --version 25 | npm --version 26 | 27 | - name: Install dependencies 28 | run: npm install 29 | 30 | - name: Test corpus & parse examples 31 | run: npm run test 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.wasm 2 | package-lock.json 3 | node_modules 4 | build 5 | examples 6 | *.log 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to tree-sitter-erlang 2 | 3 | First of all, thanks for taking the time to contribute! :heart::tada::+1: 4 | 5 | There's 3 commands to run: 6 | 7 | 1. `make` -- this will reformat, compile, and test everything. It's fast enough 8 | that you can run it often. 9 | 10 | 2. `make web` -- to build and run the local web ui 11 | 12 | 3. `make publish` -- to prepare everything for merging and update the playground 13 | 14 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tree-sitter-erlang" 3 | description = "erlang grammar for the tree-sitter parsing library" 4 | version = "0.0.1" 5 | keywords = ["incremental", "parsing", "erlang"] 6 | categories = ["parsing", "text-editors"] 7 | repository = "https://github.com/tree-sitter/tree-sitter-javascript" 8 | edition = "2018" 9 | license = "MIT" 10 | 11 | build = "bindings/rust/build.rs" 12 | include = [ 13 | "bindings/rust/*", 14 | "grammar.js", 15 | "queries/*", 16 | "src/*", 17 | ] 18 | 19 | [lib] 20 | path = "bindings/rust/lib.rs" 21 | 22 | [dependencies] 23 | tree-sitter = "0.19.3" 24 | 25 | [build-dependencies] 26 | cc = "1.0" 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020-present Abstract Machines Lab Sweden AB 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TREE_SITTER=tree-sitter 2 | 3 | all: fmt gen test 4 | 5 | fmt: 6 | ./node_modules/.bin/prettier --write grammar.js 7 | 8 | .PHONY: test 9 | test: gen 10 | $(TREE_SITTER) test 11 | 12 | .PHONY: debug 13 | debug: gen 14 | $(TREE_SITTER) test -d 15 | 16 | .PHONY: gen 17 | gen: 18 | $(TREE_SITTER) generate 19 | 20 | .PHONY: deps 21 | deps: 22 | yarn 23 | 24 | .PHONY: web 25 | web: wasm 26 | $(TREE_SITTER) web-ui 27 | 28 | .PHONY: wasm 29 | wasm: 30 | $(TREE_SITTER) build-wasm 31 | 32 | .PHONY: publish 33 | publish: all wasm 34 | cp ./tree-sitter-erlang.wasm ./docs 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tree-sitter grammar for Erlang 2 | 3 | This repo has been **archived** since the Whatsapp fork is now in a lot better shape. Use that instead! 4 | 5 | See: https://github.com/WhatsApp/tree-sitter-erlang/ 6 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "tree_sitter_erlang_binding", 5 | "include_dirs": [ 6 | " 3 | #include "nan.h" 4 | 5 | using namespace v8; 6 | 7 | extern "C" TSLanguage * tree_sitter_erlang(); 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_erlang()); 21 | 22 | Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("erlang").ToLocalChecked()); 23 | Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); 24 | } 25 | 26 | NODE_MODULE(tree_sitter_erlang_binding, Init) 27 | 28 | } // namespace 29 | -------------------------------------------------------------------------------- /bindings/node/index.js: -------------------------------------------------------------------------------- 1 | try { 2 | module.exports = require("../../build/Release/tree_sitter_erlang_binding"); 3 | } catch (error1) { 4 | if (error1.code !== 'MODULE_NOT_FOUND') { 5 | throw error1; 6 | } 7 | try { 8 | module.exports = require("../../build/Debug/tree_sitter_erlang_binding"); 9 | } catch (error2) { 10 | if (error2.code !== 'MODULE_NOT_FOUND') { 11 | throw error2; 12 | } 13 | throw error1 14 | } 15 | } 16 | 17 | try { 18 | module.exports.nodeTypeInfo = require("../../src/node-types.json"); 19 | } catch (_) {} 20 | -------------------------------------------------------------------------------- /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 | /* 17 | let scanner_path = src_dir.join("scanner.c"); 18 | c_config.file(&scanner_path); 19 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 20 | */ 21 | 22 | c_config.compile("parser"); 23 | println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); 24 | 25 | // If your language uses an external scanner written in C++, 26 | // then include this block of code: 27 | 28 | /* 29 | let mut cpp_config = cc::Build::new(); 30 | cpp_config.cpp(true); 31 | cpp_config.include(&src_dir); 32 | cpp_config 33 | .flag_if_supported("-Wno-unused-parameter") 34 | .flag_if_supported("-Wno-unused-but-set-variable"); 35 | let scanner_path = src_dir.join("scanner.cc"); 36 | cpp_config.file(&scanner_path); 37 | cpp_config.compile("scanner"); 38 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 39 | */ 40 | } 41 | -------------------------------------------------------------------------------- /bindings/rust/lib.rs: -------------------------------------------------------------------------------- 1 | //! This crate provides erlang 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_erlang::language()).expect("Error loading erlang 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 | use tree_sitter::Language; 19 | 20 | extern "C" { 21 | fn tree_sitter_erlang() -> Language; 22 | } 23 | 24 | /// Get the tree-sitter [Language][] for this grammar. 25 | /// 26 | /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 27 | pub fn language() -> Language { 28 | unsafe { tree_sitter_erlang() } 29 | } 30 | 31 | /// The content of the [`node-types.json`][] file for this grammar. 32 | /// 33 | /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types 34 | pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); 35 | 36 | // Uncomment these to include any queries that this grammar contains 37 | 38 | // pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); 39 | // pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); 40 | // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); 41 | // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); 42 | 43 | #[cfg(test)] 44 | mod tests { 45 | #[test] 46 | fn test_can_load_grammar() { 47 | let mut parser = tree_sitter::Parser::new(); 48 | parser 49 | .set_language(super::language()) 50 | .expect("Error loading erlang language"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /docs/clip.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AbstractMachinesLab/tree-sitter-erlang/3a9c769444f08bbccce03845270efac0c641c5e7/docs/clip.mp4 -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

Erlang Tree-sitter Playground

9 | ⚙️ with ❤️ by @leostera 10 | 11 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /docs/playground.js: -------------------------------------------------------------------------------- 1 | let tree; 2 | 3 | (async () => { 4 | const CAPTURE_REGEX = /@\s*([\w\._-]+)/g; 5 | const COLORS_BY_INDEX = [ 6 | 'blue', 7 | 'chocolate', 8 | 'darkblue', 9 | 'darkcyan', 10 | 'darkgreen', 11 | 'darkred', 12 | 'darkslategray', 13 | 'dimgray', 14 | 'green', 15 | 'indigo', 16 | 'navy', 17 | 'red', 18 | 'sienna', 19 | ]; 20 | 21 | const scriptURL = document.currentScript.getAttribute('src'); 22 | 23 | const codeInput = document.getElementById('code-input'); 24 | const languageSelect = document.getElementById('language-select'); 25 | const loggingCheckbox = document.getElementById('logging-checkbox'); 26 | const outputContainer = document.getElementById('output-container'); 27 | const outputContainerScroll = document.getElementById('output-container-scroll'); 28 | const playgroundContainer = document.getElementById('playground-container'); 29 | const queryCheckbox = document.getElementById('query-checkbox'); 30 | const queryContainer = document.getElementById('query-container'); 31 | const queryInput = document.getElementById('query-input'); 32 | const updateTimeSpan = document.getElementById('update-time'); 33 | const languagesByName = {}; 34 | 35 | loadState(); 36 | 37 | await TreeSitter.init(); 38 | 39 | const parser = new TreeSitter(); 40 | const codeEditor = CodeMirror.fromTextArea(codeInput, { 41 | mode: "erlang", 42 | theme: "monokai", 43 | lineNumbers: true, 44 | showCursorWhenSelecting: true 45 | }); 46 | 47 | const queryEditor = CodeMirror.fromTextArea(queryInput, { 48 | theme: "monokai", 49 | mode: "scheme", 50 | lineNumbers: true, 51 | showCursorWhenSelecting: true 52 | }); 53 | 54 | const cluster = new Clusterize({ 55 | rows: [], 56 | noDataText: null, 57 | contentElem: outputContainer, 58 | scrollElem: outputContainerScroll 59 | }); 60 | const renderTreeOnCodeChange = debounce(renderTree, 50); 61 | const saveStateOnChange = debounce(saveState, 2000); 62 | const runTreeQueryOnChange = debounce(runTreeQuery, 50); 63 | 64 | let languageName = languageSelect.value; 65 | let treeRows = null; 66 | let treeRowHighlightedIndex = -1; 67 | let parseCount = 0; 68 | let isRendering = 0; 69 | let query; 70 | 71 | codeEditor.on('changes', handleCodeChange); 72 | codeEditor.on('viewportChange', runTreeQueryOnChange); 73 | codeEditor.on('cursorActivity', debounce(handleCursorMovement, 150)); 74 | queryEditor.on('changes', debounce(handleQueryChange, 150)); 75 | 76 | loggingCheckbox.addEventListener('change', handleLoggingChange); 77 | queryCheckbox.addEventListener('change', handleQueryEnableChange); 78 | languageSelect.addEventListener('change', handleLanguageChange); 79 | outputContainer.addEventListener('click', handleTreeClick); 80 | 81 | handleQueryEnableChange(); 82 | await handleLanguageChange() 83 | 84 | playgroundContainer.style.visibility = 'visible'; 85 | 86 | async function handleLanguageChange() { 87 | const newLanguageName = languageSelect.value; 88 | if (!languagesByName[newLanguageName]) { 89 | const url = `${LANGUAGE_BASE_URL}/tree-sitter-${newLanguageName}.wasm` 90 | languageSelect.disabled = true; 91 | try { 92 | languagesByName[newLanguageName] = await TreeSitter.Language.load(url); 93 | } catch (e) { 94 | console.error(e); 95 | languageSelect.value = languageName; 96 | return 97 | } finally { 98 | languageSelect.disabled = false; 99 | } 100 | } 101 | 102 | tree = null; 103 | languageName = newLanguageName; 104 | parser.setLanguage(languagesByName[newLanguageName]); 105 | handleCodeChange(); 106 | handleQueryChange(); 107 | } 108 | 109 | async function handleCodeChange(editor, changes) { 110 | const newText = codeEditor.getValue() + '\n'; 111 | const edits = tree && changes && changes.map(treeEditForEditorChange); 112 | 113 | const start = performance.now(); 114 | if (edits) { 115 | for (const edit of edits) { 116 | tree.edit(edit); 117 | } 118 | } 119 | const newTree = parser.parse(newText, tree); 120 | const duration = (performance.now() - start).toFixed(1); 121 | 122 | updateTimeSpan.innerText = `${duration} ms`; 123 | if (tree) tree.delete(); 124 | tree = newTree; 125 | parseCount++; 126 | renderTreeOnCodeChange(); 127 | runTreeQueryOnChange(); 128 | saveStateOnChange(); 129 | } 130 | 131 | async function renderTree() { 132 | isRendering++; 133 | const cursor = tree.walk(); 134 | 135 | let currentRenderCount = parseCount; 136 | let row = ''; 137 | let rows = []; 138 | let finishedRow = false; 139 | let visitedChildren = false; 140 | let indentLevel = 0; 141 | 142 | for (let i = 0;; i++) { 143 | if (i > 0 && i % 10000 === 0) { 144 | await new Promise(r => setTimeout(r, 0)); 145 | if (parseCount !== currentRenderCount) { 146 | cursor.delete(); 147 | isRendering--; 148 | return; 149 | } 150 | } 151 | 152 | let displayName; 153 | if (cursor.nodeIsMissing) { 154 | displayName = `MISSING ${cursor.nodeType}` 155 | } else if (cursor.nodeIsNamed) { 156 | displayName = cursor.nodeType; 157 | } 158 | 159 | if (visitedChildren) { 160 | if (displayName) { 161 | finishedRow = true; 162 | } 163 | 164 | if (cursor.gotoNextSibling()) { 165 | visitedChildren = false; 166 | } else if (cursor.gotoParent()) { 167 | visitedChildren = true; 168 | indentLevel--; 169 | } else { 170 | break; 171 | } 172 | } else { 173 | if (displayName) { 174 | if (finishedRow) { 175 | row += ''; 176 | rows.push(row); 177 | finishedRow = false; 178 | } 179 | const start = cursor.startPosition; 180 | const end = cursor.endPosition; 181 | const id = cursor.nodeId; 182 | let fieldName = cursor.currentFieldName(); 183 | if (fieldName) { 184 | fieldName += ': '; 185 | } else { 186 | fieldName = ''; 187 | } 188 | row = `
${' '.repeat(indentLevel)}${fieldName}${displayName} [${start.row}, ${start.column}] - [${end.row}, ${end.column}])`; 189 | finishedRow = true; 190 | } 191 | 192 | if (cursor.gotoFirstChild()) { 193 | visitedChildren = false; 194 | indentLevel++; 195 | } else { 196 | visitedChildren = true; 197 | } 198 | } 199 | } 200 | if (finishedRow) { 201 | row += '
'; 202 | rows.push(row); 203 | } 204 | 205 | cursor.delete(); 206 | cluster.update(rows); 207 | treeRows = rows; 208 | isRendering--; 209 | handleCursorMovement(); 210 | } 211 | 212 | function runTreeQuery(_, startRow, endRow) { 213 | if (endRow == null) { 214 | const viewport = codeEditor.getViewport(); 215 | startRow = viewport.from; 216 | endRow = viewport.to; 217 | } 218 | 219 | codeEditor.operation(() => { 220 | const marks = codeEditor.getAllMarks(); 221 | marks.forEach(m => m.clear()); 222 | 223 | if (tree && query) { 224 | const captures = query.captures( 225 | tree.rootNode, 226 | {row: startRow, column: 0}, 227 | {row: endRow, column: 0}, 228 | ); 229 | let lastNodeId; 230 | for (const {name, node} of captures) { 231 | if (node.id === lastNodeId) continue; 232 | lastNodeId = node.id; 233 | const {startPosition, endPosition} = node; 234 | codeEditor.markText( 235 | {line: startPosition.row, ch: startPosition.column}, 236 | {line: endPosition.row, ch: endPosition.column}, 237 | { 238 | inclusiveLeft: true, 239 | inclusiveRight: true, 240 | css: `color: ${colorForCaptureName(name)}` 241 | } 242 | ); 243 | } 244 | } 245 | }); 246 | } 247 | 248 | function handleQueryChange() { 249 | if (query) { 250 | query.delete(); 251 | query.deleted = true; 252 | query = null; 253 | } 254 | 255 | queryEditor.operation(() => { 256 | queryEditor.getAllMarks().forEach(m => m.clear()); 257 | if (!queryCheckbox.checked) return; 258 | 259 | const queryText = queryEditor.getValue(); 260 | 261 | try { 262 | query = parser.getLanguage().query(queryText); 263 | let match; 264 | 265 | let row = 0; 266 | queryEditor.eachLine((line) => { 267 | while (match = CAPTURE_REGEX.exec(line.text)) { 268 | queryEditor.markText( 269 | {line: row, ch: match.index}, 270 | {line: row, ch: match.index + match[0].length}, 271 | { 272 | inclusiveLeft: true, 273 | inclusiveRight: true, 274 | css: `color: ${colorForCaptureName(match[1])}` 275 | } 276 | ); 277 | } 278 | row++; 279 | }); 280 | } catch (error) { 281 | const startPosition = queryEditor.posFromIndex(error.index); 282 | const endPosition = { 283 | line: startPosition.line, 284 | ch: startPosition.ch + (error.length || Infinity) 285 | }; 286 | 287 | if (error.index === queryText.length) { 288 | if (startPosition.ch > 0) { 289 | startPosition.ch--; 290 | } else if (startPosition.row > 0) { 291 | startPosition.row--; 292 | startPosition.column = Infinity; 293 | } 294 | } 295 | 296 | queryEditor.markText( 297 | startPosition, 298 | endPosition, 299 | { 300 | className: 'query-error', 301 | inclusiveLeft: true, 302 | inclusiveRight: true, 303 | attributes: {title: error.message} 304 | } 305 | ); 306 | } 307 | }); 308 | 309 | runTreeQuery(); 310 | saveQueryState(); 311 | } 312 | 313 | function handleCursorMovement() { 314 | if (isRendering) return; 315 | 316 | const selection = codeEditor.getDoc().listSelections()[0]; 317 | let start = {row: selection.anchor.line, column: selection.anchor.ch}; 318 | let end = {row: selection.head.line, column: selection.head.ch}; 319 | if ( 320 | start.row > end.row || 321 | ( 322 | start.row === end.row && 323 | start.column > end.column 324 | ) 325 | ) { 326 | let swap = end; 327 | end = start; 328 | start = swap; 329 | } 330 | const node = tree.rootNode.namedDescendantForPosition(start, end); 331 | if (treeRows) { 332 | if (treeRowHighlightedIndex !== -1) { 333 | const row = treeRows[treeRowHighlightedIndex]; 334 | if (row) treeRows[treeRowHighlightedIndex] = row.replace('highlighted', 'plain'); 335 | } 336 | treeRowHighlightedIndex = treeRows.findIndex(row => row.includes(`data-id=${node.id}`)); 337 | if (treeRowHighlightedIndex !== -1) { 338 | const row = treeRows[treeRowHighlightedIndex]; 339 | if (row) treeRows[treeRowHighlightedIndex] = row.replace('plain', 'highlighted'); 340 | } 341 | cluster.update(treeRows); 342 | const lineHeight = cluster.options.item_height; 343 | const scrollTop = outputContainerScroll.scrollTop; 344 | const containerHeight = outputContainerScroll.clientHeight; 345 | const offset = treeRowHighlightedIndex * lineHeight; 346 | if (scrollTop > offset - 20) { 347 | $(outputContainerScroll).animate({scrollTop: offset - 20}, 150); 348 | } else if (scrollTop < offset + lineHeight + 40 - containerHeight) { 349 | $(outputContainerScroll).animate({scrollTop: offset - containerHeight + 40}, 150); 350 | } 351 | } 352 | } 353 | 354 | function handleTreeClick(event) { 355 | if (event.target.tagName === 'A') { 356 | event.preventDefault(); 357 | const [startRow, startColumn, endRow, endColumn] = event 358 | .target 359 | .dataset 360 | .range 361 | .split(',') 362 | .map(n => parseInt(n)); 363 | codeEditor.focus(); 364 | codeEditor.setSelection( 365 | {line: startRow, ch: startColumn}, 366 | {line: endRow, ch: endColumn} 367 | ); 368 | } 369 | } 370 | 371 | function handleLoggingChange() { 372 | if (loggingCheckbox.checked) { 373 | parser.setLogger((message, lexing) => { 374 | if (lexing) { 375 | console.log(" ", message) 376 | } else { 377 | console.log(message) 378 | } 379 | }); 380 | } else { 381 | parser.setLogger(null); 382 | } 383 | } 384 | 385 | function handleQueryEnableChange() { 386 | if (queryCheckbox.checked) { 387 | queryContainer.style.visibility = ''; 388 | queryContainer.style.position = ''; 389 | } else { 390 | queryContainer.style.visibility = 'hidden'; 391 | queryContainer.style.position = 'absolute'; 392 | } 393 | handleQueryChange(); 394 | } 395 | 396 | function treeEditForEditorChange(change) { 397 | const oldLineCount = change.removed.length; 398 | const newLineCount = change.text.length; 399 | const lastLineLength = change.text[newLineCount - 1].length; 400 | 401 | const startPosition = {row: change.from.line, column: change.from.ch}; 402 | const oldEndPosition = {row: change.to.line, column: change.to.ch}; 403 | const newEndPosition = { 404 | row: startPosition.row + newLineCount - 1, 405 | column: newLineCount === 1 406 | ? startPosition.column + lastLineLength 407 | : lastLineLength 408 | }; 409 | 410 | const startIndex = codeEditor.indexFromPos(change.from); 411 | let newEndIndex = startIndex + newLineCount - 1; 412 | let oldEndIndex = startIndex + oldLineCount - 1; 413 | for (let i = 0; i < newLineCount; i++) newEndIndex += change.text[i].length; 414 | for (let i = 0; i < oldLineCount; i++) oldEndIndex += change.removed[i].length; 415 | 416 | return { 417 | startIndex, oldEndIndex, newEndIndex, 418 | startPosition, oldEndPosition, newEndPosition 419 | }; 420 | } 421 | 422 | function colorForCaptureName(capture) { 423 | const id = query.captureNames.indexOf(capture); 424 | return COLORS_BY_INDEX[id % COLORS_BY_INDEX.length]; 425 | } 426 | 427 | function loadState() { 428 | const language = localStorage.getItem("language"); 429 | const query = localStorage.getItem("query"); 430 | const queryEnabled = localStorage.getItem("queryEnabled"); 431 | if (language != null && query != null) { 432 | queryInput.value = query; 433 | languageSelect.value = language; 434 | queryCheckbox.checked = (queryEnabled === 'true'); 435 | } 436 | } 437 | 438 | function saveState() { 439 | localStorage.setItem("language", languageSelect.value); 440 | saveQueryState(); 441 | } 442 | 443 | function saveQueryState() { 444 | localStorage.setItem("queryEnabled", queryCheckbox.checked); 445 | localStorage.setItem("query", queryEditor.getValue()); 446 | } 447 | 448 | function debounce(func, wait, immediate) { 449 | var timeout; 450 | return function() { 451 | var context = this, args = arguments; 452 | var later = function() { 453 | timeout = null; 454 | if (!immediate) func.apply(context, args); 455 | }; 456 | var callNow = immediate && !timeout; 457 | clearTimeout(timeout); 458 | timeout = setTimeout(later, wait); 459 | if (callNow) func.apply(context, args); 460 | }; 461 | } 462 | })(); 463 | -------------------------------------------------------------------------------- /docs/playground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AbstractMachinesLab/tree-sitter-erlang/3a9c769444f08bbccce03845270efac0c641c5e7/docs/playground.png -------------------------------------------------------------------------------- /docs/tree-sitter-erlang.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AbstractMachinesLab/tree-sitter-erlang/3a9c769444f08bbccce03845270efac0c641c5e7/docs/tree-sitter-erlang.wasm -------------------------------------------------------------------------------- /docs/tree-sitter.js: -------------------------------------------------------------------------------- 1 | var Module=void 0!==Module?Module:{};!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():window.TreeSitter=t()}(0,function(){var e,t={};for(e in Module)Module.hasOwnProperty(e)&&(t[e]=Module[e]);var r,n,s=[],o=function(e,t){throw t},_=!1,a=!1;_="object"==typeof window,a="function"==typeof importScripts,r="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,n=!_&&!r&&!a;var i,u,l,d,c="";r?(c=a?require("path").dirname(c)+"/":__dirname+"/",i=function(e,t){return l||(l=require("fs")),d||(d=require("path")),e=d.normalize(e),l.readFileSync(e,t?null:"utf8")},u=function(e){var t=i(e,!0);return t.buffer||(t=new Uint8Array(t)),L(t.buffer),t},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),s=process.argv.slice(2),"undefined"!=typeof module&&(module.exports=Module),process.on("uncaughtException",function(e){if(!(e instanceof Ue))throw e}),process.on("unhandledRejection",fe),o=function(e){process.exit(e)},Module.inspect=function(){return"[Emscripten Module object]"}):n?("undefined"!=typeof read&&(i=function(e){return read(e)}),u=function(e){var t;return"function"==typeof readbuffer?new Uint8Array(readbuffer(e)):(L("object"==typeof(t=read(e,"binary"))),t)},"undefined"!=typeof scriptArgs?s=scriptArgs:void 0!==arguments&&(s=arguments),"function"==typeof quit&&(o=function(e){quit(e)}),"undefined"!=typeof print&&("undefined"==typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!=typeof printErr?printErr:print)):(_||a)&&(a?c=self.location.href:document.currentScript&&(c=document.currentScript.src),c=0!==c.indexOf("blob:")?c.substr(0,c.lastIndexOf("/")+1):"",i=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.send(null),t.responseText},a&&(u=function(e){var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),function(e,t,r){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(){200==n.status||0==n.status&&n.response?t(n.response):r()},n.onerror=r,n.send(null)});Module.print||console.log.bind(console);var m=Module.printErr||console.warn.bind(console);for(e in t)t.hasOwnProperty(e)&&(Module[e]=t[e]);t=null,Module.arguments&&(s=Module.arguments),Module.thisProgram&&Module.thisProgram,Module.quit&&(o=Module.quit);var f=16;function p(e){var t=z[Q>>2],r=t+e+15&-16;return z[Q>>2]=r,t}function h(e,t){return t||(t=f),Math.ceil(e/t)*t}function M(e){switch(e){case"i1":case"i8":return 1;case"i16":return 2;case"i32":return 4;case"i64":return 8;case"float":return 4;case"double":return 8;default:if("*"===e[e.length-1])return 4;if("i"===e[0]){var t=Number(e.substr(1));return L(t%8==0,"getNativeTypeSize invalid bits "+t+", type "+e),t/8}return 0}}var g={nextHandle:1,loadedLibs:{"-1":{refcount:1/0,name:"__self__",module:Module,global:!0}},loadedLibNames:{__self__:-1}};function w(e){return 0==e.indexOf("dynCall_")||-1!=["setTempRet0","getTempRet0","stackAlloc","stackSave","stackRestore","__growWasmMemory","__heap_base","__data_end"].indexOf(e)?e:"_"+e}function y(e,t){t=t||{global:!0,nodelete:!0};var r,n=g.loadedLibNames[e];if(n)return r=g.loadedLibs[n],t.global&&!r.global&&(r.global=!0,"loading"!==r.module&&a(r.module)),t.nodelete&&r.refcount!==1/0&&(r.refcount=1/0),r.refcount++,t.loadAsync?Promise.resolve(n):n;function s(e){if(t.fs){var r=t.fs.readFile(e,{encoding:"binary"});return r instanceof Uint8Array||(r=new Uint8Array(lib_data)),t.loadAsync?Promise.resolve(r):r}return t.loadAsync?(n=e,fetch(n,{credentials:"same-origin"}).then(function(e){if(!e.ok)throw"failed to load binary file at '"+n+"'";return e.arrayBuffer()}).then(function(e){return new Uint8Array(e)})):u(e);var n}function o(e){return E(e,t)}function _(){if(void 0!==Module.preloadedWasm&&void 0!==Module.preloadedWasm[e]){var r=Module.preloadedWasm[e];return t.loadAsync?Promise.resolve(r):r}return t.loadAsync?s(e).then(function(e){return o(e)}):o(s(e))}function a(e){for(var t in e)if(e.hasOwnProperty(t)){var r=w(t);Module.hasOwnProperty(r)||(Module[r]=e[t])}}function i(e){r.global&&a(e),r.module=e}return n=g.nextHandle++,r={refcount:t.nodelete?1/0:1,name:e,module:"loading",global:t.global},g.loadedLibNames[e]=n,g.loadedLibs[n]=r,t.loadAsync?_().then(function(e){return i(e),n}):(i(_()),n)}function b(e,t,r,n){var s={};for(var o in e){var _=e[o];"object"==typeof _&&(_=_.value),"number"==typeof _&&(_+=t),s[o]=_,n&&(n["_"+o]=_)}return s}function E(e,t){L(1836278016==new Uint32Array(new Uint8Array(e.subarray(0,24)).buffer)[0],"need to see wasm magic number"),L(0===e[8],"need the dylink section to be first");var r=9;function n(){for(var t=0,n=1;;){var s=e[r++];if(t+=(127&s)*n,n*=128,!(128&s))break}return t}n();L(6===e[r]),L(e[++r]==="d".charCodeAt(0)),L(e[++r]==="y".charCodeAt(0)),L(e[++r]==="l".charCodeAt(0)),L(e[++r]==="i".charCodeAt(0)),L(e[++r]==="n".charCodeAt(0)),L(e[++r]==="k".charCodeAt(0)),r++;for(var s=n(),o=n(),_=n(),a=n(),i=n(),u=[],l=0;l=0,a=0;return e[t]=function(){if(!a){var e=m(n,0,_);a=N(e,o)}return a}}return e[t]=function(){return m(t).apply(null,arguments)}}}),g={global:{NaN:NaN,Infinity:1/0},"global.Math":Math,env:M,wasi_snapshot_preview1:M};function y(e,t){var n=b(e.exports,r,0,t),s=n.__post_instantiate;return s&&(ne?s():ee.push(s)),n}return t.loadAsync?WebAssembly.instantiate(e,g).then(function(e){return y(e.instance,c)}):y(new WebAssembly.Instance(new WebAssembly.Module(e),g),c)}return t.loadAsync?Promise.all(u.map(function(e){return y(e,t)})).then(function(){return p()}):(u.forEach(function(e){y(e,t)}),p())}Module.loadWebAssemblyModule=E;var v,I=[];function S(e,t){var r,n=T;if(!v){v=new WeakMap;for(var s=0;s>0]=t;break;case"i16":H[e>>1]=t;break;case"i32":z[e>>2]=t;break;case"i64":Ee=[t>>>0,(be=t,+oe(be)>=1?be>0?(0|ie(+ae(be/4294967296),4294967295))>>>0:~~+_e((be-+(~~be>>>0))/4294967296)>>>0:0)],z[e>>2]=Ee[0],z[e+4>>2]=Ee[1];break;case"float":K[e>>2]=t;break;case"double":G[e>>3]=t;break;default:fe("invalid type for setValue: "+r)}}function q(e,t,r){switch("*"===(t=t||"i8").charAt(t.length-1)&&(t="i32"),t){case"i1":case"i8":return D[e>>0];case"i16":return H[e>>1];case"i32":case"i64":return z[e>>2];case"float":return K[e>>2];case"double":return G[e>>3];default:fe("invalid type for getValue: "+t)}return null}P=h(P,1),Module.wasmBinary&&(x=Module.wasmBinary),Module.noExitRuntime&&(A=Module.noExitRuntime),"object"!=typeof WebAssembly&&fe("no native wasm support detected");var T=new WebAssembly.Table({initial:12,element:"anyfunc"}),$=!1;function L(e,t){e||fe("Assertion failed: "+t)}var W=3;function Z(e){return ne?Te(e):p(e)}var F="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function O(e,t,r){for(var n=t+r,s=t;e[s]&&!(s>=n);)++s;if(s-t>16&&e.subarray&&F)return F.decode(e.subarray(t,s));for(var o="";t>10,56320|1023&u)}}else o+=String.fromCharCode((31&_)<<6|a)}else o+=String.fromCharCode(_)}return o}function j(e,t){return e?O(B,e,t):""}var U,D,B,H,z,K,G;function X(e){U=e,Module.HEAP8=D=new Int8Array(e),Module.HEAP16=H=new Int16Array(e),Module.HEAP32=z=new Int32Array(e),Module.HEAPU8=B=new Uint8Array(e),Module.HEAPU16=new Uint16Array(e),Module.HEAPU32=new Uint32Array(e),Module.HEAPF32=K=new Float32Array(e),Module.HEAPF64=G=new Float64Array(e)}var Q=8016,V=Module.INITIAL_MEMORY||33554432;function Y(e){for(;e.length>0;){var t=e.shift();if("function"!=typeof t){var r=t.func;"number"==typeof r?void 0===t.arg?Module.dynCall_v(r):Module.dynCall_vi(r,t.arg):r(void 0===t.arg?null:t.arg)}else t(Module)}}(C=Module.wasmMemory?Module.wasmMemory:new WebAssembly.Memory({initial:V/65536,maximum:32768}))&&(U=C.buffer),V=U.byteLength,X(U),z[Q>>2]=5251056;var J=[],ee=[],te=[],re=[],ne=!1;function se(e){J.unshift(e)}var oe=Math.abs,_e=Math.ceil,ae=Math.floor,ie=Math.min,ue=0,le=null,de=null;function ce(e){ue++,Module.monitorRunDependencies&&Module.monitorRunDependencies(ue)}function me(e){if(ue--,Module.monitorRunDependencies&&Module.monitorRunDependencies(ue),0==ue&&(null!==le&&(clearInterval(le),le=null),de)){var t=de;de=null,t()}}function fe(e){throw Module.onAbort&&Module.onAbort(e),m(e+=""),$=!0,1,e="abort("+e+"). Build with -s ASSERTIONS=1 for more info.",new WebAssembly.RuntimeError(e)}function pe(e,t){return String.prototype.startsWith?e.startsWith(t):0===e.indexOf(t)}Module.preloadedImages={},Module.preloadedAudios={},Module.preloadedWasm={},se(function(){if(Module.dynamicLibraries&&Module.dynamicLibraries.length>0&&!u)return ce(),void Promise.all(Module.dynamicLibraries.map(function(e){return y(e,{loadAsync:!0,global:!0,nodelete:!0})})).then(function(){me()});var e;(e=Module.dynamicLibraries)&&e.forEach(function(e){y(e,{global:!0,nodelete:!0})})});var he="data:application/octet-stream;base64,";function Me(e){return pe(e,he)}var ge="file://";function we(e){return pe(e,ge)}var ye,be,Ee,ve,Ie="tree-sitter.wasm";function Se(){try{if(x)return new Uint8Array(x);if(u)return u(Ie);throw"both async and sync fetching of the wasm failed"}catch(e){fe(e)}}function Ne(){fe()}Me(Ie)||(ye=Ie,Ie=Module.locateFile?Module.locateFile(ye,c):c+ye),ee.push({func:function(){Fe()}},{func:function(){qe()}}),Module._abort=Ne,ve=r?function(){var e=process.hrtime();return 1e3*e[0]+e[1]/1e6}:"undefined"!=typeof dateNow?dateNow:function(){return performance.now()};var xe=!0;function Ae(e){try{return C.grow(e-U.byteLength+65535>>>16),X(C.buffer),1}catch(e){}}function Ce(e,t,r){if(at){const e=j(r);at(e,0!==t)}}var ke,Pe=P,Re={__memory_base:1024,__stack_pointer:5251056,__table_base:1,abort:Ne,clock_gettime:function(e,t){var r,n;if(0===e)r=Date.now();else{if(1!==e&&4!==e||!xe)return n=28,z[$e()>>2]=n,-1;r=ve()}return z[t>>2]=r/1e3|0,z[t+4>>2]=r%1e3*1e3*1e3|0,0},emscripten_memcpy_big:function(e,t,r){B.copyWithin(e,t,t+r)},emscripten_resize_heap:function(e){e>>>=0;var t=B.length;if(e>2147483648)return!1;for(var r,n,s=1;s<=4;s*=2){var o=t*(1+.2/s);if(o=Math.min(o,e+100663296),Ae(Math.min(2147483648,((r=Math.max(16777216,e,o))%(n=65536)>0&&(r+=n-r%n),r))))return!0}return!1},exit:function(e){Be(e)},fp$tree_sitter_log_callback$viii:function(){return Module._fp$tree_sitter_log_callback$viii.apply(null,arguments)},memory:C,setTempRet0:function(e){k(0|e)},table:T,tree_sitter_parse_callback:function(e,t,r,n,s){var o=_t(t,{row:r,column:n});"string"==typeof o?(R(s,o.length,"i32"),function(e,t,r){if(void 0===r&&(r=2147483647),r<2)return 0;for(var n=(r-=2)<2*e.length?r/2:e.length,s=0;s>1]=o,t+=2}H[t>>1]=0}(o,e,10240)):R(s,0,"i32")}},qe=(function(){var e={env:Re,wasi_snapshot_preview1:Re};function t(e,t){var r=e.exports;r=b(r,P),Module.asm=r,me()}function r(e){t(e.instance)}function n(t){return(x||!_&&!a||"function"!=typeof fetch||we(Ie)?new Promise(function(e,t){e(Se())}):fetch(Ie,{credentials:"same-origin"}).then(function(e){if(!e.ok)throw"failed to load wasm binary file at '"+Ie+"'";return e.arrayBuffer()}).catch(function(){return Se()})).then(function(t){return WebAssembly.instantiate(t,e)}).then(t,function(e){m("failed to asynchronously prepare wasm: "+e),fe(e)})}if(ce(),Module.instantiateWasm)try{return Module.instantiateWasm(e,t)}catch(e){return m("Module.instantiateWasm callback failed with error: "+e),!1}(function(){if(x||"function"!=typeof WebAssembly.instantiateStreaming||Me(Ie)||we(Ie)||"function"!=typeof fetch)return n(r);fetch(Ie,{credentials:"same-origin"}).then(function(t){return WebAssembly.instantiateStreaming(t,e).then(r,function(e){return m("wasm streaming compile failed: "+e),m("falling back to ArrayBuffer instantiation"),n(r)})})})()}(),Module.___wasm_call_ctors=function(){return(qe=Module.___wasm_call_ctors=Module.asm.__wasm_call_ctors).apply(null,arguments)}),Te=(Module._calloc=function(){return(Module._calloc=Module.asm.calloc).apply(null,arguments)},Module._ts_language_symbol_count=function(){return(Module._ts_language_symbol_count=Module.asm.ts_language_symbol_count).apply(null,arguments)},Module._ts_language_version=function(){return(Module._ts_language_version=Module.asm.ts_language_version).apply(null,arguments)},Module._ts_language_field_count=function(){return(Module._ts_language_field_count=Module.asm.ts_language_field_count).apply(null,arguments)},Module._ts_language_symbol_name=function(){return(Module._ts_language_symbol_name=Module.asm.ts_language_symbol_name).apply(null,arguments)},Module._ts_language_symbol_type=function(){return(Module._ts_language_symbol_type=Module.asm.ts_language_symbol_type).apply(null,arguments)},Module._ts_language_field_name_for_id=function(){return(Module._ts_language_field_name_for_id=Module.asm.ts_language_field_name_for_id).apply(null,arguments)},Module._memcpy=function(){return(Module._memcpy=Module.asm.memcpy).apply(null,arguments)},Module._free=function(){return(Module._free=Module.asm.free).apply(null,arguments)},Module._malloc=function(){return(Te=Module._malloc=Module.asm.malloc).apply(null,arguments)}),$e=(Module._ts_parser_delete=function(){return(Module._ts_parser_delete=Module.asm.ts_parser_delete).apply(null,arguments)},Module._ts_parser_set_language=function(){return(Module._ts_parser_set_language=Module.asm.ts_parser_set_language).apply(null,arguments)},Module._ts_parser_timeout_micros=function(){return(Module._ts_parser_timeout_micros=Module.asm.ts_parser_timeout_micros).apply(null,arguments)},Module._ts_parser_set_timeout_micros=function(){return(Module._ts_parser_set_timeout_micros=Module.asm.ts_parser_set_timeout_micros).apply(null,arguments)},Module._memcmp=function(){return(Module._memcmp=Module.asm.memcmp).apply(null,arguments)},Module._ts_query_new=function(){return(Module._ts_query_new=Module.asm.ts_query_new).apply(null,arguments)},Module._iswspace=function(){return(Module._iswspace=Module.asm.iswspace).apply(null,arguments)},Module._ts_query_delete=function(){return(Module._ts_query_delete=Module.asm.ts_query_delete).apply(null,arguments)},Module._iswalnum=function(){return(Module._iswalnum=Module.asm.iswalnum).apply(null,arguments)},Module._ts_query_pattern_count=function(){return(Module._ts_query_pattern_count=Module.asm.ts_query_pattern_count).apply(null,arguments)},Module._ts_query_capture_count=function(){return(Module._ts_query_capture_count=Module.asm.ts_query_capture_count).apply(null,arguments)},Module._ts_query_string_count=function(){return(Module._ts_query_string_count=Module.asm.ts_query_string_count).apply(null,arguments)},Module._ts_query_capture_name_for_id=function(){return(Module._ts_query_capture_name_for_id=Module.asm.ts_query_capture_name_for_id).apply(null,arguments)},Module._ts_query_string_value_for_id=function(){return(Module._ts_query_string_value_for_id=Module.asm.ts_query_string_value_for_id).apply(null,arguments)},Module._ts_query_predicates_for_pattern=function(){return(Module._ts_query_predicates_for_pattern=Module.asm.ts_query_predicates_for_pattern).apply(null,arguments)},Module._ts_tree_delete=function(){return(Module._ts_tree_delete=Module.asm.ts_tree_delete).apply(null,arguments)},Module._ts_init=function(){return(Module._ts_init=Module.asm.ts_init).apply(null,arguments)},Module._ts_parser_new_wasm=function(){return(Module._ts_parser_new_wasm=Module.asm.ts_parser_new_wasm).apply(null,arguments)},Module._ts_parser_enable_logger_wasm=function(){return(Module._ts_parser_enable_logger_wasm=Module.asm.ts_parser_enable_logger_wasm).apply(null,arguments)},Module._ts_parser_parse_wasm=function(){return(Module._ts_parser_parse_wasm=Module.asm.ts_parser_parse_wasm).apply(null,arguments)},Module._ts_tree_root_node_wasm=function(){return(Module._ts_tree_root_node_wasm=Module.asm.ts_tree_root_node_wasm).apply(null,arguments)},Module._ts_tree_edit_wasm=function(){return(Module._ts_tree_edit_wasm=Module.asm.ts_tree_edit_wasm).apply(null,arguments)},Module._ts_tree_get_changed_ranges_wasm=function(){return(Module._ts_tree_get_changed_ranges_wasm=Module.asm.ts_tree_get_changed_ranges_wasm).apply(null,arguments)},Module._ts_tree_cursor_new_wasm=function(){return(Module._ts_tree_cursor_new_wasm=Module.asm.ts_tree_cursor_new_wasm).apply(null,arguments)},Module._ts_tree_cursor_delete_wasm=function(){return(Module._ts_tree_cursor_delete_wasm=Module.asm.ts_tree_cursor_delete_wasm).apply(null,arguments)},Module._ts_tree_cursor_reset_wasm=function(){return(Module._ts_tree_cursor_reset_wasm=Module.asm.ts_tree_cursor_reset_wasm).apply(null,arguments)},Module._ts_tree_cursor_goto_first_child_wasm=function(){return(Module._ts_tree_cursor_goto_first_child_wasm=Module.asm.ts_tree_cursor_goto_first_child_wasm).apply(null,arguments)},Module._ts_tree_cursor_goto_next_sibling_wasm=function(){return(Module._ts_tree_cursor_goto_next_sibling_wasm=Module.asm.ts_tree_cursor_goto_next_sibling_wasm).apply(null,arguments)},Module._ts_tree_cursor_goto_parent_wasm=function(){return(Module._ts_tree_cursor_goto_parent_wasm=Module.asm.ts_tree_cursor_goto_parent_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_type_id_wasm=function(){return(Module._ts_tree_cursor_current_node_type_id_wasm=Module.asm.ts_tree_cursor_current_node_type_id_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_is_named_wasm=function(){return(Module._ts_tree_cursor_current_node_is_named_wasm=Module.asm.ts_tree_cursor_current_node_is_named_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_is_missing_wasm=function(){return(Module._ts_tree_cursor_current_node_is_missing_wasm=Module.asm.ts_tree_cursor_current_node_is_missing_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_id_wasm=function(){return(Module._ts_tree_cursor_current_node_id_wasm=Module.asm.ts_tree_cursor_current_node_id_wasm).apply(null,arguments)},Module._ts_tree_cursor_start_position_wasm=function(){return(Module._ts_tree_cursor_start_position_wasm=Module.asm.ts_tree_cursor_start_position_wasm).apply(null,arguments)},Module._ts_tree_cursor_end_position_wasm=function(){return(Module._ts_tree_cursor_end_position_wasm=Module.asm.ts_tree_cursor_end_position_wasm).apply(null,arguments)},Module._ts_tree_cursor_start_index_wasm=function(){return(Module._ts_tree_cursor_start_index_wasm=Module.asm.ts_tree_cursor_start_index_wasm).apply(null,arguments)},Module._ts_tree_cursor_end_index_wasm=function(){return(Module._ts_tree_cursor_end_index_wasm=Module.asm.ts_tree_cursor_end_index_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_field_id_wasm=function(){return(Module._ts_tree_cursor_current_field_id_wasm=Module.asm.ts_tree_cursor_current_field_id_wasm).apply(null,arguments)},Module._ts_tree_cursor_current_node_wasm=function(){return(Module._ts_tree_cursor_current_node_wasm=Module.asm.ts_tree_cursor_current_node_wasm).apply(null,arguments)},Module._ts_node_symbol_wasm=function(){return(Module._ts_node_symbol_wasm=Module.asm.ts_node_symbol_wasm).apply(null,arguments)},Module._ts_node_child_count_wasm=function(){return(Module._ts_node_child_count_wasm=Module.asm.ts_node_child_count_wasm).apply(null,arguments)},Module._ts_node_named_child_count_wasm=function(){return(Module._ts_node_named_child_count_wasm=Module.asm.ts_node_named_child_count_wasm).apply(null,arguments)},Module._ts_node_child_wasm=function(){return(Module._ts_node_child_wasm=Module.asm.ts_node_child_wasm).apply(null,arguments)},Module._ts_node_named_child_wasm=function(){return(Module._ts_node_named_child_wasm=Module.asm.ts_node_named_child_wasm).apply(null,arguments)},Module._ts_node_child_by_field_id_wasm=function(){return(Module._ts_node_child_by_field_id_wasm=Module.asm.ts_node_child_by_field_id_wasm).apply(null,arguments)},Module._ts_node_next_sibling_wasm=function(){return(Module._ts_node_next_sibling_wasm=Module.asm.ts_node_next_sibling_wasm).apply(null,arguments)},Module._ts_node_prev_sibling_wasm=function(){return(Module._ts_node_prev_sibling_wasm=Module.asm.ts_node_prev_sibling_wasm).apply(null,arguments)},Module._ts_node_next_named_sibling_wasm=function(){return(Module._ts_node_next_named_sibling_wasm=Module.asm.ts_node_next_named_sibling_wasm).apply(null,arguments)},Module._ts_node_prev_named_sibling_wasm=function(){return(Module._ts_node_prev_named_sibling_wasm=Module.asm.ts_node_prev_named_sibling_wasm).apply(null,arguments)},Module._ts_node_parent_wasm=function(){return(Module._ts_node_parent_wasm=Module.asm.ts_node_parent_wasm).apply(null,arguments)},Module._ts_node_descendant_for_index_wasm=function(){return(Module._ts_node_descendant_for_index_wasm=Module.asm.ts_node_descendant_for_index_wasm).apply(null,arguments)},Module._ts_node_named_descendant_for_index_wasm=function(){return(Module._ts_node_named_descendant_for_index_wasm=Module.asm.ts_node_named_descendant_for_index_wasm).apply(null,arguments)},Module._ts_node_descendant_for_position_wasm=function(){return(Module._ts_node_descendant_for_position_wasm=Module.asm.ts_node_descendant_for_position_wasm).apply(null,arguments)},Module._ts_node_named_descendant_for_position_wasm=function(){return(Module._ts_node_named_descendant_for_position_wasm=Module.asm.ts_node_named_descendant_for_position_wasm).apply(null,arguments)},Module._ts_node_start_point_wasm=function(){return(Module._ts_node_start_point_wasm=Module.asm.ts_node_start_point_wasm).apply(null,arguments)},Module._ts_node_end_point_wasm=function(){return(Module._ts_node_end_point_wasm=Module.asm.ts_node_end_point_wasm).apply(null,arguments)},Module._ts_node_start_index_wasm=function(){return(Module._ts_node_start_index_wasm=Module.asm.ts_node_start_index_wasm).apply(null,arguments)},Module._ts_node_end_index_wasm=function(){return(Module._ts_node_end_index_wasm=Module.asm.ts_node_end_index_wasm).apply(null,arguments)},Module._ts_node_to_string_wasm=function(){return(Module._ts_node_to_string_wasm=Module.asm.ts_node_to_string_wasm).apply(null,arguments)},Module._ts_node_children_wasm=function(){return(Module._ts_node_children_wasm=Module.asm.ts_node_children_wasm).apply(null,arguments)},Module._ts_node_named_children_wasm=function(){return(Module._ts_node_named_children_wasm=Module.asm.ts_node_named_children_wasm).apply(null,arguments)},Module._ts_node_descendants_of_type_wasm=function(){return(Module._ts_node_descendants_of_type_wasm=Module.asm.ts_node_descendants_of_type_wasm).apply(null,arguments)},Module._ts_node_is_named_wasm=function(){return(Module._ts_node_is_named_wasm=Module.asm.ts_node_is_named_wasm).apply(null,arguments)},Module._ts_node_has_changes_wasm=function(){return(Module._ts_node_has_changes_wasm=Module.asm.ts_node_has_changes_wasm).apply(null,arguments)},Module._ts_node_has_error_wasm=function(){return(Module._ts_node_has_error_wasm=Module.asm.ts_node_has_error_wasm).apply(null,arguments)},Module._ts_node_is_missing_wasm=function(){return(Module._ts_node_is_missing_wasm=Module.asm.ts_node_is_missing_wasm).apply(null,arguments)},Module._ts_query_matches_wasm=function(){return(Module._ts_query_matches_wasm=Module.asm.ts_query_matches_wasm).apply(null,arguments)},Module._ts_query_captures_wasm=function(){return(Module._ts_query_captures_wasm=Module.asm.ts_query_captures_wasm).apply(null,arguments)},Module._iswdigit=function(){return(Module._iswdigit=Module.asm.iswdigit).apply(null,arguments)},Module._iswalpha=function(){return(Module._iswalpha=Module.asm.iswalpha).apply(null,arguments)},Module._iswlower=function(){return(Module._iswlower=Module.asm.iswlower).apply(null,arguments)},Module._towupper=function(){return(Module._towupper=Module.asm.towupper).apply(null,arguments)},Module.___errno_location=function(){return($e=Module.___errno_location=Module.asm.__errno_location).apply(null,arguments)}),Le=(Module._memchr=function(){return(Module._memchr=Module.asm.memchr).apply(null,arguments)},Module._strlen=function(){return(Module._strlen=Module.asm.strlen).apply(null,arguments)},Module.stackSave=function(){return(Le=Module.stackSave=Module.asm.stackSave).apply(null,arguments)}),We=Module.stackRestore=function(){return(We=Module.stackRestore=Module.asm.stackRestore).apply(null,arguments)},Ze=Module.stackAlloc=function(){return(Ze=Module.stackAlloc=Module.asm.stackAlloc).apply(null,arguments)},Fe=(Module.__Znwm=function(){return(Module.__Znwm=Module.asm._Znwm).apply(null,arguments)},Module.__ZdlPv=function(){return(Module.__ZdlPv=Module.asm._ZdlPv).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEmmmmmm=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEmmmmmm=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEmmmmmm).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEm=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEm=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE7reserveEm).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9push_backEc=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9push_backEc=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9push_backEc).apply(null,arguments)},Module.__ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4copyEPcmm=function(){return(Module.__ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4copyEPcmm=Module.asm._ZNKSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4copyEPcmm).apply(null,arguments)},Module.__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEED2Ev=function(){return(Module.__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEED2Ev=Module.asm._ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEED2Ev).apply(null,arguments)},Module.__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE9push_backEw=function(){return(Module.__ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE9push_backEw=Module.asm._ZNSt3__212basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE9push_backEw).apply(null,arguments)},Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_=function(){return(Module.__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_=Module.asm._ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_).apply(null,arguments)},Module.__ZNKSt3__220__vector_base_commonILb1EE20__throw_length_errorEv=function(){return(Module.__ZNKSt3__220__vector_base_commonILb1EE20__throw_length_errorEv=Module.asm._ZNKSt3__220__vector_base_commonILb1EE20__throw_length_errorEv).apply(null,arguments)},Module.dynCall_iiii=function(){return(Module.dynCall_iiii=Module.asm.dynCall_iiii).apply(null,arguments)},Module.dynCall_ii=function(){return(Module.dynCall_ii=Module.asm.dynCall_ii).apply(null,arguments)},Module.dynCall_vi=function(){return(Module.dynCall_vi=Module.asm.dynCall_vi).apply(null,arguments)},Module.dynCall_vii=function(){return(Module.dynCall_vii=Module.asm.dynCall_vii).apply(null,arguments)},Module.dynCall_iiiii=function(){return(Module.dynCall_iiiii=Module.asm.dynCall_iiiii).apply(null,arguments)},Module.dynCall_iidiiii=function(){return(Module.dynCall_iidiiii=Module.asm.dynCall_iidiiii).apply(null,arguments)},Module._orig$ts_parser_timeout_micros=function(){return(Module._orig$ts_parser_timeout_micros=Module.asm.orig$ts_parser_timeout_micros).apply(null,arguments)},Module._orig$ts_parser_set_timeout_micros=function(){return(Module._orig$ts_parser_set_timeout_micros=Module.asm.orig$ts_parser_set_timeout_micros).apply(null,arguments)},Module.___assign_got_enties=function(){return(Fe=Module.___assign_got_enties=Module.asm.__assign_got_enties).apply(null,arguments)}),Oe={TRANSFER_BUFFER:1504,__cxa_new_handler:6144,__data_end:6984};for(var je in Oe)Module["_"+je]=Pe+Oe[je];for(var je in Module.NAMED_GLOBALS=Oe,Oe)!function(e){var t=Module["_"+e];Module["g$_"+e]=function(){return t}}(je);function Ue(e){this.name="ExitStatus",this.message="Program terminated with exit("+e+")",this.status=e}Module._fp$tree_sitter_log_callback$viii=function(){L(Module._tree_sitter_log_callback||!0,"external function `tree_sitter_log_callback` is missing.perhaps a side module was not linked in? if this symbol was expected to arrive from a system library, try to build the MAIN_MODULE with EMCC_FORCE_STDLIBS=XX in the environment");var e=Module.asm.tree_sitter_log_callback;e||(e=Module._tree_sitter_log_callback),e||(e=Module._tree_sitter_log_callback),e||(e=Ce);var t=N(e,"viii");return Module._fp$tree_sitter_log_callback$viii=function(){return t},t},Module.allocate=function(e,t,r,n){var s,o;"number"==typeof e?(s=!0,o=e):(s=!1,o=e.length);var _,a="string"==typeof t?t:null;if(_=r==W?n:[Te,Ze,p][r](Math.max(o,a?1:t.length)),s){var i;for(n=_,L(0==(3&_)),i=_+(-4&o);n>2]=0;for(i=_+o;n>0]=0;return _}if("i8"===a)return e.subarray||e.slice?B.set(e,_):B.set(new Uint8Array(e),_),_;for(var u,l,d,c=0;c0||(!function(){if(Module.preRun)for("function"==typeof Module.preRun&&(Module.preRun=[Module.preRun]);Module.preRun.length;)se(Module.preRun.shift());Y(J)}(),ue>0||(Module.setStatus?(Module.setStatus("Running..."),setTimeout(function(){setTimeout(function(){Module.setStatus("")},1),t()},1)):t()))}function Be(e,t){t&&A&&0===e||(A||($=!0,e,!0,Module.onExit&&Module.onExit(e)),o(e,new Ue(e)))}if(de=function e(){ke||De(),ke||(de=e)},Module.run=De,Module.preInit)for("function"==typeof Module.preInit&&(Module.preInit=[Module.preInit]);Module.preInit.length>0;)Module.preInit.pop()();var He=!0;Module.noInitialRun&&(He=!1),A=!0,De();const ze=Module,Ke={},Ge=4,Xe=5*Ge,Qe=2*Ge,Ve=2*Ge+2*Qe,Ye={row:0,column:0},Je=/[\w-.]*/g,et=1,tt=2,rt=/^_?tree_sitter_\w+/;var nt,st,ot,_t,at,it=new Promise(e=>{Module.onRuntimeInitialized=e}).then(()=>{ot=ze._ts_init(),nt=q(ot,"i32"),st=q(ot+Ge,"i32")});class Parser{static init(){return it}constructor(){if(null==ot)throw new Error("You must first call Parser.init() and wait for it to resolve.");ze._ts_parser_new_wasm(),this[0]=q(ot,"i32"),this[1]=q(ot+Ge,"i32")}delete(){ze._ts_parser_delete(this[0]),ze._free(this[1]),this[0]=0,this[1]=0}setLanguage(e){let t;if(e){if(e.constructor!==Language)throw new Error("Argument must be a Language");{t=e[0];const r=ze._ts_language_version(t);if(re.slice(t,n));else{if("function"!=typeof e)throw new Error("Argument must be a string or a function");_t=e}this.logCallback?(at=this.logCallback,ze._ts_parser_enable_logger_wasm(this[0],1)):(at=null,ze._ts_parser_enable_logger_wasm(this[0],0));let n=0,s=0;if(r&&r.includedRanges){n=r.includedRanges.length;let e=s=ze._calloc(n,Ve);for(let t=0;t0){let e=r;for(let r=0;r0){let r=t;for(let t=0;t0){let r=t;for(let t=0;t0){let e=a;for(let t=0;t<_;t++)i[t]=ft(this.tree,e),e+=Xe}return ze._free(a),ze._free(o),i}get nextSibling(){return mt(this),ze._ts_node_next_sibling_wasm(this.tree[0]),ft(this.tree)}get previousSibling(){return mt(this),ze._ts_node_prev_sibling_wasm(this.tree[0]),ft(this.tree)}get nextNamedSibling(){return mt(this),ze._ts_node_next_named_sibling_wasm(this.tree[0]),ft(this.tree)}get previousNamedSibling(){return mt(this),ze._ts_node_prev_named_sibling_wasm(this.tree[0]),ft(this.tree)}get parent(){return mt(this),ze._ts_node_parent_wasm(this.tree[0]),ft(this.tree)}descendantForIndex(e,t=e){if("number"!=typeof e||"number"!=typeof t)throw new Error("Arguments must be numbers");mt(this);let r=ot+Xe;return R(r,e,"i32"),R(r+Ge,t,"i32"),ze._ts_node_descendant_for_index_wasm(this.tree[0]),ft(this.tree)}namedDescendantForIndex(e,t=e){if("number"!=typeof e||"number"!=typeof t)throw new Error("Arguments must be numbers");mt(this);let r=ot+Xe;return R(r,e,"i32"),R(r+Ge,t,"i32"),ze._ts_node_named_descendant_for_index_wasm(this.tree[0]),ft(this.tree)}descendantForPosition(e,t=e){if(!ct(e)||!ct(t))throw new Error("Arguments must be {row, column} objects");mt(this);let r=ot+Xe;return Mt(r,e),Mt(r+Qe,t),ze._ts_node_descendant_for_position_wasm(this.tree[0]),ft(this.tree)}namedDescendantForPosition(e,t=e){if(!ct(e)||!ct(t))throw new Error("Arguments must be {row, column} objects");mt(this);let r=ot+Xe;return Mt(r,e),Mt(r+Qe,t),ze._ts_node_named_descendant_for_position_wasm(this.tree[0]),ft(this.tree)}walk(){return mt(this),ze._ts_tree_cursor_new_wasm(this.tree[0]),new TreeCursor(Ke,this.tree)}toString(){mt(this);const e=ze._ts_node_to_string_wasm(this.tree[0]),t=function(e){for(var t="";;){var r=B[e++>>0];if(!r)return t;t+=String.fromCharCode(r)}}(e);return ze._free(e),t}}class TreeCursor{constructor(e,t){dt(e),this.tree=t,ht(this)}delete(){pt(this),ze._ts_tree_cursor_delete_wasm(this.tree[0]),this[0]=this[1]=this[2]=0}reset(e){mt(e),pt(this,ot+Xe),ze._ts_tree_cursor_reset_wasm(this.tree[0]),ht(this)}get nodeType(){return this.tree.language.types[this.nodeTypeId]||"ERROR"}get nodeTypeId(){return pt(this),ze._ts_tree_cursor_current_node_type_id_wasm(this.tree[0])}get nodeId(){return pt(this),ze._ts_tree_cursor_current_node_id_wasm(this.tree[0])}get nodeIsNamed(){return pt(this),1===ze._ts_tree_cursor_current_node_is_named_wasm(this.tree[0])}get nodeIsMissing(){return pt(this),1===ze._ts_tree_cursor_current_node_is_missing_wasm(this.tree[0])}get nodeText(){pt(this);const e=ze._ts_tree_cursor_start_index_wasm(this.tree[0]),t=ze._ts_tree_cursor_end_index_wasm(this.tree[0]);return ut(this.tree,e,t)}get startPosition(){return pt(this),ze._ts_tree_cursor_start_position_wasm(this.tree[0]),gt(ot)}get endPosition(){return pt(this),ze._ts_tree_cursor_end_position_wasm(this.tree[0]),gt(ot)}get startIndex(){return pt(this),ze._ts_tree_cursor_start_index_wasm(this.tree[0])}get endIndex(){return pt(this),ze._ts_tree_cursor_end_index_wasm(this.tree[0])}currentNode(){return pt(this),ze._ts_tree_cursor_current_node_wasm(this.tree[0]),ft(this.tree)}currentFieldId(){return pt(this),ze._ts_tree_cursor_current_field_id_wasm(this.tree[0])}currentFieldName(){return this.tree.language.fields[this.currentFieldId()]}gotoFirstChild(){pt(this);const e=ze._ts_tree_cursor_goto_first_child_wasm(this.tree[0]);return ht(this),1===e}gotoNextSibling(){pt(this);const e=ze._ts_tree_cursor_goto_next_sibling_wasm(this.tree[0]);return ht(this),1===e}gotoParent(){pt(this);const e=ze._ts_tree_cursor_goto_parent_wasm(this.tree[0]);return ht(this),1===e}}class Language{constructor(e,t){dt(e),this[0]=t,this.types=new Array(ze._ts_language_symbol_count(this[0]));for(let e=0,t=this.types.length;e=55296&&n<=57343&&(n=65536+((1023&n)<<10)|1023&e.charCodeAt(++r)),n<=127?++t:t+=n<=2047?2:n<=65535?3:4}return t}(e),r=ze._malloc(t+1);(function(e,t,r,n){if(!(n>0))return 0;for(var s=r,o=r+n-1,_=0;_=55296&&a<=57343&&(a=65536+((1023&a)<<10)|1023&e.charCodeAt(++_)),a<=127){if(r>=o)break;t[r++]=a}else if(a<=2047){if(r+1>=o)break;t[r++]=192|a>>6,t[r++]=128|63&a}else if(a<=65535){if(r+2>=o)break;t[r++]=224|a>>12,t[r++]=128|a>>6&63,t[r++]=128|63&a}else{if(r+3>=o)break;t[r++]=240|a>>18,t[r++]=128|a>>12&63,t[r++]=128|a>>6&63,t[r++]=128|63&a}}t[r]=0})(e,B,r,t+1);const n=ze._ts_query_new(this[0],r,t,ot,ot+Ge);if(!n){const t=q(ot+Ge,"i32"),n=j(r,q(ot,"i32")).length,s=e.substr(n,100).split("\n")[0];let o,_=s.match(Je)[0];switch(t){case 2:o=new RangeError(`Bad node name '${_}'`);break;case 3:o=new RangeError(`Bad field name '${_}'`);break;case 4:o=new RangeError(`Bad capture name @${_}`);break;case 5:o=new TypeError(`Bad pattern structure at offset ${n}: '${s}'...`),_="";break;default:o=new SyntaxError(`Bad syntax at offset ${n}: '${s}'...`),_=""}throw o.index=n,o.length=_.length,ze._free(r),o}const s=ze._ts_query_string_count(n),o=ze._ts_query_capture_count(n),_=ze._ts_query_pattern_count(n),a=new Array(o),i=new Array(s);for(let e=0;e0){if("string"!==s[0].type)throw new Error("Predicates must begin with a literal value");const t=s[0].value;let r=!0;switch(t){case"not-eq?":r=!1;case"eq?":if(3!==s.length)throw new Error(`Wrong number of arguments to \`#eq?\` predicate. Expected 2, got ${s.length-1}`);if("capture"!==s[1].type)throw new Error(`First argument of \`#eq?\` predicate must be a capture. Got "${s[1].value}"`);if("capture"===s[2].type){const t=s[1].name,n=s[2].name;m[e].push(function(e){let s,o;for(const r of e)r.name===t&&(s=r.node),r.name===n&&(o=r.node);return s.text===o.text===r})}else{const t=s[1].name,n=s[2].value;m[e].push(function(e){for(const s of e)if(s.name===t)return s.node.text===n===r;return!1})}break;case"not-match?":r=!1;case"match?":if(3!==s.length)throw new Error(`Wrong number of arguments to \`#match?\` predicate. Expected 2, got ${s.length-1}.`);if("capture"!==s[1].type)throw new Error(`First argument of \`#match?\` predicate must be a capture. Got "${s[1].value}".`);if("string"!==s[2].type)throw new Error(`Second argument of \`#match?\` predicate must be a string. Got @${s[2].value}.`);const n=s[1].name,o=new RegExp(s[2].value);m[e].push(function(e){for(const t of e)if(t.name===n)return o.test(t.node.text)===r;return!1});break;case"set!":if(s.length<2||s.length>3)throw new Error(`Wrong number of arguments to \`#set!\` predicate. Expected 1 or 2. Got ${s.length-1}.`);if(s.some(e=>"string"!==e.type))throw new Error('Arguments to `#set!` predicate must be a strings.".');u[e]||(u[e]={}),u[e][s[1].value]=s[2]?s[2].value:null;break;case"is?":case"is-not?":if(s.length<2||s.length>3)throw new Error(`Wrong number of arguments to \`#${t}\` predicate. Expected 1 or 2. Got ${s.length-1}.`);if(s.some(e=>"string"!==e.type))throw new Error(`Arguments to \`#${t}\` predicate must be a strings.".`);const _="is?"===t?l:d;_[e]||(_[e]={}),_[e][s[1].value]=s[2]?s[2].value:null;break;default:c[e].push({operator:t,operands:s.slice(1)})}s.length=0}}Object.freeze(u[e]),Object.freeze(l[e]),Object.freeze(d[e])}return ze._free(r),new Query(Ke,n,a,m,c,Object.freeze(u),Object.freeze(l),Object.freeze(d))}static load(e){let t;if("undefined"!=typeof process&&process.versions&&process.versions.node){const r=require("fs");t=Promise.resolve(r.readFileSync(e))}else t=fetch(e).then(e=>e.arrayBuffer().then(t=>{if(e.ok)return new Uint8Array(t);{const r=new TextDecoder("utf-8").decode(t);throw new Error(`Language.load failed with status ${e.status}.\n\n${r}`)}}));return t.then(e=>E(e,{loadAsync:!0})).then(e=>{const t=Object.keys(e),r=t.find(e=>rt.test(e)&&!e.includes("external_scanner_"));r||console.log(`Couldn't find language function in WASM file. Symbols:\n${JSON.stringify(t,null,2)}`);const n=e[r]();return new Language(Ke,n)})}}class Query{constructor(e,t,r,n,s,o,_,a){dt(e),this[0]=t,this.captureNames=r,this.textPredicates=n,this.predicates=s,this.setProperties=o,this.assertedProperties=_,this.refutedProperties=a}delete(){ze._ts_query_delete(this[0]),this[0]=0}matches(e,t,r){t||(t=Ye),r||(r=Ye),mt(e),ze._ts_query_matches_wasm(this[0],e.tree[0],t.row,t.column,r.row,r.column);const n=q(ot,"i32"),s=q(ot+Ge,"i32"),o=new Array(n);let _=s;for(let t=0;te(s))){o[t]={pattern:r,captures:s};const e=this.setProperties[r];e&&(o[t].setProperties=e);const n=this.assertedProperties[r];n&&(o[t].assertedProperties=n);const _=this.refutedProperties[r];_&&(o[t].refutedProperties=_)}}return ze._free(s),o}captures(e,t,r){t||(t=Ye),r||(r=Ye),mt(e),ze._ts_query_captures_wasm(this[0],e.tree[0],t.row,t.column,r.row,r.column);const n=q(ot,"i32"),s=q(ot+Ge,"i32"),o=[],_=[];let a=s;for(let t=0;te(_))){const e=_[n],r=this.setProperties[t];r&&(e.setProperties=r);const s=this.assertedProperties[t];s&&(e.assertedProperties=s);const a=this.refutedProperties[t];a&&(e.refutedProperties=a),o.push(e)}}return ze._free(s),o}predicatesForPattern(e){return this.predicates[e]}}function ut(e,t,r){const n=r-t;let s=e.textCallback(t,null,r);for(t+=s.length;t0))break;t+=n.length,s+=n}return t>r&&(s=s.slice(0,n)),s}function lt(e,t,r,n){for(let s=0,o=n.length;s", 50 | ">=", 51 | "and", 52 | "andalso", 53 | "band", 54 | "bor", 55 | "bsl", 56 | "bsr", 57 | "bxor", 58 | "div", 59 | "or", 60 | "orelse", 61 | "rem", 62 | "xor", 63 | ]; 64 | const OP2_RIGHT_ASSOC = ["=!", "++", "--"]; 65 | 66 | /////////////////////////////////////////////////////////////////////////////// 67 | // 68 | // Precedences 69 | // 70 | /////////////////////////////////////////////////////////////////////////////// 71 | const PREC = { 72 | EXPR_MAP_UPDATE: 101, 73 | TOP_LEVEL_EXPRESSION: 100, 74 | UNARY_OP: 10, 75 | BINARY_OP: 9, 76 | MODULE_DECLARATION: 8, 77 | FUNCTION_CLAUSE: 7, 78 | FUNCTION_NAME: 5, 79 | PARENTHESIZED_EXPRESSION: 6, 80 | EXPR_LIST_CONS: 5, 81 | EXPRESSION: 4, 82 | PATTERN: 3, 83 | MACRO_APPLICATION: 1, 84 | MATCH: -1, // prefer other expressions to matches 85 | }; 86 | 87 | /////////////////////////////////////////////////////////////////////////////// 88 | // 89 | // Combinators 90 | // 91 | /////////////////////////////////////////////////////////////////////////////// 92 | const opt = optional; 93 | const sepBy = (sep, x) => seq(x, repeat(seq(sep, x))); 94 | const delim = (open, x, close) => seq(open, x, close); 95 | 96 | const tuple = (x) => delim(BRACE_LEFT, opt(sepBy(COMMA, x)), BRACE_RIGHT); 97 | const list = (x) => delim(BRACKET_LEFT, opt(sepBy(COMMA, x)), BRACKET_RIGHT); 98 | const parens = (x) => delim(PARENS_LEFT, x, PARENS_RIGHT); 99 | const args = (x) => field("arguments", parens(opt(sepBy(COMMA, x)))); 100 | 101 | const oneOf = (x) => choice.apply(null, x); 102 | 103 | /////////////////////////////////////////////////////////////////////////////// 104 | // 105 | // Grammar 106 | // 107 | /////////////////////////////////////////////////////////////////////////////// 108 | module.exports = grammar({ 109 | name: "erlang", 110 | 111 | word: ($) => $._unquoted_atom, 112 | 113 | extras: ($) => [/[\x01-\x20\x80-\xA0]/, $.comment], 114 | 115 | inline: ($) => [$.term, $.expression], 116 | 117 | conflicts: ($) => [ 118 | [$._structure_item, $._expr_operator_binary], 119 | [ 120 | $._structure_item, 121 | $.expr_map_update, 122 | $.expr_record_access, 123 | $.expr_record_update, 124 | ], 125 | ], 126 | 127 | rules: { 128 | source_file: ($) => repeat($._structure_item), 129 | 130 | _structure_item: ($) => 131 | choice( 132 | prec(PREC.TOP_LEVEL_EXPRESSION, $.expression), 133 | prec(PREC.MODULE_DECLARATION, $._module) 134 | ), 135 | 136 | //////////////////////////////////////////////////////////////////////////// 137 | // 138 | // Modules 139 | // 140 | //////////////////////////////////////////////////////////////////////////// 141 | 142 | _module: ($) => 143 | choice( 144 | $.type_declaration, 145 | $.function_spec, 146 | $.function_declaration, 147 | $.module_attribute, 148 | $.module_name, 149 | $.module_export 150 | ), 151 | 152 | module_attribute: ($) => seq(DASH, $.atom, parens($.expression), DOT), 153 | 154 | module_name: ($) => seq(DASH, "module", parens($.atom), DOT), 155 | 156 | module_export: ($) => 157 | seq( 158 | DASH, 159 | choice("export", "export_type"), 160 | parens(list(seq($.atom, SLASH, $.integer))), 161 | DOT 162 | ), 163 | 164 | function_declaration: ($) => seq(sepBy(SEMI, $.function_clause), DOT), 165 | 166 | function_clause: ($) => 167 | prec(PREC.FUNCTION_CLAUSE, seq(field("name", $.atom), $.lambda_clause)), 168 | 169 | comment: ($) => /%.*/, 170 | 171 | //////////////////////////////////////////////////////////////////////////// 172 | // 173 | // Types 174 | // 175 | //////////////////////////////////////////////////////////////////////////// 176 | 177 | type_declaration: ($) => 178 | seq( 179 | DASH, 180 | choice("type", "opaque"), 181 | field("name", $.atom), 182 | args($.variable), 183 | DOUBLE_COLON, 184 | field("def", $.type_expression), 185 | DOT 186 | ), 187 | 188 | function_spec: ($) => 189 | seq( 190 | DASH, 191 | choice("spec", "callback"), 192 | field("name", $.atom), 193 | args($.type_expression), 194 | ARROW, 195 | field("def", $.type_expression), 196 | DOT 197 | ), 198 | 199 | type_expression: ($) => 200 | sepBy( 201 | PIPE, 202 | choice( 203 | $.type_atom, 204 | $.type_application, 205 | $.type_bitstring, 206 | $.type_fun, 207 | $.type_integer, 208 | $.type_map, 209 | $.type_record, 210 | $.type_tuple, 211 | $.type_variable, 212 | $._type_list 213 | ) 214 | ), 215 | 216 | type_variable: ($) => $.variable, 217 | 218 | type_atom: ($) => $.atom, 219 | 220 | type_application: ($) => 221 | prec.right( 222 | PREC.MACRO_APPLICATION, 223 | seq(opt(seq($.atom, COLON)), $.atom, args($.type_expression)) 224 | ), 225 | 226 | type_bitstring: ($) => 227 | seq( 228 | BINARY_LEFT, 229 | choice( 230 | seq(UNDERSCORE, COLON, $.variable), 231 | seq(UNDERSCORE, COLON, UNDERSCORE, STAR, $.variable), 232 | seq( 233 | UNDERSCORE, 234 | COLON, 235 | $.variable, 236 | UNDERSCORE, 237 | COLON, 238 | UNDERSCORE, 239 | STAR, 240 | $.variable 241 | ), 242 | BINARY_RIGHT 243 | ) 244 | ), 245 | 246 | type_fun: ($) => 247 | seq( 248 | "fun", 249 | parens( 250 | opt( 251 | choice( 252 | seq(parens(DOT_DOT_DOT), ARROW, $.type_expression), 253 | seq(args($.type_expression), ARROW, $.type_expression) 254 | ) 255 | ) 256 | ) 257 | ), 258 | type_integer: ($) => choice($.integer, seq($.integer, DOT_DOT, $.integer)), 259 | 260 | _type_list: ($) => choice($.type_list, $.type_nonempty_list), 261 | 262 | type_list: ($) => delim(BRACKET_LEFT, $.type_expression, BRACKET_RIGHT), 263 | 264 | type_nonempty_list: ($) => 265 | delim( 266 | BRACKET_LEFT, 267 | seq($.type_expression, COMMA, DOT_DOT_DOT), 268 | BRACKET_RIGHT 269 | ), 270 | 271 | type_tuple: ($) => tuple($.type_expression), 272 | 273 | type_map: ($) => 274 | seq(HASH, BRACE_LEFT, opt(sepBy(COMMA, $.type_map_entry)), BRACE_RIGHT), 275 | type_map_entry: ($) => 276 | seq($.type_expression, choice(FAT_ARROW, COLON_EQUAL), $.type_expression), 277 | 278 | type_record: ($) => 279 | seq( 280 | HASH, 281 | $.atom, 282 | BRACE_LEFT, 283 | opt(sepBy(COMMA, $.type_record_field)), 284 | BRACE_RIGHT 285 | ), 286 | type_record_field: ($) => 287 | seq($.type_expression, DOUBLE_COLON, $.type_expression), 288 | 289 | //////////////////////////////////////////////////////////////////////////// 290 | // 291 | // Patterns 292 | // 293 | //////////////////////////////////////////////////////////////////////////// 294 | 295 | pattern: ($) => 296 | prec(PREC.PATTERN, choice($.term, $.variable, $.pat_list, $.pat_tuple)), 297 | 298 | pat_list: ($) => 299 | prec(PREC.PATTERN, choice(list($.pattern), $.pat_list_cons)), 300 | 301 | pat_list_cons: ($) => 302 | delim( 303 | BRACKET_LEFT, 304 | seq( 305 | field("init", sepBy(COMMA, $.pattern)), 306 | PIPE, 307 | field("tail", $.pattern) 308 | ), 309 | BRACKET_RIGHT 310 | ), 311 | 312 | pat_tuple: ($) => prec(PREC.PATTERN, tuple($.pattern)), 313 | pat_map: ($) => 314 | seq(HASH, BRACE_LEFT, opt(sepBy(COMMA, $.pat_map_entry)), BRACE_RIGHT), 315 | pat_map_entry: ($) => seq($.term, COLON_EQUAL, $.pattern), 316 | 317 | //////////////////////////////////////////////////////////////////////////// 318 | // 319 | // Expressions 320 | // 321 | //////////////////////////////////////////////////////////////////////////// 322 | 323 | expression: ($) => 324 | choice( 325 | prec(PREC.PARENTHESIZED_EXPRESSION, parens($._expr)), 326 | prec(PREC.EXPRESSION, $._expr) 327 | ), 328 | 329 | _expr: ($) => 330 | choice( 331 | $.expr_begin_block, 332 | $.expr_bitstring_comprehension, 333 | $.expr_case, 334 | $.expr_catch, 335 | $.expr_function_call, 336 | $.expr_if, 337 | $.expr_lambda, 338 | $.expr_list, 339 | $.expr_list_comprehension, 340 | $.expr_macro_application, 341 | $.expr_map_update, 342 | $.expr_match, 343 | $.expr_receive, 344 | $.expr_record_access, 345 | $.expr_record_update, 346 | $.expr_send, 347 | $.expr_throw, 348 | $.expr_try, 349 | $.expr_op, 350 | $.term, 351 | $.variable 352 | ), 353 | 354 | expr_map_update: ($) => 355 | prec.left(PREC.EXPR_MAP_UPDATE, seq($.expression, $.map)), 356 | 357 | expr_record_access: ($) => 358 | prec.left( 359 | PREC.EXPR_MAP_UPDATE, 360 | seq($.expression, HASH, $.atom, DOT, $.atom) 361 | ), 362 | 363 | expr_record_update: ($) => 364 | prec.left(PREC.EXPR_MAP_UPDATE, seq($.expression, $.record)), 365 | 366 | expr_try: ($) => 367 | seq( 368 | "try", 369 | $.expression, 370 | opt(seq("of", sepBy(SEMI, $.case_clause))), 371 | choice($.expr_try_catch, $.expr_try_after, $._expr_try_catch_after), 372 | "end" 373 | ), 374 | 375 | expr_try_catch: ($) => seq("catch", sepBy(SEMI, $.catch_clause)), 376 | expr_try_after: ($) => seq("after", $.expression), 377 | _expr_try_catch_after: ($) => seq($.expr_try_catch, $.expr_try_after), 378 | catch_clause: ($) => 379 | seq( 380 | field("pattern", $.catch_pattern), 381 | opt($.guard_clause), 382 | ARROW, 383 | field("body", sepBy(COMMA, $.expression)) 384 | ), 385 | catch_pattern: ($) => 386 | seq( 387 | field("class", $.pattern), 388 | field("exception", opt(seq(COLON, $.pattern))), 389 | field("stacktrace", opt(seq(COLON, $.variable))) 390 | ), 391 | 392 | expr_catch: ($) => prec.left(seq("catch", $.expression)), 393 | expr_throw: ($) => prec.left(seq("throw", $.expression)), 394 | 395 | expr_begin_block: ($) => seq("begin", sepBy(COMMA, $.expression), "end"), 396 | 397 | expr_list_comprehension: ($) => 398 | seq( 399 | BRACKET_LEFT, 400 | $.expression, 401 | DOUBLE_PIPE, 402 | $.expr_list_generator, 403 | opt(seq(COMMA, $.expr_list_filter)), 404 | BRACKET_RIGHT 405 | ), 406 | 407 | expr_list_generator: ($) => seq($.expression, REV_ARROW, $.expression), 408 | expr_list_filter: ($) => sepBy(COMMA, $.expression), 409 | 410 | expr_bitstring_comprehension: ($) => 411 | seq( 412 | BINARY_LEFT, 413 | $.term, 414 | DOUBLE_PIPE, 415 | $.expr_bitstring_generator, 416 | opt(seq(COMMA, $.expr_bitstring_filter)), 417 | BINARY_RIGHT 418 | ), 419 | 420 | expr_bitstring_generator: ($) => 421 | seq(BINARY_LEFT, $.expression, BINARY_RIGHT, REV_FAT_ARROW, $.expression), 422 | expr_bitstring_filter: ($) => sepBy(COMMA, $.expression), 423 | 424 | expr_op: ($) => choice($._expr_operator_unary, $._expr_operator_binary), 425 | 426 | _expr_operator_unary: ($) => 427 | prec.right( 428 | PREC.UNARY_OP, 429 | seq(field("operator", oneOf(OP1)), field("operand", $.expression)) 430 | ), 431 | 432 | _expr_operator_binary: ($) => 433 | choice( 434 | prec.left( 435 | PREC.BINARY_OP, 436 | seq( 437 | field("lhs", $.expression), 438 | field("operator", oneOf(OP2_LEFT_ASSOC)), 439 | field("rhs", $.expression) 440 | ) 441 | ), 442 | prec.right( 443 | PREC.BINARY_OP, 444 | seq( 445 | field("lhs", $.expression), 446 | field("operator", oneOf(OP2_RIGHT_ASSOC)), 447 | field("rhs", $.expression) 448 | ) 449 | ) 450 | ), 451 | 452 | expr_send: ($) => prec.right(seq($.expression, BANG, $.expression)), 453 | 454 | expr_receive: ($) => 455 | seq( 456 | "receive", 457 | field("branches", opt(sepBy(SEMI, $.case_clause))), 458 | opt($.expr_receive_after), 459 | "end" 460 | ), 461 | 462 | expr_receive_after: ($) => seq("after", $.case_clause), 463 | 464 | expr_if: ($) => seq("if", sepBy(SEMI, $.if_clause), "end"), 465 | 466 | if_clause: ($) => 467 | seq( 468 | field("condition", $.guard_seq), 469 | ARROW, 470 | field("body", sepBy(COMMA, $.expression)) 471 | ), 472 | 473 | expr_list: ($) => 474 | prec(PREC.EXPR_LIST_CONS, choice(list($.expression), $.expr_list_cons)), 475 | 476 | expr_list_cons: ($) => 477 | delim( 478 | BRACKET_LEFT, 479 | seq( 480 | field("init", sepBy(COMMA, $.expression)), 481 | PIPE, 482 | field("tail", $.expression) 483 | ), 484 | BRACKET_RIGHT 485 | ), 486 | 487 | expr_case: ($) => 488 | seq("case", $.expression, "of", sepBy(SEMI, $.case_clause), "end"), 489 | 490 | case_clause: ($) => 491 | seq( 492 | field("pattern", $.pattern), 493 | opt($.guard_clause), 494 | ARROW, 495 | field("body", sepBy(COMMA, $.expression)) 496 | ), 497 | 498 | guard_clause: ($) => seq("when", $.guard_seq), 499 | guard_seq: ($) => sepBy(SEMI, $.guard), 500 | guard: ($) => sepBy(COMMA, $.expression), 501 | 502 | expr_match: ($) => 503 | prec.right(PREC.MATCH, seq($.expression, EQUAL, $.expression)), 504 | 505 | expr_lambda: ($) => seq("fun", sepBy(SEMI, $.lambda_clause), "end"), 506 | 507 | lambda_clause: ($) => 508 | seq( 509 | field("arguments", args($.pattern)), 510 | opt($.guard_clause), 511 | ARROW, 512 | field("body", sepBy(COMMA, $.expression)) 513 | ), 514 | 515 | expr_function_call: ($) => 516 | seq(field("name", $._function_name), args($.expression)), 517 | 518 | _function_name: ($) => 519 | prec( 520 | PREC.FUNCTION_NAME, 521 | choice($.computed_function_name, $.qualified_function_name) 522 | ), 523 | 524 | qualified_function_name: ($) => 525 | seq( 526 | field("module_name", choice($.variable, $.atom, parens($.expression))), 527 | COLON, 528 | field("function_name", choice($.variable, $.atom, parens($.expression))) 529 | ), 530 | 531 | computed_function_name: ($) => 532 | prec( 533 | PREC.FUNCTION_NAME, 534 | choice($.variable, $.atom, parens($.expression)) 535 | ), 536 | 537 | expr_macro_application: ($) => 538 | prec.right( 539 | PREC.MACRO_APPLICATION, 540 | seq(QUESTION, $._macro_name, opt(args($.expression))) 541 | ), 542 | 543 | _macro_name: ($) => choice($.variable, $.atom), 544 | 545 | variable: ($) => 546 | /[_A-Z\xC0-\xD6\xD8-\xDE][_@a-zA-Z0-9\xC0-\xD6\xD8-\xDE\xDF-\xF6\xF8-\xFF]*/, 547 | 548 | term: ($) => 549 | choice( 550 | $.atom, 551 | $.binary_string, 552 | $.char, 553 | $.float, 554 | $.integer, 555 | $.list, 556 | $.tuple, 557 | $.map, 558 | $.record, 559 | $.string 560 | ), 561 | 562 | list: ($) => list($.expression), 563 | tuple: ($) => tuple($.expression), 564 | 565 | atom: ($) => field("value", choice($._unquoted_atom, $._quoted_atom)), 566 | _unquoted_atom: ($) => 567 | /[a-z\xDF-\xF6\xF8-\xFF][_@a-zA-Z0-9\xC0-\xD6\xD8-\xDE\xDF-\xF6\xF8-\xFF]*/, 568 | _quoted_atom: ($) => seq("'", repeat(choice(/[^'\\]+/, $._escape)), "'"), 569 | 570 | integer: ($) => 571 | choice( 572 | // binary syntax 573 | /-?2#[01_]+/, 574 | // hex syntax 575 | /-?16#[a-fA-F0-9_]+/, 576 | // regular "other base" syntax 577 | /-?([\d*_]*#)?[\d_]+/ 578 | ), 579 | float: ($) => /-?([\d_]*#)?[\d_]+\.[\d_]+(e-?[\d_]+)?/, 580 | 581 | string: ($) => seq('"', repeat(choice(/[^"\\]+/, $._escape)), '"'), 582 | 583 | char: ($) => seq("$", choice(/[^\\]/, $._escape)), 584 | 585 | _escape: ($) => 586 | token( 587 | seq( 588 | "\\", 589 | choice( 590 | /[0-7]{1,3}/, 591 | /x[0-9a-fA-F]{2}/, 592 | /x{[0-9a-fA-F]+}/, 593 | "\n", 594 | /[nrtvbfesd]/ 595 | ) 596 | ) 597 | ), 598 | 599 | binary_string: ($) => 600 | seq(BINARY_LEFT, opt(sepBy(COMMA, $.bin_part)), BINARY_RIGHT), 601 | bin_part: ($) => 602 | choice( 603 | seq( 604 | choice($.integer, $.float, $.string), 605 | opt($.bin_sized), 606 | opt($.bin_type_list) 607 | ), 608 | seq(parens($.expression), opt($.bin_sized), opt($.bin_type_list)) 609 | ), 610 | bin_sized: ($) => seq(/:/, $.integer), 611 | bin_type_list: ($) => seq(/\//, sepBy(DASH, $.bin_type)), 612 | bin_type: ($) => 613 | choice( 614 | "big", 615 | "binary", 616 | "bits", 617 | "bitstring", 618 | "bytes", 619 | "float", 620 | "integer", 621 | "little", 622 | "native", 623 | "signed", 624 | "unsigned", 625 | "utf16", 626 | "utf32", 627 | "utf8" 628 | ), 629 | 630 | map: ($) => 631 | seq(HASH, BRACE_LEFT, opt(sepBy(COMMA, $.map_entry)), BRACE_RIGHT), 632 | map_entry: ($) => seq($.term, choice(FAT_ARROW, COLON_EQUAL), $.expression), 633 | 634 | record: ($) => 635 | seq( 636 | HASH, 637 | $.atom, 638 | BRACE_LEFT, 639 | opt(sepBy(COMMA, $.record_field)), 640 | BRACE_RIGHT 641 | ), 642 | record_field: ($) => seq($.term, EQUAL, $.expression), 643 | }, 644 | }); 645 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tree-parser-erlang", 3 | "version": "0.0.0", 4 | "description": "Tree Parser support for Erlang", 5 | "scripts": { 6 | "gen": "tree-sitter generate", 7 | "parse": "tree-sitter parse", 8 | "test": "yarn run gen && tree-sitter test" 9 | }, 10 | "author": "Leandro Ostera ", 11 | "license": "Apache-2.0", 12 | "dependencies": { 13 | "nan": "^2.14.1", 14 | "prettier": "^2.2.1", 15 | "tree-sitter-cli": "^0.17.3" 16 | }, 17 | "main": "bindings/node" 18 | } 19 | -------------------------------------------------------------------------------- /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 | }; 127 | 128 | /* 129 | * Lexer Macros 130 | */ 131 | 132 | #define START_LEXER() \ 133 | bool result = false; \ 134 | bool skip = false; \ 135 | bool eof = false; \ 136 | int32_t lookahead; \ 137 | goto start; \ 138 | next_state: \ 139 | lexer->advance(lexer, skip); \ 140 | start: \ 141 | skip = false; \ 142 | lookahead = lexer->lookahead; 143 | 144 | #define ADVANCE(state_value) \ 145 | { \ 146 | state = state_value; \ 147 | goto next_state; \ 148 | } 149 | 150 | #define SKIP(state_value) \ 151 | { \ 152 | skip = true; \ 153 | state = state_value; \ 154 | goto next_state; \ 155 | } 156 | 157 | #define ACCEPT_TOKEN(symbol_value) \ 158 | result = true; \ 159 | lexer->result_symbol = symbol_value; \ 160 | lexer->mark_end(lexer); 161 | 162 | #define END_STATE() return result; 163 | 164 | /* 165 | * Parse Table Macros 166 | */ 167 | 168 | #define SMALL_STATE(id) id - LARGE_STATE_COUNT 169 | 170 | #define STATE(id) id 171 | 172 | #define ACTIONS(id) id 173 | 174 | #define SHIFT(state_value) \ 175 | {{ \ 176 | .shift = { \ 177 | .type = TSParseActionTypeShift, \ 178 | .state = state_value \ 179 | } \ 180 | }} 181 | 182 | #define SHIFT_REPEAT(state_value) \ 183 | {{ \ 184 | .shift = { \ 185 | .type = TSParseActionTypeShift, \ 186 | .state = state_value, \ 187 | .repetition = true \ 188 | } \ 189 | }} 190 | 191 | #define SHIFT_EXTRA() \ 192 | {{ \ 193 | .shift = { \ 194 | .type = TSParseActionTypeShift, \ 195 | .extra = true \ 196 | } \ 197 | }} 198 | 199 | #define REDUCE(symbol_val, child_count_val, ...) \ 200 | {{ \ 201 | .reduce = { \ 202 | .type = TSParseActionTypeReduce, \ 203 | .symbol = symbol_val, \ 204 | .child_count = child_count_val, \ 205 | __VA_ARGS__ \ 206 | }, \ 207 | }} 208 | 209 | #define RECOVER() \ 210 | {{ \ 211 | .type = TSParseActionTypeRecover \ 212 | }} 213 | 214 | #define ACCEPT_INPUT() \ 215 | {{ \ 216 | .type = TSParseActionTypeAccept \ 217 | }} 218 | 219 | #ifdef __cplusplus 220 | } 221 | #endif 222 | 223 | #endif // TREE_SITTER_PARSER_H_ 224 | -------------------------------------------------------------------------------- /test/corpus/advent_of_code_2020.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | runner 3 | ================================================================================ 4 | 5 | % Source code generated with Caramel. 6 | -module(runner). 7 | 8 | -export([main/1]). 9 | -export([run_days/1]). 10 | -export([run_one/1]). 11 | 12 | run_one({N, Day}) -> 13 | io:format(<<"Running day #~p...">>, [N | []]), 14 | io:format(<<"~p\n">>, [Day() | []]). 15 | 16 | -spec run_days(list({any(), fun(() -> any())})) -> ok. 17 | run_days(Days) -> lists:foreach(fun 18 | (Day) -> run_one(Day) 19 | end, Days). 20 | 21 | -spec main(any()) -> ok. 22 | main(_) -> 23 | io:format(<<"==# Advent Of Code 2020! #==\n\n">>, []), 24 | Days = [{1, fun 25 | () -> day_1:run() 26 | end} | []], 27 | run_days(Days), 28 | io:format(<<"\n\n">>, []). 29 | 30 | -------------------------------------------------------------------------------- 31 | 32 | (source_file 33 | (comment) 34 | (module_name 35 | (atom)) 36 | (module_export 37 | (atom) 38 | (integer)) 39 | (module_export 40 | (atom) 41 | (integer)) 42 | (module_export 43 | (atom) 44 | (integer)) 45 | (function_declaration 46 | (function_clause 47 | (atom) 48 | (lambda_clause 49 | (pattern 50 | (pat_tuple 51 | (pattern 52 | (variable)) 53 | (pattern 54 | (variable)))) 55 | (expr_function_call 56 | (qualified_function_name 57 | (atom) 58 | (atom)) 59 | (binary_string 60 | (bin_part 61 | (string))) 62 | (expr_list 63 | (expr_list_cons 64 | (variable) 65 | (expr_list)))) 66 | (expr_function_call 67 | (qualified_function_name 68 | (atom) 69 | (atom)) 70 | (binary_string 71 | (bin_part 72 | (string))) 73 | (expr_list 74 | (expr_list_cons 75 | (expr_function_call 76 | (computed_function_name 77 | (variable))) 78 | (expr_list))))))) 79 | (function_spec 80 | (atom) 81 | (type_expression 82 | (type_application 83 | (atom) 84 | (type_expression 85 | (type_tuple 86 | (type_expression 87 | (type_application 88 | (atom))) 89 | (type_expression 90 | (type_fun 91 | (type_expression 92 | (type_application 93 | (atom))))))))) 94 | (type_expression 95 | (type_atom 96 | (atom)))) 97 | (function_declaration 98 | (function_clause 99 | (atom) 100 | (lambda_clause 101 | (pattern 102 | (variable)) 103 | (expr_function_call 104 | (qualified_function_name 105 | (atom) 106 | (atom)) 107 | (expr_lambda 108 | (lambda_clause 109 | (pattern 110 | (variable)) 111 | (expr_function_call 112 | (computed_function_name 113 | (atom)) 114 | (variable)))) 115 | (variable))))) 116 | (function_spec 117 | (atom) 118 | (type_expression 119 | (type_application 120 | (atom))) 121 | (type_expression 122 | (type_atom 123 | (atom)))) 124 | (function_declaration 125 | (function_clause 126 | (atom) 127 | (lambda_clause 128 | (pattern 129 | (variable)) 130 | (expr_function_call 131 | (qualified_function_name 132 | (atom) 133 | (atom)) 134 | (binary_string 135 | (bin_part 136 | (string))) 137 | (expr_list)) 138 | (expr_match 139 | (variable) 140 | (expr_list 141 | (expr_list_cons 142 | (tuple 143 | (integer) 144 | (expr_lambda 145 | (lambda_clause 146 | (expr_function_call 147 | (qualified_function_name 148 | (atom) 149 | (atom)))))) 150 | (expr_list)))) 151 | (expr_function_call 152 | (computed_function_name 153 | (atom)) 154 | (variable)) 155 | (expr_function_call 156 | (qualified_function_name 157 | (atom) 158 | (atom)) 159 | (binary_string 160 | (bin_part 161 | (string))) 162 | (expr_list)))))) 163 | 164 | ================================================================================ 165 | day 1 166 | ================================================================================ 167 | 168 | % Source code generated with Caramel. 169 | -module(day_1). 170 | 171 | -export([find_entry_pair/2]). 172 | -export([find_entry_triplet/2]). 173 | -export([run/0]). 174 | 175 | -spec find_entry_triplet(integer(), list(integer())) -> option:t(integer()). 176 | find_entry_triplet(Number, Entries) -> lists:foldl(fun 177 | (E1, Acc1) -> 178 | case Acc1 of 179 | none -> lists:foldl(fun 180 | (E2, Acc2) -> 181 | case Acc2 of 182 | none -> lists:foldl(fun 183 | (E3, Acc3) -> 184 | case Acc3 of 185 | none -> case erlang:'=:='(Number, erlang:'+'(erlang:'+'(E1, E2), E3)) of 186 | true -> {some, erlang:'*'(erlang:'*'(E1, E2), E3)}; 187 | false -> none 188 | end; 189 | _ -> Acc3 190 | end 191 | end, none, Entries); 192 | _ -> Acc2 193 | end 194 | end, none, Entries); 195 | _ -> Acc1 196 | end 197 | end, none, Entries). 198 | 199 | -spec find_entry_pair(integer(), list(integer())) -> option:t(integer()). 200 | find_entry_pair(Number, Entries) -> lists:foldl(fun 201 | (E1, Acc1) -> 202 | case Acc1 of 203 | none -> lists:foldl(fun 204 | (E2, Acc2) -> 205 | case Acc2 of 206 | none -> case erlang:'=:='(Number, erlang:'+'(E1, E2)) of 207 | true -> {some, erlang:'*'(E1, E2)}; 208 | false -> none 209 | end; 210 | _ -> Acc2 211 | end 212 | end, none, Entries); 213 | _ -> Acc1 214 | end 215 | end, none, Entries). 216 | 217 | -spec run() -> list(option:t(integer())). 218 | run() -> [find_entry_pair(2020, [0 | [0 | [0 | []]]]) | [find_entry_triplet(2020, [0 | [0 | [0 | []]]]) | []]]. 219 | 220 | -------------------------------------------------------------------------------- 221 | 222 | (source_file 223 | (comment) 224 | (module_name 225 | (atom)) 226 | (module_export 227 | (atom) 228 | (integer)) 229 | (module_export 230 | (atom) 231 | (integer)) 232 | (module_export 233 | (atom) 234 | (integer)) 235 | (function_spec 236 | (atom) 237 | (type_expression 238 | (type_application 239 | (atom))) 240 | (type_expression 241 | (type_application 242 | (atom) 243 | (type_expression 244 | (type_application 245 | (atom))))) 246 | (type_expression 247 | (type_application 248 | (atom) 249 | (atom) 250 | (type_expression 251 | (type_application 252 | (atom)))))) 253 | (function_declaration 254 | (function_clause 255 | (atom) 256 | (lambda_clause 257 | (pattern 258 | (variable)) 259 | (pattern 260 | (variable)) 261 | (expr_function_call 262 | (qualified_function_name 263 | (atom) 264 | (atom)) 265 | (expr_lambda 266 | (lambda_clause 267 | (pattern 268 | (variable)) 269 | (pattern 270 | (variable)) 271 | (expr_case 272 | (variable) 273 | (case_clause 274 | (pattern 275 | (atom)) 276 | (expr_function_call 277 | (qualified_function_name 278 | (atom) 279 | (atom)) 280 | (expr_lambda 281 | (lambda_clause 282 | (pattern 283 | (variable)) 284 | (pattern 285 | (variable)) 286 | (expr_case 287 | (variable) 288 | (case_clause 289 | (pattern 290 | (atom)) 291 | (expr_function_call 292 | (qualified_function_name 293 | (atom) 294 | (atom)) 295 | (expr_lambda 296 | (lambda_clause 297 | (pattern 298 | (variable)) 299 | (pattern 300 | (variable)) 301 | (expr_case 302 | (variable) 303 | (case_clause 304 | (pattern 305 | (atom)) 306 | (expr_case 307 | (expr_function_call 308 | (qualified_function_name 309 | (atom) 310 | (atom)) 311 | (variable) 312 | (expr_function_call 313 | (qualified_function_name 314 | (atom) 315 | (atom)) 316 | (expr_function_call 317 | (qualified_function_name 318 | (atom) 319 | (atom)) 320 | (variable) 321 | (variable)) 322 | (variable))) 323 | (case_clause 324 | (pattern 325 | (atom)) 326 | (tuple 327 | (atom) 328 | (expr_function_call 329 | (qualified_function_name 330 | (atom) 331 | (atom)) 332 | (expr_function_call 333 | (qualified_function_name 334 | (atom) 335 | (atom)) 336 | (variable) 337 | (variable)) 338 | (variable)))) 339 | (case_clause 340 | (pattern 341 | (atom)) 342 | (atom)))) 343 | (case_clause 344 | (pattern 345 | (variable)) 346 | (variable))))) 347 | (atom) 348 | (variable))) 349 | (case_clause 350 | (pattern 351 | (variable)) 352 | (variable))))) 353 | (atom) 354 | (variable))) 355 | (case_clause 356 | (pattern 357 | (variable)) 358 | (variable))))) 359 | (atom) 360 | (variable))))) 361 | (function_spec 362 | (atom) 363 | (type_expression 364 | (type_application 365 | (atom))) 366 | (type_expression 367 | (type_application 368 | (atom) 369 | (type_expression 370 | (type_application 371 | (atom))))) 372 | (type_expression 373 | (type_application 374 | (atom) 375 | (atom) 376 | (type_expression 377 | (type_application 378 | (atom)))))) 379 | (function_declaration 380 | (function_clause 381 | (atom) 382 | (lambda_clause 383 | (pattern 384 | (variable)) 385 | (pattern 386 | (variable)) 387 | (expr_function_call 388 | (qualified_function_name 389 | (atom) 390 | (atom)) 391 | (expr_lambda 392 | (lambda_clause 393 | (pattern 394 | (variable)) 395 | (pattern 396 | (variable)) 397 | (expr_case 398 | (variable) 399 | (case_clause 400 | (pattern 401 | (atom)) 402 | (expr_function_call 403 | (qualified_function_name 404 | (atom) 405 | (atom)) 406 | (expr_lambda 407 | (lambda_clause 408 | (pattern 409 | (variable)) 410 | (pattern 411 | (variable)) 412 | (expr_case 413 | (variable) 414 | (case_clause 415 | (pattern 416 | (atom)) 417 | (expr_case 418 | (expr_function_call 419 | (qualified_function_name 420 | (atom) 421 | (atom)) 422 | (variable) 423 | (expr_function_call 424 | (qualified_function_name 425 | (atom) 426 | (atom)) 427 | (variable) 428 | (variable))) 429 | (case_clause 430 | (pattern 431 | (atom)) 432 | (tuple 433 | (atom) 434 | (expr_function_call 435 | (qualified_function_name 436 | (atom) 437 | (atom)) 438 | (variable) 439 | (variable)))) 440 | (case_clause 441 | (pattern 442 | (atom)) 443 | (atom)))) 444 | (case_clause 445 | (pattern 446 | (variable)) 447 | (variable))))) 448 | (atom) 449 | (variable))) 450 | (case_clause 451 | (pattern 452 | (variable)) 453 | (variable))))) 454 | (atom) 455 | (variable))))) 456 | (function_spec 457 | (atom) 458 | (type_expression 459 | (type_application 460 | (atom) 461 | (type_expression 462 | (type_application 463 | (atom) 464 | (atom) 465 | (type_expression 466 | (type_application 467 | (atom)))))))) 468 | (function_declaration 469 | (function_clause 470 | (atom) 471 | (lambda_clause 472 | (expr_list 473 | (expr_list_cons 474 | (expr_function_call 475 | (computed_function_name 476 | (atom)) 477 | (integer) 478 | (expr_list 479 | (expr_list_cons 480 | (integer) 481 | (expr_list 482 | (expr_list_cons 483 | (integer) 484 | (expr_list 485 | (expr_list_cons 486 | (integer) 487 | (expr_list)))))))) 488 | (expr_list 489 | (expr_list_cons 490 | (expr_function_call 491 | (computed_function_name 492 | (atom)) 493 | (integer) 494 | (expr_list 495 | (expr_list_cons 496 | (integer) 497 | (expr_list 498 | (expr_list_cons 499 | (integer) 500 | (expr_list 501 | (expr_list_cons 502 | (integer) 503 | (expr_list)))))))) 504 | (expr_list))))))))) 505 | -------------------------------------------------------------------------------- /test/corpus/comments.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | empty 3 | ================================================================================ 4 | 5 | % 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (comment)) 11 | 12 | ================================================================================ 13 | single line 14 | ================================================================================ 15 | 16 | % single comment 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (comment)) 22 | 23 | ================================================================================ 24 | multiple start symbols 25 | ================================================================================ 26 | 27 | %%% multi "%" 28 | hello 29 | 30 | -------------------------------------------------------------------------------- 31 | 32 | (source_file 33 | (comment) 34 | (atom)) 35 | 36 | ================================================================================ 37 | many consecutive lines 38 | ================================================================================ 39 | 40 | %% many 41 | %% consecutive 42 | hello 43 | %% lines 44 | 45 | -------------------------------------------------------------------------------- 46 | 47 | (source_file 48 | (comment) 49 | (comment) 50 | (atom) 51 | (comment)) 52 | 53 | ================================================================================ 54 | nested 55 | ================================================================================ 56 | 57 | [ 1 %% inside a list 58 | , { 2 % and a tuple, too! 59 | , 3 } 60 | ] 61 | 62 | -------------------------------------------------------------------------------- 63 | 64 | (source_file 65 | (expr_list 66 | (integer) 67 | (comment) 68 | (tuple 69 | (integer) 70 | (comment) 71 | (integer)))) 72 | -------------------------------------------------------------------------------- /test/corpus/expr_arithmetic.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | reference examples 3 | ================================================================================ 4 | 5 | 2#10 band 2#01 6 | 7 | 2#10 bor 2#01 8 | 9 | 1 bsl (1 bsl 64) 10 | 11 | -------------------------------------------------------------------------------- 12 | 13 | (source_file 14 | (expr_op 15 | (integer) 16 | (integer)) 17 | (expr_op 18 | (integer) 19 | (integer)) 20 | (expr_op 21 | (integer) 22 | (expr_op 23 | (integer) 24 | (integer)))) 25 | -------------------------------------------------------------------------------- /test/corpus/expr_bit_string.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | comprehensions 3 | ================================================================================ 4 | 5 | << << (X*2) >> || <> <= << 1,2,3 >>, is_integer(X) >> 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_bitstring_comprehension 11 | (binary_string 12 | (bin_part 13 | (expr_op 14 | (variable) 15 | (integer)))) 16 | (expr_bitstring_generator 17 | (variable) 18 | (binary_string 19 | (bin_part 20 | (integer)) 21 | (bin_part 22 | (integer)) 23 | (bin_part 24 | (integer)))) 25 | (expr_bitstring_filter 26 | (expr_function_call 27 | (computed_function_name 28 | (atom)) 29 | (variable))))) 30 | -------------------------------------------------------------------------------- /test/corpus/expr_block.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | single expression 3 | ================================================================================ 4 | 5 | begin 6 | A 7 | end 8 | 9 | -------------------------------------------------------------------------------- 10 | 11 | (source_file 12 | (expr_begin_block 13 | (variable))) 14 | 15 | ================================================================================ 16 | multiple expressions 17 | ================================================================================ 18 | 19 | begin 20 | A, 21 | B 22 | end 23 | 24 | -------------------------------------------------------------------------------- 25 | 26 | (source_file 27 | (expr_begin_block 28 | (variable) 29 | (variable))) 30 | -------------------------------------------------------------------------------- /test/corpus/expr_case.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | simple 3 | ================================================================================ 4 | 5 | case A of 6 | [] -> ok 7 | end 8 | 9 | -------------------------------------------------------------------------------- 10 | 11 | (source_file 12 | (expr_case 13 | (variable) 14 | (case_clause 15 | (pattern 16 | (pat_list)) 17 | (atom)))) 18 | 19 | ================================================================================ 20 | multi branch 21 | ================================================================================ 22 | 23 | case f(A) of 24 | [] -> ok; 25 | _ -> error 26 | end 27 | 28 | -------------------------------------------------------------------------------- 29 | 30 | (source_file 31 | (expr_case 32 | (expr_function_call 33 | (computed_function_name 34 | (atom)) 35 | (variable)) 36 | (case_clause 37 | (pattern 38 | (pat_list)) 39 | (atom)) 40 | (case_clause 41 | (pattern 42 | (variable)) 43 | (atom)))) 44 | 45 | ================================================================================ 46 | multi branch ignoring 47 | ================================================================================ 48 | 49 | case Acc1 of 50 | none -> ok; 51 | _ -> Acc1 52 | end 53 | 54 | -------------------------------------------------------------------------------- 55 | 56 | (source_file 57 | (expr_case 58 | (variable) 59 | (case_clause 60 | (pattern 61 | (atom)) 62 | (atom)) 63 | (case_clause 64 | (pattern 65 | (variable)) 66 | (variable)))) 67 | 68 | ================================================================================ 69 | simple with guards 70 | ================================================================================ 71 | 72 | case A of 73 | [] when B -> ok 74 | end 75 | 76 | -------------------------------------------------------------------------------- 77 | 78 | (source_file 79 | (expr_case 80 | (variable) 81 | (case_clause 82 | (pattern 83 | (pat_list)) 84 | (guard_clause 85 | (guard_seq 86 | (guard 87 | (variable)))) 88 | (atom)))) 89 | 90 | ================================================================================ 91 | simple with multiple guards 92 | ================================================================================ 93 | 94 | case A of 95 | [] when B, C; D, E -> ok 96 | end 97 | 98 | -------------------------------------------------------------------------------- 99 | 100 | (source_file 101 | (expr_case 102 | (variable) 103 | (case_clause 104 | (pattern 105 | (pat_list)) 106 | (guard_clause 107 | (guard_seq 108 | (guard 109 | (variable) 110 | (variable)) 111 | (guard 112 | (variable) 113 | (variable)))) 114 | (atom)))) 115 | -------------------------------------------------------------------------------- /test/corpus/expr_exceptions.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | catch an expression 3 | ================================================================================ 4 | 5 | catch 1+2 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_op 11 | (expr_catch 12 | (integer)) 13 | (integer))) 14 | 15 | ================================================================================ 16 | catch must be parenthesized 17 | ================================================================================ 18 | 19 | A = catch 1+2 20 | A = (catch 1+2) 21 | 22 | -------------------------------------------------------------------------------- 23 | 24 | (source_file 25 | (expr_match 26 | (variable) 27 | (expr_op 28 | (expr_catch 29 | (integer)) 30 | (integer))) 31 | (expr_match 32 | (variable) 33 | (expr_op 34 | (expr_catch 35 | (integer)) 36 | (integer)))) 37 | 38 | ================================================================================ 39 | catch throw 40 | ================================================================================ 41 | 42 | catch (throw hello) 43 | 44 | -------------------------------------------------------------------------------- 45 | 46 | (source_file 47 | (expr_catch 48 | (expr_throw 49 | (atom)))) 50 | 51 | ================================================================================ 52 | try with single catch branch ignoring exception 53 | ================================================================================ 54 | 55 | try A 56 | catch 57 | _ -> ok 58 | end 59 | 60 | -------------------------------------------------------------------------------- 61 | 62 | (source_file 63 | (expr_try 64 | (variable) 65 | (expr_try_catch 66 | (catch_clause 67 | (catch_pattern 68 | (pattern 69 | (variable))) 70 | (atom))))) 71 | 72 | ================================================================================ 73 | try with multiple catch branches 74 | ================================================================================ 75 | 76 | try A 77 | catch 78 | Class:ExceptionPattern -> ok; 79 | _ -> ok 80 | end 81 | 82 | -------------------------------------------------------------------------------- 83 | 84 | (source_file 85 | (expr_try 86 | (variable) 87 | (expr_try_catch 88 | (catch_clause 89 | (catch_pattern 90 | (pattern 91 | (variable)) 92 | (pattern 93 | (variable))) 94 | (atom)) 95 | (catch_clause 96 | (catch_pattern 97 | (pattern 98 | (variable))) 99 | (atom))))) 100 | 101 | ================================================================================ 102 | try with catch capturing stacktrace 103 | ================================================================================ 104 | 105 | try A 106 | catch 107 | Class:ExceptionPattern:Stacktrace -> ok 108 | end 109 | 110 | -------------------------------------------------------------------------------- 111 | 112 | (source_file 113 | (expr_try 114 | (variable) 115 | (expr_try_catch 116 | (catch_clause 117 | (catch_pattern 118 | (pattern 119 | (variable)) 120 | (pattern 121 | (variable)) 122 | (variable)) 123 | (atom))))) 124 | 125 | ================================================================================ 126 | try with catch capturing stacktrace with guard 127 | ================================================================================ 128 | 129 | try A 130 | catch 131 | Class:ExceptionPattern:Stacktrace when is_good(Stacktrace) -> ok 132 | end 133 | 134 | -------------------------------------------------------------------------------- 135 | 136 | (source_file 137 | (expr_try 138 | (variable) 139 | (expr_try_catch 140 | (catch_clause 141 | (catch_pattern 142 | (pattern 143 | (variable)) 144 | (pattern 145 | (variable)) 146 | (variable)) 147 | (guard_clause 148 | (guard_seq 149 | (guard 150 | (expr_function_call 151 | (computed_function_name 152 | (atom)) 153 | (variable))))) 154 | (atom))))) 155 | 156 | ================================================================================ 157 | try with of patterns 158 | ================================================================================ 159 | 160 | try A of 161 | A when is_good(A) -> ok 162 | catch 163 | Class:ExceptionPattern:Stacktrace when is_good(Stacktrace) -> ok 164 | end 165 | 166 | -------------------------------------------------------------------------------- 167 | 168 | (source_file 169 | (expr_try 170 | (variable) 171 | (case_clause 172 | (pattern 173 | (variable)) 174 | (guard_clause 175 | (guard_seq 176 | (guard 177 | (expr_function_call 178 | (computed_function_name 179 | (atom)) 180 | (variable))))) 181 | (atom)) 182 | (expr_try_catch 183 | (catch_clause 184 | (catch_pattern 185 | (pattern 186 | (variable)) 187 | (pattern 188 | (variable)) 189 | (variable)) 190 | (guard_clause 191 | (guard_seq 192 | (guard 193 | (expr_function_call 194 | (computed_function_name 195 | (atom)) 196 | (variable))))) 197 | (atom))))) 198 | 199 | ================================================================================ 200 | try with after 201 | ================================================================================ 202 | 203 | try A after 1 end 204 | 205 | -------------------------------------------------------------------------------- 206 | 207 | (source_file 208 | (expr_try 209 | (variable) 210 | (expr_try_after 211 | (integer)))) 212 | 213 | ================================================================================ 214 | try with of patterns, after value, and multiple catch branches 215 | ================================================================================ 216 | 217 | try A of 218 | A when is_good(A) -> ok 219 | catch 220 | Class:ExceptionPattern:Stacktrace when is_good(Stacktrace) -> ok; 221 | _ -> error 222 | after 223 | noop 224 | end 225 | 226 | 227 | -------------------------------------------------------------------------------- 228 | 229 | (source_file 230 | (expr_try 231 | (variable) 232 | (case_clause 233 | (pattern 234 | (variable)) 235 | (guard_clause 236 | (guard_seq 237 | (guard 238 | (expr_function_call 239 | (computed_function_name 240 | (atom)) 241 | (variable))))) 242 | (atom)) 243 | (expr_try_catch 244 | (catch_clause 245 | (catch_pattern 246 | (pattern 247 | (variable)) 248 | (pattern 249 | (variable)) 250 | (variable)) 251 | (guard_clause 252 | (guard_seq 253 | (guard 254 | (expr_function_call 255 | (computed_function_name 256 | (atom)) 257 | (variable))))) 258 | (atom)) 259 | (catch_clause 260 | (catch_pattern 261 | (pattern 262 | (variable))) 263 | (atom))) 264 | (expr_try_after 265 | (atom)))) 266 | -------------------------------------------------------------------------------- /test/corpus/expr_function_call.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | apply lambda without args 3 | ================================================================================ 4 | 5 | Lambda() 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_function_call 11 | (computed_function_name 12 | (variable)))) 13 | 14 | ================================================================================ 15 | apply lambda with args 16 | ================================================================================ 17 | 18 | Lambda(1) 19 | Lambda(1,2,3) 20 | 21 | -------------------------------------------------------------------------------- 22 | 23 | (source_file 24 | (expr_function_call 25 | (computed_function_name 26 | (variable)) 27 | (integer)) 28 | (expr_function_call 29 | (computed_function_name 30 | (variable)) 31 | (integer) 32 | (integer) 33 | (integer))) 34 | 35 | ================================================================================ 36 | nested lambda application 37 | ================================================================================ 38 | 39 | Op(1, Lambda(1,2,3)) 40 | 41 | -------------------------------------------------------------------------------- 42 | 43 | (source_file 44 | (expr_function_call 45 | (computed_function_name 46 | (variable)) 47 | (integer) 48 | (expr_function_call 49 | (computed_function_name 50 | (variable)) 51 | (integer) 52 | (integer) 53 | (integer)))) 54 | 55 | ================================================================================ 56 | qualified function call without args 57 | ================================================================================ 58 | 59 | local:function() 60 | 61 | -------------------------------------------------------------------------------- 62 | 63 | (source_file 64 | (expr_function_call 65 | (qualified_function_name 66 | (atom) 67 | (atom)))) 68 | 69 | ================================================================================ 70 | qualified function call with args 71 | ================================================================================ 72 | 73 | local:function(1) 74 | local:function(1,2,3) 75 | 76 | -------------------------------------------------------------------------------- 77 | 78 | (source_file 79 | (expr_function_call 80 | (qualified_function_name 81 | (atom) 82 | (atom)) 83 | (integer)) 84 | (expr_function_call 85 | (qualified_function_name 86 | (atom) 87 | (atom)) 88 | (integer) 89 | (integer) 90 | (integer))) 91 | 92 | ================================================================================ 93 | nested qualified function calls 94 | ================================================================================ 95 | 96 | local:op(1, local:function(1,2,3)) 97 | 98 | -------------------------------------------------------------------------------- 99 | 100 | (source_file 101 | (expr_function_call 102 | (qualified_function_name 103 | (atom) 104 | (atom)) 105 | (integer) 106 | (expr_function_call 107 | (qualified_function_name 108 | (atom) 109 | (atom)) 110 | (integer) 111 | (integer) 112 | (integer)))) 113 | 114 | ================================================================================ 115 | local function call without args 116 | ================================================================================ 117 | 118 | local_function(). 119 | 120 | -------------------------------------------------------------------------------- 121 | 122 | (source_file 123 | (atom) 124 | (ERROR)) 125 | 126 | ================================================================================ 127 | local function call with args 128 | ================================================================================ 129 | 130 | A = local_function(1) 131 | 132 | -------------------------------------------------------------------------------- 133 | 134 | (source_file 135 | (expr_match 136 | (variable) 137 | (expr_function_call 138 | (computed_function_name 139 | (atom)) 140 | (integer)))) 141 | 142 | ================================================================================ 143 | nested local function calls 144 | ================================================================================ 145 | 146 | A = local_op(1, local_function(1)) 147 | 148 | -------------------------------------------------------------------------------- 149 | 150 | (source_file 151 | (expr_match 152 | (variable) 153 | (expr_function_call 154 | (computed_function_name 155 | (atom)) 156 | (integer) 157 | (expr_function_call 158 | (computed_function_name 159 | (atom)) 160 | (integer))))) 161 | 162 | ================================================================================ 163 | mixed function calls 164 | ================================================================================ 165 | 166 | module:function(Lambda(1, 'local$function'(1,2,3))) 167 | 168 | -------------------------------------------------------------------------------- 169 | 170 | (source_file 171 | (expr_function_call 172 | (qualified_function_name 173 | (atom) 174 | (atom)) 175 | (expr_function_call 176 | (computed_function_name 177 | (variable)) 178 | (integer) 179 | (expr_function_call 180 | (computed_function_name 181 | (atom)) 182 | (integer) 183 | (integer) 184 | (integer))))) 185 | -------------------------------------------------------------------------------- /test/corpus/expr_if.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | if with a single clause 3 | ================================================================================ 4 | 5 | if Exp -> true end 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_if 11 | (if_clause 12 | (guard_seq 13 | (guard 14 | (variable))) 15 | (atom)))) 16 | 17 | ================================================================================ 18 | if with many clauses 19 | ================================================================================ 20 | 21 | if 22 | A -> B; 23 | C -> D 24 | end 25 | 26 | -------------------------------------------------------------------------------- 27 | 28 | (source_file 29 | (expr_if 30 | (if_clause 31 | (guard_seq 32 | (guard 33 | (variable))) 34 | (variable)) 35 | (if_clause 36 | (guard_seq 37 | (guard 38 | (variable))) 39 | (variable)))) 40 | 41 | ================================================================================ 42 | if with default branch 43 | ================================================================================ 44 | 45 | if 46 | A -> B; 47 | true -> D 48 | end 49 | 50 | -------------------------------------------------------------------------------- 51 | 52 | (source_file 53 | (expr_if 54 | (if_clause 55 | (guard_seq 56 | (guard 57 | (variable))) 58 | (variable)) 59 | (if_clause 60 | (guard_seq 61 | (guard 62 | (atom))) 63 | (variable)))) 64 | 65 | ================================================================================ 66 | if with guard sequence 67 | ================================================================================ 68 | 69 | if 70 | A, B; C -> D; 71 | true -> E 72 | end 73 | 74 | -------------------------------------------------------------------------------- 75 | 76 | (source_file 77 | (expr_if 78 | (if_clause 79 | (guard_seq 80 | (guard 81 | (variable) 82 | (variable)) 83 | (guard 84 | (variable))) 85 | (variable)) 86 | (if_clause 87 | (guard_seq 88 | (guard 89 | (atom))) 90 | (variable)))) 91 | -------------------------------------------------------------------------------- /test/corpus/expr_list.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | comprehensions 3 | ================================================================================ 4 | 5 | [ (X*2) || X <- [ 1,2,3 ], X > 2 ] 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_list_comprehension 11 | (expr_op 12 | (variable) 13 | (integer)) 14 | (expr_list_generator 15 | (variable) 16 | (expr_list 17 | (integer) 18 | (integer) 19 | (integer))) 20 | (expr_list_filter 21 | (expr_op 22 | (variable) 23 | (integer))))) 24 | -------------------------------------------------------------------------------- /test/corpus/expr_map.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | updates 3 | ================================================================================ 4 | 5 | M#{ 1 => V } 6 | (f())#{ k := V } 7 | 8 | -------------------------------------------------------------------------------- 9 | 10 | (source_file 11 | (expr_map_update 12 | (variable) 13 | (map 14 | (map_entry 15 | (integer) 16 | (variable)))) 17 | (expr_map_update 18 | (expr_function_call 19 | (computed_function_name 20 | (atom))) 21 | (map 22 | (map_entry 23 | (atom) 24 | (variable))))) 25 | -------------------------------------------------------------------------------- /test/corpus/expr_match.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | binding 3 | ================================================================================ 4 | 5 | A = 1 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_match 11 | (variable) 12 | (integer))) 13 | 14 | ================================================================================ 15 | matching on constants 16 | ================================================================================ 17 | 18 | 1 = A 19 | 20 | -------------------------------------------------------------------------------- 21 | 22 | (source_file 23 | (expr_match 24 | (integer) 25 | (variable))) 26 | 27 | ================================================================================ 28 | matching on tuples 29 | ================================================================================ 30 | 31 | {A, 1} = B 32 | 33 | -------------------------------------------------------------------------------- 34 | 35 | (source_file 36 | (expr_match 37 | (tuple 38 | (variable) 39 | (integer)) 40 | (variable))) 41 | 42 | ================================================================================ 43 | matching on maps 44 | ================================================================================ 45 | 46 | #{ a := A } = B 47 | 48 | -------------------------------------------------------------------------------- 49 | 50 | (source_file 51 | (expr_match 52 | (map 53 | (map_entry 54 | (atom) 55 | (variable))) 56 | (variable))) 57 | 58 | ================================================================================ 59 | matching on lists 60 | ================================================================================ 61 | 62 | [] = L 63 | [1|_] = L2 64 | [1, B] = L3 65 | [1, B | T ] = L4 66 | 67 | -------------------------------------------------------------------------------- 68 | 69 | (source_file 70 | (expr_match 71 | (expr_list) 72 | (variable)) 73 | (expr_match 74 | (expr_list 75 | (expr_list_cons 76 | (integer) 77 | (variable))) 78 | (variable)) 79 | (expr_match 80 | (expr_list 81 | (integer) 82 | (variable)) 83 | (variable)) 84 | (expr_match 85 | (expr_list 86 | (expr_list_cons 87 | (integer) 88 | (variable) 89 | (variable))) 90 | (variable))) 91 | 92 | ================================================================================ 93 | ignoring match 94 | ================================================================================ 95 | 96 | _ = 1 97 | 98 | -------------------------------------------------------------------------------- 99 | 100 | (source_file 101 | (expr_match 102 | (variable) 103 | (integer))) 104 | -------------------------------------------------------------------------------- /test/corpus/expr_operators.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | unary ops 3 | ================================================================================ 4 | 5 | +A 6 | -A 7 | bnot A 8 | not A 9 | 10 | -------------------------------------------------------------------------------- 11 | 12 | (source_file 13 | (expr_op 14 | (expr_op 15 | (variable) 16 | (variable))) 17 | (expr_op 18 | (variable)) 19 | (expr_op 20 | (variable))) 21 | 22 | ================================================================================ 23 | op left associativity 24 | ================================================================================ 25 | 26 | A * 1 * none 27 | A / 1 / none 28 | A and 1 and none 29 | A band 1 band none 30 | A div 1 div none 31 | A rem 1 rem none 32 | A + 1 + none 33 | A - 1 - none 34 | A bor 1 bor none 35 | A bsl 1 bsl none 36 | A bsr 1 bsr none 37 | A bxor 1 bxor none 38 | A or 1 or none 39 | A xor 1 xor none 40 | 41 | -------------------------------------------------------------------------------- 42 | 43 | (source_file 44 | (expr_op 45 | (expr_op 46 | (variable) 47 | (integer)) 48 | (atom)) 49 | (expr_op 50 | (expr_op 51 | (variable) 52 | (integer)) 53 | (atom)) 54 | (expr_op 55 | (expr_op 56 | (variable) 57 | (integer)) 58 | (atom)) 59 | (expr_op 60 | (expr_op 61 | (variable) 62 | (integer)) 63 | (atom)) 64 | (expr_op 65 | (expr_op 66 | (variable) 67 | (integer)) 68 | (atom)) 69 | (expr_op 70 | (expr_op 71 | (variable) 72 | (integer)) 73 | (atom)) 74 | (expr_op 75 | (expr_op 76 | (variable) 77 | (integer)) 78 | (atom)) 79 | (expr_op 80 | (expr_op 81 | (variable) 82 | (integer)) 83 | (atom)) 84 | (expr_op 85 | (expr_op 86 | (variable) 87 | (integer)) 88 | (atom)) 89 | (expr_op 90 | (expr_op 91 | (variable) 92 | (integer)) 93 | (atom)) 94 | (expr_op 95 | (expr_op 96 | (variable) 97 | (integer)) 98 | (atom)) 99 | (expr_op 100 | (expr_op 101 | (variable) 102 | (integer)) 103 | (atom)) 104 | (expr_op 105 | (expr_op 106 | (variable) 107 | (integer)) 108 | (atom)) 109 | (expr_op 110 | (expr_op 111 | (variable) 112 | (integer)) 113 | (atom))) 114 | 115 | ================================================================================ 116 | op right associativity 117 | ================================================================================ 118 | 119 | A ++ B ++ C 120 | A -- B -- C 121 | 122 | -------------------------------------------------------------------------------- 123 | 124 | (source_file 125 | (expr_op 126 | (variable) 127 | (expr_op 128 | (variable) 129 | (variable))) 130 | (expr_op 131 | (variable) 132 | (expr_op 133 | (variable) 134 | (variable)))) 135 | 136 | ================================================================================ 137 | op precedence: + - 138 | ================================================================================ 139 | 140 | 1 - - - 2 141 | 1 + - + 2 142 | 143 | -------------------------------------------------------------------------------- 144 | 145 | (source_file 146 | (expr_op 147 | (integer) 148 | (expr_op 149 | (expr_op 150 | (integer)))) 151 | (expr_op 152 | (integer) 153 | (expr_op 154 | (expr_op 155 | (integer))))) 156 | 157 | ================================================================================ 158 | binary ops 159 | ================================================================================ 160 | 161 | A - B 162 | A + B 163 | 164 | A * B 165 | A ++ B 166 | A -- B 167 | A / B 168 | A /= B 169 | A < B 170 | A =/= B 171 | A =:= B 172 | A =< B 173 | A == B 174 | A > B 175 | A >= B 176 | A and B 177 | A band B 178 | A bor B 179 | A bsl B 180 | A bsr B 181 | A bxor B 182 | A div B 183 | A or B 184 | A rem B 185 | A xor B 186 | 187 | -------------------------------------------------------------------------------- 188 | 189 | (source_file 190 | (expr_op 191 | (variable) 192 | (variable)) 193 | (expr_op 194 | (variable) 195 | (variable)) 196 | (expr_op 197 | (variable) 198 | (variable)) 199 | (expr_op 200 | (variable) 201 | (variable)) 202 | (expr_op 203 | (variable) 204 | (variable)) 205 | (expr_op 206 | (variable) 207 | (variable)) 208 | (expr_op 209 | (variable) 210 | (variable)) 211 | (expr_op 212 | (variable) 213 | (variable)) 214 | (expr_op 215 | (variable) 216 | (variable)) 217 | (expr_op 218 | (variable) 219 | (variable)) 220 | (expr_op 221 | (variable) 222 | (variable)) 223 | (expr_op 224 | (variable) 225 | (variable)) 226 | (expr_op 227 | (variable) 228 | (variable)) 229 | (expr_op 230 | (variable) 231 | (variable)) 232 | (expr_op 233 | (variable) 234 | (variable)) 235 | (expr_op 236 | (variable) 237 | (variable)) 238 | (expr_op 239 | (variable) 240 | (variable)) 241 | (expr_op 242 | (variable) 243 | (variable)) 244 | (expr_op 245 | (variable) 246 | (variable)) 247 | (expr_op 248 | (variable) 249 | (variable)) 250 | (expr_op 251 | (variable) 252 | (variable)) 253 | (expr_op 254 | (variable) 255 | (variable)) 256 | (expr_op 257 | (variable) 258 | (variable)) 259 | (expr_op 260 | (variable) 261 | (variable))) 262 | -------------------------------------------------------------------------------- /test/corpus/expr_receive.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | receive anything 3 | ================================================================================ 4 | 5 | receive _ -> ok end 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_receive 11 | (case_clause 12 | (pattern 13 | (variable)) 14 | (atom)))) 15 | 16 | ================================================================================ 17 | receive with branches 18 | ================================================================================ 19 | 20 | receive 21 | true -> false; 22 | false -> true 23 | end 24 | 25 | -------------------------------------------------------------------------------- 26 | 27 | (source_file 28 | (expr_receive 29 | (case_clause 30 | (pattern 31 | (atom)) 32 | (atom)) 33 | (case_clause 34 | (pattern 35 | (atom)) 36 | (atom)))) 37 | 38 | ================================================================================ 39 | receive with branches with guards 40 | ================================================================================ 41 | 42 | receive 43 | A when is_good(A) -> false; 44 | false -> true 45 | end 46 | 47 | -------------------------------------------------------------------------------- 48 | 49 | (source_file 50 | (expr_receive 51 | (case_clause 52 | (pattern 53 | (variable)) 54 | (guard_clause 55 | (guard_seq 56 | (guard 57 | (expr_function_call 58 | (computed_function_name 59 | (atom)) 60 | (variable))))) 61 | (atom)) 62 | (case_clause 63 | (pattern 64 | (atom)) 65 | (atom)))) 66 | 67 | ================================================================================ 68 | receive with timeout 69 | ================================================================================ 70 | 71 | receive 72 | _ -> ok 73 | after 74 | infinity -> not_ok 75 | end 76 | 77 | -------------------------------------------------------------------------------- 78 | 79 | (source_file 80 | (expr_receive 81 | (case_clause 82 | (pattern 83 | (variable)) 84 | (atom)) 85 | (expr_receive_after 86 | (case_clause 87 | (pattern 88 | (atom)) 89 | (atom))))) 90 | 91 | ================================================================================ 92 | receive without branches 93 | ================================================================================ 94 | 95 | receive after 96 | infinity -> not_ok 97 | end 98 | 99 | -------------------------------------------------------------------------------- 100 | 101 | (source_file 102 | (expr_receive 103 | (expr_receive_after 104 | (case_clause 105 | (pattern 106 | (atom)) 107 | (atom))))) 108 | -------------------------------------------------------------------------------- /test/corpus/expr_send.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | send 3 | ================================================================================ 4 | 5 | a ! b 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_send 11 | (atom) 12 | (atom))) 13 | 14 | ================================================================================ 15 | associativity 16 | ================================================================================ 17 | 18 | a ! b ! c 19 | 20 | -------------------------------------------------------------------------------- 21 | 22 | (source_file 23 | (expr_send 24 | (atom) 25 | (expr_send 26 | (atom) 27 | (atom)))) 28 | -------------------------------------------------------------------------------- /test/corpus/expr_variable.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | named 3 | ================================================================================ 4 | 5 | A 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (variable)) 11 | 12 | ================================================================================ 13 | named with numbers 14 | ================================================================================ 15 | 16 | A1234 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (variable)) 22 | 23 | ================================================================================ 24 | class cased 25 | ================================================================================ 26 | 27 | AnotherVariable 28 | 29 | -------------------------------------------------------------------------------- 30 | 31 | (source_file 32 | (variable)) 33 | 34 | ================================================================================ 35 | jiraffe cased 36 | ================================================================================ 37 | 38 | Another_variable 39 | 40 | -------------------------------------------------------------------------------- 41 | 42 | (source_file 43 | (variable)) 44 | 45 | ================================================================================ 46 | ignored with name 47 | ================================================================================ 48 | 49 | _A 50 | 51 | -------------------------------------------------------------------------------- 52 | 53 | (source_file 54 | (variable)) 55 | 56 | ================================================================================ 57 | ignored 58 | ================================================================================ 59 | 60 | _ 61 | 62 | -------------------------------------------------------------------------------- 63 | 64 | (source_file 65 | (variable)) 66 | -------------------------------------------------------------------------------- /test/corpus/incomplete.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | unfinished function clause 3 | ================================================================================ 4 | 5 | f(1) -> 1 6 | -------------------------------------------------------------------------------- /test/corpus/macros.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | macro usage 3 | ================================================================================ 4 | 5 | ?MY_MACRO 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_macro_application 11 | (variable))) 12 | 13 | ================================================================================ 14 | macro application 15 | ================================================================================ 16 | 17 | ?MY_MACRO(2) 18 | ?MY_MACRO(2, [1]) 19 | ?MY_MACRO(2, [1], ?MY_MACRO_EXTRA) 20 | 21 | -------------------------------------------------------------------------------- 22 | 23 | (source_file 24 | (expr_macro_application 25 | (variable) 26 | (integer)) 27 | (expr_macro_application 28 | (variable) 29 | (integer) 30 | (expr_list 31 | (integer))) 32 | (expr_macro_application 33 | (variable) 34 | (integer) 35 | (expr_list 36 | (integer)) 37 | (expr_macro_application 38 | (variable)))) 39 | -------------------------------------------------------------------------------- /test/corpus/module_attribute.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | name attribute 3 | ================================================================================ 4 | 5 | -module(name). 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (module_name 11 | (atom))) 12 | 13 | ================================================================================ 14 | export attribute 15 | ================================================================================ 16 | 17 | -export([hello/0, what/1]). 18 | -export_type([t/0, t_aux/1]). 19 | 20 | -------------------------------------------------------------------------------- 21 | 22 | (source_file 23 | (module_export 24 | (atom) 25 | (integer) 26 | (atom) 27 | (integer)) 28 | (module_export 29 | (atom) 30 | (integer) 31 | (atom) 32 | (integer))) 33 | -------------------------------------------------------------------------------- /test/corpus/module_function.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | single clause function 3 | ================================================================================ 4 | 5 | main() -> ok. 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (function_declaration 11 | (function_clause 12 | (atom) 13 | (lambda_clause 14 | (atom))))) 15 | 16 | ================================================================================ 17 | single clause function with one arg 18 | ================================================================================ 19 | 20 | main(A) -> ok. 21 | 22 | -------------------------------------------------------------------------------- 23 | 24 | (source_file 25 | (function_declaration 26 | (function_clause 27 | (atom) 28 | (lambda_clause 29 | (pattern 30 | (variable)) 31 | (atom))))) 32 | 33 | ================================================================================ 34 | single clause function with one ignored arg 35 | ================================================================================ 36 | 37 | main(_) -> ok. 38 | 39 | -------------------------------------------------------------------------------- 40 | 41 | (source_file 42 | (function_declaration 43 | (function_clause 44 | (atom) 45 | (lambda_clause 46 | (pattern 47 | (variable)) 48 | (atom))))) 49 | 50 | ================================================================================ 51 | multi clause function 52 | ================================================================================ 53 | 54 | main([]) -> ok; 55 | main(Args) -> ok. 56 | 57 | -------------------------------------------------------------------------------- 58 | 59 | (source_file 60 | (function_declaration 61 | (function_clause 62 | (atom) 63 | (lambda_clause 64 | (pattern 65 | (pat_list)) 66 | (atom))) 67 | (function_clause 68 | (atom) 69 | (lambda_clause 70 | (pattern 71 | (variable)) 72 | (atom))))) 73 | -------------------------------------------------------------------------------- /test/corpus/playground.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | playground example code 3 | ================================================================================ 4 | -module(hello_joe). 5 | 6 | -export([main/1]). 7 | 8 | % that's right. we got this. 9 | main([]) -> ok; 10 | main([Name | _]) -> io:format(<<"Hello, ~p!">>, [Name]). 11 | 12 | -------------------------------------------------------------------------------- 13 | 14 | (source_file 15 | (module_name 16 | (atom)) 17 | (module_export 18 | (atom) 19 | (integer)) 20 | (comment) 21 | (function_declaration 22 | (function_clause 23 | (atom) 24 | (lambda_clause 25 | (pattern 26 | (pat_list)) 27 | (atom))) 28 | (function_clause 29 | (atom) 30 | (lambda_clause 31 | (pattern 32 | (pat_list 33 | (pat_list_cons 34 | (pattern 35 | (variable)) 36 | (pattern 37 | (variable))))) 38 | (expr_function_call 39 | (qualified_function_name 40 | (atom) 41 | (atom)) 42 | (binary_string 43 | (bin_part 44 | (string))) 45 | (expr_list 46 | (variable))))))) 47 | -------------------------------------------------------------------------------- /test/corpus/term_atom.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | simple 3 | ================================================================================ 4 | 5 | atom 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (atom)) 11 | 12 | ================================================================================ 13 | simple with symbol 14 | ================================================================================ 15 | 16 | a_to_mic 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (atom)) 22 | 23 | ================================================================================ 24 | simple with number 25 | ================================================================================ 26 | 27 | atom1 28 | 29 | -------------------------------------------------------------------------------- 30 | 31 | (source_file 32 | (atom)) 33 | 34 | ================================================================================ 35 | mixed case 36 | ================================================================================ 37 | 38 | anAtom 39 | 40 | -------------------------------------------------------------------------------- 41 | 42 | (source_file 43 | (atom)) 44 | 45 | ================================================================================ 46 | mixed case with number 47 | ================================================================================ 48 | 49 | anAtom9 50 | 51 | -------------------------------------------------------------------------------- 52 | 53 | (source_file 54 | (atom)) 55 | 56 | ================================================================================ 57 | quoted atom 58 | ================================================================================ 59 | 60 | 'atom' 61 | 62 | -------------------------------------------------------------------------------- 63 | 64 | (source_file 65 | (atom)) 66 | 67 | ================================================================================ 68 | quoted atom with number 69 | ================================================================================ 70 | 71 | 'atom' 72 | 73 | -------------------------------------------------------------------------------- 74 | 75 | (source_file 76 | (atom)) 77 | 78 | ================================================================================ 79 | quoted atom with symbols 80 | ================================================================================ 81 | 82 | 'a.to!m"ic_0#%@^&*()}{[]' 83 | 84 | -------------------------------------------------------------------------------- 85 | 86 | (source_file 87 | (atom)) 88 | 89 | ================================================================================ 90 | quoted atom with escapes 91 | ================================================================================ 92 | 93 | 'abc\0\00\000\xAA\x{DEADBEEF}\n\r\t\v\b\f\e\s\d\ 94 | ' 95 | 96 | -------------------------------------------------------------------------------- 97 | 98 | (source_file 99 | (atom)) 100 | -------------------------------------------------------------------------------- /test/corpus/term_binary_string.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | empty 3 | ================================================================================ 4 | 5 | <<>> 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (binary_string)) 11 | 12 | ================================================================================ 13 | with integer 14 | ================================================================================ 15 | 16 | <<10>> 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (binary_string 22 | (bin_part 23 | (integer)))) 24 | 25 | ================================================================================ 26 | with integer and type-specifier 27 | ================================================================================ 28 | 29 | <<10/integer>> 30 | 31 | -------------------------------------------------------------------------------- 32 | 33 | (source_file 34 | (binary_string 35 | (bin_part 36 | (integer) 37 | (bin_type_list 38 | (bin_type))))) 39 | 40 | ================================================================================ 41 | with integer and multiple type-specifier 42 | ================================================================================ 43 | 44 | <<10/integer-signed-native>> 45 | 46 | -------------------------------------------------------------------------------- 47 | 48 | (source_file 49 | (binary_string 50 | (bin_part 51 | (integer) 52 | (bin_type_list 53 | (bin_type) 54 | (bin_type) 55 | (bin_type))))) 56 | 57 | ================================================================================ 58 | with integer and bit-pattern size 59 | ================================================================================ 60 | 61 | <<10:2>> 62 | 63 | -------------------------------------------------------------------------------- 64 | 65 | (source_file 66 | (binary_string 67 | (bin_part 68 | (integer) 69 | (bin_sized 70 | (integer))))) 71 | 72 | ================================================================================ 73 | with integer and bit-pattern size and type-specifier 74 | ================================================================================ 75 | 76 | <<10:2/little>> 77 | 78 | -------------------------------------------------------------------------------- 79 | 80 | (source_file 81 | (binary_string 82 | (bin_part 83 | (integer) 84 | (bin_sized 85 | (integer)) 86 | (bin_type_list 87 | (bin_type))))) 88 | 89 | ================================================================================ 90 | with integer and bit-pattern size and multiple type-specifiers 91 | ================================================================================ 92 | 93 | <<10:2/little-unsigned>> 94 | 95 | -------------------------------------------------------------------------------- 96 | 97 | (source_file 98 | (binary_string 99 | (bin_part 100 | (integer) 101 | (bin_sized 102 | (integer)) 103 | (bin_type_list 104 | (bin_type) 105 | (bin_type))))) 106 | 107 | ================================================================================ 108 | with float 109 | ================================================================================ 110 | 111 | <<10.10>> 112 | 113 | -------------------------------------------------------------------------------- 114 | 115 | (source_file 116 | (binary_string 117 | (bin_part 118 | (float)))) 119 | 120 | ================================================================================ 121 | with float and type-specifier 122 | ================================================================================ 123 | 124 | <<10.10/float>> 125 | 126 | -------------------------------------------------------------------------------- 127 | 128 | (source_file 129 | (binary_string 130 | (bin_part 131 | (float) 132 | (bin_type_list 133 | (bin_type))))) 134 | 135 | ================================================================================ 136 | with float and multiple type-specifier 137 | ================================================================================ 138 | 139 | <<10.10/float-signed-native>> 140 | 141 | -------------------------------------------------------------------------------- 142 | 143 | (source_file 144 | (binary_string 145 | (bin_part 146 | (float) 147 | (bin_type_list 148 | (bin_type) 149 | (bin_type) 150 | (bin_type))))) 151 | 152 | ================================================================================ 153 | with float and bit-pattern size 154 | ================================================================================ 155 | 156 | <<10.10:2>> 157 | 158 | -------------------------------------------------------------------------------- 159 | 160 | (source_file 161 | (binary_string 162 | (bin_part 163 | (float) 164 | (bin_sized 165 | (integer))))) 166 | 167 | ================================================================================ 168 | with float and bit-pattern size and type-specifier 169 | ================================================================================ 170 | 171 | <<10.10:2/little>> 172 | 173 | -------------------------------------------------------------------------------- 174 | 175 | (source_file 176 | (binary_string 177 | (bin_part 178 | (float) 179 | (bin_sized 180 | (integer)) 181 | (bin_type_list 182 | (bin_type))))) 183 | 184 | ================================================================================ 185 | with float and bit-pattern size and multiple type-specifiers 186 | ================================================================================ 187 | 188 | <<10.10:2/little-unsigned>> 189 | 190 | -------------------------------------------------------------------------------- 191 | 192 | (source_file 193 | (binary_string 194 | (bin_part 195 | (float) 196 | (bin_sized 197 | (integer)) 198 | (bin_type_list 199 | (bin_type) 200 | (bin_type))))) 201 | 202 | ================================================================================ 203 | with string 204 | ================================================================================ 205 | 206 | <<"10">> 207 | 208 | -------------------------------------------------------------------------------- 209 | 210 | (source_file 211 | (binary_string 212 | (bin_part 213 | (string)))) 214 | 215 | ================================================================================ 216 | with many components 217 | ================================================================================ 218 | 219 | <<10:1/native, "hello", 10.2/unsigned, (A)/binary, (B):8>> 220 | 221 | -------------------------------------------------------------------------------- 222 | 223 | (source_file 224 | (binary_string 225 | (bin_part 226 | (integer) 227 | (bin_sized 228 | (integer)) 229 | (bin_type_list 230 | (bin_type))) 231 | (bin_part 232 | (string)) 233 | (bin_part 234 | (float) 235 | (bin_type_list 236 | (bin_type))) 237 | (bin_part 238 | (variable) 239 | (bin_type_list 240 | (bin_type))) 241 | (bin_part 242 | (variable) 243 | (bin_sized 244 | (integer))))) 245 | -------------------------------------------------------------------------------- /test/corpus/term_char.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | alphanum 3 | ================================================================================ 4 | 5 | $a 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (char)) 11 | -------------------------------------------------------------------------------- /test/corpus/term_float.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | small 3 | ================================================================================ 4 | 5 | 0.0 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (float)) 11 | 12 | ================================================================================ 13 | negative 14 | ================================================================================ 15 | 16 | -0.0 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (float)) 22 | 23 | ================================================================================ 24 | large 25 | ================================================================================ 26 | 27 | 100000.25974069347221723 28 | 29 | -------------------------------------------------------------------------------- 30 | 31 | (source_file 32 | (float)) 33 | 34 | ================================================================================ 35 | large with separator 36 | ================================================================================ 37 | 38 | 100_000.259_740_693 39 | 40 | -------------------------------------------------------------------------------- 41 | 42 | (source_file 43 | (float)) 44 | 45 | ================================================================================ 46 | exponential notation 47 | ================================================================================ 48 | 49 | 2.5974069347221725e195 50 | 51 | -------------------------------------------------------------------------------- 52 | 53 | (source_file 54 | (float)) 55 | 56 | ================================================================================ 57 | negative exponential notation 58 | ================================================================================ 59 | 60 | 2.5974069347221725e-195 61 | 62 | -------------------------------------------------------------------------------- 63 | 64 | (source_file 65 | (float)) 66 | -------------------------------------------------------------------------------- /test/corpus/term_fun.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | constant without args 3 | ================================================================================ 4 | 5 | fun () -> ok end 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_lambda 11 | (lambda_clause 12 | (atom)))) 13 | 14 | ================================================================================ 15 | identity function 16 | ================================================================================ 17 | 18 | fun (X) -> X end 19 | 20 | -------------------------------------------------------------------------------- 21 | 22 | (source_file 23 | (expr_lambda 24 | (lambda_clause 25 | (pattern 26 | (variable)) 27 | (variable)))) 28 | 29 | ================================================================================ 30 | multiple clauses 31 | ================================================================================ 32 | 33 | fun 34 | ([]) -> ok; 35 | (Args) when Args > 0 -> Args 36 | end 37 | 38 | -------------------------------------------------------------------------------- 39 | 40 | (source_file 41 | (expr_lambda 42 | (lambda_clause 43 | (pattern 44 | (pat_list)) 45 | (atom)) 46 | (lambda_clause 47 | (pattern 48 | (variable)) 49 | (guard_clause 50 | (guard_seq 51 | (guard 52 | (expr_op 53 | (variable) 54 | (integer))))) 55 | (variable)))) 56 | -------------------------------------------------------------------------------- /test/corpus/term_integer.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | small 3 | ================================================================================ 4 | 5 | 0 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (integer)) 11 | 12 | ================================================================================ 13 | large 14 | ================================================================================ 15 | 16 | 123456789123456789 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (integer)) 22 | 23 | ================================================================================ 24 | with separator 25 | ================================================================================ 26 | 27 | 123_45_67891_2345_6789 28 | 29 | -------------------------------------------------------------------------------- 30 | 31 | (source_file 32 | (integer)) 33 | 34 | ================================================================================ 35 | negative 36 | ================================================================================ 37 | 38 | -123456789123456789 39 | 40 | -------------------------------------------------------------------------------- 41 | 42 | (source_file 43 | (integer)) 44 | 45 | ================================================================================ 46 | fib(10000) 47 | ================================================================================ 48 | 49 | 2597406934722172416615503402127591541488048538651769658472477070395253454351127368626555677283671674475463758722307443211163839947387509103096569738218830449305228763853133492135302679278956701051276578271635608073050532200243233114383986516137827238124777453778337299916214634050054669860390862750996639366409211890125271960172105060300350586894028558103675117658251368377438684936413457338834365158775425371912410500332195991330062204363035213756525421823998690848556374080179251761629391754963458558616300762819916081109836526352995440694284206571046044903805647136346033000520852277707554446794723709030979019014860432846819857961015951001850608264919234587313399150133919932363102301864172536477136266475080133982431231703431452964181790051187957316766834979901682011849907756686456845066287392485603914047605199550066288826345877189410680370091879365001733011710028310473947456256091444932821374855573864080579813028266640270354294412104919995803131876805899186513425175959911520563155337703996941035518275274919959802257507902037798103089922984996304496255814045517000250299764322193462165366210841876745428298261398234478366581588040819003307382939500082132009374715485131027220817305432264866949630987914714362925554252624043999615326979876807510646819068792118299167964409178271868561702918102212679267401362650499784968843680975254700131004574186406448299485872551744746695651879126916993244564817673322257149314967763345846623830333820239702436859478287641875788572910710133700300094229333597292779191409212804901545976262791057055248158884051779418192905216769576608748815567860128818354354292307397810154785701328438612728620176653953444993001980062953893698550072328665131718113588661353747268458543254898113717660519461693791688442534259478126310388952047956594380715301911253964847112638900713362856910155145342332944128435722099628674611942095166100230974070996553190050815866991144544264788287264284501725332048648319457892039984893823636745618220375097348566847433887249049337031633826571760729778891798913667325190623247118037280173921572390822769228077292456662750538337500692607721059361942126892030256744356537800831830637593334502350256972906515285327194367756015666039916404882563967693079290502951488693413799125174856667074717514938979038653338139534684837808612673755438382110844897653836848318258836339917310455850905663846202501463131183108742907729262215943020429159474030610183981685506695026197376150857176119947587572212987205312060791864980361596092339594104118635168854883911918517906151156275293615849000872150192226511785315089251027528045151238603792184692121533829287136924321527332714157478829590260157195485316444794546750285840236000238344790520345108033282013803880708980734832620122795263360677366987578332625485944906021917368867786241120562109836985019729017715780112040458649153935115783499546100636635745448508241888279067531359950519206222976015376529797308588164873117308237059828489404487403932053592935976454165560795472477862029969232956138971989467942218727360512336559521133108778758228879597580320459608479024506385194174312616377510459921102486879496341706862092908893068525234805692599833377510390101316617812305114571932706629167125446512151746802548190358351688971707570677865618800822034683632101813026232996027599403579997774046244952114531588370357904483293150007246173417355805567832153454341170020258560809166294198637401514569572272836921963229511187762530753402594781448204657460288485500062806934811398276016855584079542162057543557291510641537592939022884356120792643705560062367986544382464373946972471945996555795505838034825597839682776084731530251788951718630722761103630509360074262261717363058613291544024695432904616258691774630578507674937487992329181750163484068813465534370997589353607405172909412697657593295156818624747127636468836551757018353417274662607306510451195762866349922848678780591085118985653555434958761664016447588028633629704046289097067736256584300235314749461233912068632146637087844699210427541569410912246568571204717241133378489816764096924981633421176857150311671040068175303192115415611958042570658693127276213710697472226029655524611053715554532499750843275200199214301910505362996007042963297805103066650638786268157658772683745128976850796366371059380911225428835839194121154773759981301921650952140133306070987313732926518169226845063443954056729812031546392324981793780469103793422169495229100793029949237507299325063050942813902793084134473061411643355614764093104425918481363930542369378976520526456347648318272633371512112030629233889286487949209737847861884868260804647319539200840398308008803869049557419756219293922110825766397681361044490024720948340326796768837621396744075713887292863079821849314343879778088737958896840946143415927131757836511457828935581859902923534388888846587452130838137779443636119762839036894595760120316502279857901545344747352706972851454599861422902737291131463782045516225447535356773622793648545035710208644541208984235038908770223039849380214734809687433336225449150117411751570704561050895274000206380497967960402617818664481248547269630823473377245543390519841308769781276565916764229022948181763075710255793365008152286383634493138089971785087070863632205869018938377766063006066757732427272929247421295265000706646722730009956124191409138984675224955790729398495608750456694217771551107346630456603944136235888443676215273928597072287937355966723924613827468703217858459948257514745406436460997059316120596841560473234396652457231650317792833860590388360417691428732735703986803342604670071717363573091122981306903286137122597937096605775172964528263757434075792282180744352908669606854021718597891166333863858589736209114248432178645039479195424208191626088571069110433994801473013100869848866430721216762473119618190737820766582968280796079482259549036328266578006994856825300536436674822534603705134503603152154296943991866236857638062351209884448741138600171173647632126029961408561925599707566827866778732377419444462275399909291044697716476151118672327238679208133367306181944849396607123345271856520253643621964198782752978813060080313141817069314468221189275784978281094367751540710106350553798003842219045508482239386993296926659221112742698133062300073465628498093636693049446801628553712633412620378491919498600097200836727876650786886306933418995225768314390832484886340318940194161036979843833346608676709431643653538430912157815543512852077720858098902099586449602479491970687230765687109234380719509824814473157813780080639358418756655098501321882852840184981407690738507369535377711880388528935347600930338598691608289335421147722936561907276264603726027239320991187820407067412272258120766729040071924237930330972132364184093956102995971291799828290009539147382437802779051112030954582532888721146170133440385939654047806199333224547317803407340902512130217279595753863158148810392952475410943880555098382627633127606718126171022011356181800775400227516734144169216424973175621363128588281978005788832454534581522434937268133433997710512532081478345067139835038332901313945986481820272322043341930929011907832896569222878337497354301561722829115627329468814853281922100752373626827643152685735493223028018101449649009015529248638338885664893002250974343601200814365153625369199446709711126951966725780061891215440222487564601554632812091945824653557432047644212650790655208208337976071465127508320487165271577472325887275761128357592132553934446289433258105028633583669291828566894736223508250294964065798630809614341696830467595174355313224362664207197608459024263017473392225291248366316428006552870975051997504913009859468071013602336440164400179188610853230764991714372054467823597211760465153200163085336319351589645890681722372812310320271897917951272799656053694032111242846590994556380215461316106267521633805664394318881268199494005537068697621855231858921100963441012933535733918459668197539834284696822889460076352031688922002021931318369757556962061115774305826305535862015637891246031220672933992617378379625150999935403648731423208873977968908908369996292995391977217796533421249291978383751460062054967341662833487341011097770535898066498136011395571584328308713940582535274056081011503907941688079197212933148303072638678631411038443128215994936824342998188719768637604496342597524256886188688978980888315865076262604856465004322896856149255063968811404400429503894245872382233543101078691517328333604779262727765686076177705616874050257743749983775830143856135427273838589774133526949165483929721519554793578923866762502745370104660909382449626626935321303744538892479216161188889702077910448563199514826630802879549546453583866307344423753319712279158861707289652090149848305435983200771326653407290662016775706409690183771201306823245333477966660525325490873601961480378241566071271650383582257289215708209369510995890132859490724306183325755201208090007175022022949742801823445413711916298449914722254196594682221468260644961839254249670903104007581488857971672246322887016438403908463856731164308169537326790303114583680575021119639905615169154708510459700542098571797318015564741406172334145847111268547929892443001391468289103679179216978616582489007322033591376706527676521307143985302760988478056216994659655461379174985659739227379416726495377801992098355427866179123126699374730777730569324430166839333011554515542656864937492128687049121754245967831132969248492466744261999033972825674873460201150442228780466124320183016108232183908654771042398228531316559685688005226571474428823317539456543881928624432662503345388199590085105211383124491861802624432195540433985722841341254409411771722156867086291742124053110620522842986199273629406208834754853645128123279609097213953775360023076765694208219943034648783348544492713539450224591334374664937701655605763384697062918725745426505879414630176639760457474311081556747091652708748125267159913793240527304613693961169892589808311906322510777928562071999459487700611801002296132304588294558440952496611158342804908643860880796440557763691857743754025896855927252514563404385217825890599553954627451385454452916761042969267970893580056234501918571489030418495767400819359973218711957496357095967825171096264752068890806407651445893132870767454169607107931692704285168093413311046353506242209810363216771910420786162184213763938194625697286781413636389620123976910465418956806197323148414224550071617215851321302030684176087215892702098879108938081045903397276547326416916845445627600759561367103584575649094430692452532085003091068783157561519847567569191284784654692558665111557913461272425336083635131342183905177154511228464455136016013513228948543271504760839307556100908786096663870612278690274831819331606701484957163004705262228238406266818448788374548131994380387613830128859885264201992286188208499588640888521352501457615396482647451025902530743172956899636499615707551855837165935367125448515089362904567736630035562457374779100987992499146967224041481601289530944015488942613783140087804311431741858071826185149051138744831358439067228949408258286021650288927228387426432786168690381960530155894459451808735197246008221529343980828254126128257157209350985382800738560472910941184006084485235377833503306861977724501886364070344973366473100602018128792886991861824418453968994777259482169137133647470453172979809245844361129618997595696240971845564020511432589591844724920942930301651488713079802102379065536525154780298059407529440513145807551537794861635879901158192019808879694967187448224156836463534326160242632934761634458163890163805123894184523973421841496889262398489648642093409816681494771155177009562669029850101513537599801272501241971119871526593747484778935488777815192931171431167444773882941064615028751327709474504763922874890662989841540259350834035142035136168819248238998027706666916342133424312054507359388616687691188185776118135771332483965209882085982391298606386822804754362408956522921410859852037330544625953261340234864689275060526893755148403298542086991221052597005628576707702567695300978970046408920009852106980295419699802138053295798159478289934443245491565327845223840551240445208226435420656313310702940722371552770504263482073984454889589248861397657079145414427653584572951329719091947694411910966797474262675590953832039169673494261360032263077428684105040061351052194413778158095005714526846009810352109249040027958050736436961021241137739717164869525493114805040126568351268829598413983222676377804500626507241731757395219796890754825199329259649801627068665658030178877405615167159731927320479376247375505855052839660294566992522173600874081212014209071041937598571721431338017425141582491824710905084715977249417049320254165239323233258851588893337097136310892571531417761978326033750109026284066415801371359356529278088456305951770081443994114674291850360748852366654744869928083230516815711602911836374147958492100860528981469547750812338896943152861021202736747049903930417035171342126923486700566627506229058636911882228903170510305406882096970875545329369434063981297696478031825451642178347347716471058423238594580183052756213910186997604305844068665712346869679456044155742100039179758348979935882751881524675930878928159243492197545387668305684668420775409821781247053354523194797398953320175988640281058825557698004397120538312459428957377696001857497335249965013509368925958021863811725906506436882127156815751021712900765992750370228283963962915973251173418586721023497317765969454283625519371556009143680329311962842546628403142444370648432390374906410811300792848955767243481200090309888457270907750873638873299642555050473812528975962934822878917619920725138309388288292510416837622758204081918933603653875284116785703720989718832986921927816629675844580174911809119663048187434155067790863948831489241504300476704527971283482211522202837062857314244107823792513645086677566622804977211397140621664116324756784216612961477109018826094677377686406176721484293894976671380122788941309026553511096118347012565197540807095384060916863936906673786627209429434264260402902158317345003727462588992622049877121178405563348492490326003508569099382392777297498413565614830788262363322368380709822346012274241379036473451735925215754757160934270935192901723954921426490691115271523338109124042812102893738488167358953934508930697715522989199698903885883275409044300321986834003470271220020159699371690650330547577095398748580670024491045504890061727189168031394528036165633941571334637222550477547460756055024108764382121688848916940371258901948490685379722244562009483819491532724502276218589169507405794983759821006604481996519360110261576947176202571702048684914616894068404140833587562118319210838005632144562018941505945780025318747471911604840677997765414830622179069330853875129298983009580277554145435058768984944179136535891620098725222049055183554603706533183176716110738009786625247488691476077664470147193074476302411660335671765564874440577990531996271632972009109449249216456030618827772947750764777446452586328919159107444252320082918209518021083700353881330983215894608680127954224752071924134648334963915094813097541433244209299930751481077919002346128122330161799429930618800533414550633932139339646861616416955220216447995417243171165744471364197733204899365074767844149929548073025856442942381787641506492878361767978677158510784235702640213388018875601989234056868423215585628508645525258377010620532224244987990625263484010774322488172558602233302076399933854152015343847725442917895130637050320444917797752370871958277976799686113626532291118629631164685159934660693460557545956063155830033697634000276685151293843638886090828376141157732003527565158745906567025439437931104838571313294490604926582363108949535090082673154497226396648088618041573977888472892174618974189721700770009862449653759012727015227634510874906948012210684952063002519011655963580552429180205586904259685261047412834518466736938580027700252965356366721619883672428226933950325930390994583168665542234654857020875504617520521853721567282679903418135520602999895366470106557900532129541336924472492212436324523042895188461779122338069674233980694887270587503389228395095135209123109258159006960395156367736067109050566299603571876423247920752836160805597697778756476767210521222327184821484446631261487584226092608875764331731023263768864822594691211032367737558122133470556805958008310127481673962019583598023967414489867276845869819376783757167936723213081586191045995058970991064686919463448038574143829629547131372173669836184558144505748676124322451519943362182916191468026091121793001864788050061351603144350076189213441602488091741051232290357179205497927970924502479940842696158818442616163780044759478212240873204124421169199805572649118243661921835714762891425805771871743688000324113008704819373962295017143090098476927237498875938639942530595331607891618810863505982444578942799346514915952884869757488025823353571677864826828051140885429732788197765736966005727700162592404301688659946862983717270595809808730901820120931003430058796552694788049809205484305467611034654748067290674399763612592434637719995843862812391985470202414880076880818848087892391591369463293113276849329777201646641727587259122354784480813433328050087758855264686119576962172239308693795757165821852416204341972383989932734803429262340722338155102209101262949249742423271698842023297303260161790575673111235465890298298313115123607606773968998153812286999642014609852579793691246016346088762321286205634215901479188632194659637483482564291616278532948239313229440231043277288768139550213348266388687453259281587854503890991561949632478855035090289390973718988003999026132015872678637873095678109625311008054489418857983565902063680699643165033912029944327726770869305240718416592070096139286401966725750087012218149733133695809600369751764951350040285926249203398111014953227533621844500744331562434532484217986108346261345897591234839970751854223281677187215956827243245910829019886390369784542622566912542747056097567984857136623679023878478161201477982939080513150258174523773529510165296934562786122241150783587755373348372764439838082000667214740034466322776918936967612878983488942094688102308427036452854504966759697318836044496702853190637396916357980928865719935397723495486787180416401415281489443785036291071517805285857583987711145474240156416477194116391354935466755593592608849200546384685403028080936417250583653368093407225310820844723570226809826951426162451204040711501448747856199922814664565893938488028643822313849852328452360667045805113679663751039248163336173274547275775636810977344539275827560597425160705468689657794530521602315939865780974801515414987097778078705357058008472376892422189750312758527140173117621279898744958406199843913365680297721208751934988504499713914285158032324823021340630312586072624541637765234505522051086318285359658520708173392709566445011404055106579055037417780393351658360904543047721422281816832539613634982525215232257690920254216409657452618066051777901592902884240599998882753691957540116954696152270401280857579766154722192925655963991820948894642657512288766330302133746367449217449351637104725732980832812726468187759356584218383594702792013663907689741738962252575782663990809792647011407580367850599381887184560094695833270775126181282015391041773950918244137561999937819240362469558235924171478702779448443108751901807414110290370706052085162975798361754251041642244867577350756338018895379263183389855955956527857227926155524494739363665533904528656215464288343162282921123290451842212532888101415884061619939195042230059898349966569463580186816717074818823215848647734386780911564660755175385552224428524049468033692299989300783900020690121517740696428573930196910500988278523053797637940257968953295112436166778910585557213381789089945453947915927374958600268237844486872037243488834616856290097850532497036933361942439802882364323553808208003875741710969289725499878566253048867033095150518452126944989251596392079421452606508516052325614861938282489838000815085351564642761700832096483117944401971780149213345335903336672376719229722069970766055482452247416927774637522135201716231722137632445699154022395494158227418930589911746931773776518735850032318014432883916374243795854695691221774098948611515564046609565094538115520921863711518684562543275047870530006998423140180169421109105925493596116719457630962328831271268328501760321771680400249657674186927113215573270049935709942324416387089242427584407651215572676037924765341808984312676941110313165951429479377670698881249643421933287404390485538222160837088907598277390184204138197811025854537088586701450623578513960109987476052535450100439353062072439709976445146790993381448994644609780957731953604938734950026860564555693224229691815630293922487606470873431166384205442489628760213650246991893040112513103835085621908060270866604873585849001704200923929789193938125116798421788115209259130435572321635660895603514383883939018953166274355609970015699780289236362349895374653428746875 50 | 51 | -------------------------------------------------------------------------------- 52 | 53 | (source_file 54 | (integer)) 55 | 56 | ================================================================================ 57 | with base 2 58 | ================================================================================ 59 | 60 | 2#1010 61 | 62 | -------------------------------------------------------------------------------- 63 | 64 | (source_file 65 | (integer)) 66 | 67 | ================================================================================ 68 | with base 2 (large) 69 | ================================================================================ 70 | 71 | 2#0000_1010_1001 72 | 73 | -------------------------------------------------------------------------------- 74 | 75 | (source_file 76 | (integer)) 77 | 78 | ================================================================================ 79 | with base 16 80 | ================================================================================ 81 | 82 | 16#1f 83 | 84 | -------------------------------------------------------------------------------- 85 | 86 | (source_file 87 | (integer)) 88 | 89 | ================================================================================ 90 | with base 16 (large) 91 | ================================================================================ 92 | 93 | 16#4865_316F_774F_6C64 94 | 95 | -------------------------------------------------------------------------------- 96 | 97 | (source_file 98 | (integer)) 99 | -------------------------------------------------------------------------------- /test/corpus/term_list.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | empty 3 | ================================================================================ 4 | 5 | [] 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (expr_list)) 11 | 12 | ================================================================================ 13 | list of size 1 14 | ================================================================================ 15 | 16 | [1] 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (expr_list 22 | (integer))) 23 | 24 | ================================================================================ 25 | pair 26 | ================================================================================ 27 | 28 | [1, a] 29 | 30 | -------------------------------------------------------------------------------- 31 | 32 | (source_file 33 | (expr_list 34 | (integer) 35 | (atom))) 36 | 37 | ================================================================================ 38 | nested lists 39 | ================================================================================ 40 | 41 | [ok, [1, []]] 42 | 43 | -------------------------------------------------------------------------------- 44 | 45 | (source_file 46 | (expr_list 47 | (atom) 48 | (expr_list 49 | (integer) 50 | (expr_list)))) 51 | 52 | ================================================================================ 53 | lists consing 54 | ================================================================================ 55 | 56 | [ok | [1 | []]] 57 | 58 | -------------------------------------------------------------------------------- 59 | 60 | (source_file 61 | (expr_list 62 | (expr_list_cons 63 | (atom) 64 | (expr_list 65 | (expr_list_cons 66 | (integer) 67 | (expr_list)))))) 68 | -------------------------------------------------------------------------------- /test/corpus/term_map.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | empty 3 | ================================================================================ 4 | 5 | #{} 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (map)) 11 | 12 | ================================================================================ 13 | with one key and value 14 | ================================================================================ 15 | 16 | #{ hello => world } 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (map 22 | (map_entry 23 | (atom) 24 | (atom)))) 25 | 26 | ================================================================================ 27 | with many keys and values 28 | ================================================================================ 29 | 30 | #{ 31 | hello => joe, 32 | goodbye => moe 33 | } 34 | 35 | -------------------------------------------------------------------------------- 36 | 37 | (source_file 38 | (map 39 | (map_entry 40 | (atom) 41 | (atom)) 42 | (map_entry 43 | (atom) 44 | (atom)))) 45 | -------------------------------------------------------------------------------- /test/corpus/term_record.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | empty 3 | ================================================================================ 4 | 5 | #r{} 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (record 11 | (atom))) 12 | 13 | ================================================================================ 14 | record access 15 | ================================================================================ 16 | 17 | A#r.a 18 | 19 | -------------------------------------------------------------------------------- 20 | 21 | (source_file 22 | (expr_record_access 23 | (variable) 24 | (atom) 25 | (atom))) 26 | 27 | ================================================================================ 28 | with one key and value 29 | ================================================================================ 30 | 31 | #r{ hello = world } 32 | 33 | -------------------------------------------------------------------------------- 34 | 35 | (source_file 36 | (record 37 | (atom) 38 | (record_field 39 | (atom) 40 | (atom)))) 41 | 42 | ================================================================================ 43 | with many keys and values 44 | ================================================================================ 45 | 46 | #r{ hello = world 47 | , goodbye = moe 48 | } 49 | 50 | -------------------------------------------------------------------------------- 51 | 52 | (source_file 53 | (record 54 | (atom) 55 | (record_field 56 | (atom) 57 | (atom)) 58 | (record_field 59 | (atom) 60 | (atom)))) 61 | 62 | ================================================================================ 63 | updates 64 | ================================================================================ 65 | 66 | M#r{ 1 = V } 67 | (f())#r{ k = V } 68 | 69 | -------------------------------------------------------------------------------- 70 | 71 | (source_file 72 | (expr_record_update 73 | (variable) 74 | (record 75 | (atom) 76 | (record_field 77 | (integer) 78 | (variable)))) 79 | (expr_record_update 80 | (expr_function_call 81 | (computed_function_name 82 | (atom))) 83 | (record 84 | (atom) 85 | (record_field 86 | (atom) 87 | (variable))))) 88 | 89 | ================================================================================ 90 | nested record updates 91 | ================================================================================ 92 | 93 | N2#nrec2.nrec1#nrec1.nrec0#nrec0{name = "nested0a"} 94 | 95 | -------------------------------------------------------------------------------- 96 | 97 | (source_file 98 | (expr_record_update 99 | (expr_record_access 100 | (expr_record_access 101 | (variable) 102 | (atom) 103 | (atom)) 104 | (atom) 105 | (atom)) 106 | (record 107 | (atom) 108 | (record_field 109 | (atom) 110 | (string))))) 111 | -------------------------------------------------------------------------------- /test/corpus/term_string.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | empty 3 | ================================================================================ 4 | 5 | "" 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (string)) 11 | 12 | ================================================================================ 13 | alphabetic 14 | ================================================================================ 15 | 16 | "hellojoe" 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (string)) 22 | 23 | ================================================================================ 24 | alphanumeric 25 | ================================================================================ 26 | 27 | "hello1234" 28 | 29 | -------------------------------------------------------------------------------- 30 | 31 | (source_file 32 | (string)) 33 | 34 | ================================================================================ 35 | escapes 36 | ================================================================================ 37 | 38 | "abc\0\00\000\xAA\x{DEADBEEF}\n\r\t\v\b\f\e\s\d\ 39 | " 40 | 41 | -------------------------------------------------------------------------------- 42 | 43 | (source_file 44 | (string)) 45 | -------------------------------------------------------------------------------- /test/corpus/term_tuple.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | empty 3 | ================================================================================ 4 | 5 | {} 6 | 7 | -------------------------------------------------------------------------------- 8 | 9 | (source_file 10 | (tuple)) 11 | 12 | ================================================================================ 13 | tuple of size 1 14 | ================================================================================ 15 | 16 | {1} 17 | 18 | -------------------------------------------------------------------------------- 19 | 20 | (source_file 21 | (tuple 22 | (integer))) 23 | 24 | ================================================================================ 25 | pair 26 | ================================================================================ 27 | 28 | {1, a} 29 | 30 | -------------------------------------------------------------------------------- 31 | 32 | (source_file 33 | (tuple 34 | (integer) 35 | (atom))) 36 | 37 | ================================================================================ 38 | triplet 39 | ================================================================================ 40 | 41 | {1, a, <<"!">>} 42 | 43 | -------------------------------------------------------------------------------- 44 | 45 | (source_file 46 | (tuple 47 | (integer) 48 | (atom) 49 | (binary_string 50 | (bin_part 51 | (string))))) 52 | 53 | ================================================================================ 54 | quad 55 | ================================================================================ 56 | 57 | {1, a, <<"!">>, $j} 58 | 59 | -------------------------------------------------------------------------------- 60 | 61 | (source_file 62 | (tuple 63 | (integer) 64 | (atom) 65 | (binary_string 66 | (bin_part 67 | (string))) 68 | (char))) 69 | 70 | ================================================================================ 71 | nested tuples 72 | ================================================================================ 73 | 74 | {ok, {1, {}}} 75 | 76 | -------------------------------------------------------------------------------- 77 | 78 | (source_file 79 | (tuple 80 | (atom) 81 | (tuple 82 | (integer) 83 | (tuple)))) 84 | -------------------------------------------------------------------------------- /test/corpus/types.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | type application 3 | ================================================================================ 4 | 5 | -type alias() :: int(). 6 | 7 | -opaque opaque_alias() :: reference(). 8 | 9 | -------------------------------------------------------------------------------- 10 | 11 | (source_file 12 | (type_declaration 13 | (atom) 14 | (type_expression 15 | (type_application 16 | (atom)))) 17 | (type_declaration 18 | (atom) 19 | (type_expression 20 | (type_application 21 | (atom))))) 22 | 23 | ================================================================================ 24 | qualified type application 25 | ================================================================================ 26 | 27 | -type alias() :: erlang:int(). 28 | 29 | -------------------------------------------------------------------------------- 30 | 31 | (source_file 32 | (type_declaration 33 | (atom) 34 | (type_expression 35 | (type_application 36 | (atom) 37 | (atom))))) 38 | 39 | ================================================================================ 40 | lists 41 | ================================================================================ 42 | 43 | -type a_list() :: [alias()]. 44 | 45 | -type b_list() :: [alias(), ...]. 46 | 47 | -------------------------------------------------------------------------------- 48 | 49 | (source_file 50 | (type_declaration 51 | (atom) 52 | (type_expression 53 | (type_list 54 | (type_expression 55 | (type_application 56 | (atom)))))) 57 | (type_declaration 58 | (atom) 59 | (type_expression 60 | (type_nonempty_list 61 | (type_expression 62 | (type_application 63 | (atom))))))) 64 | 65 | ================================================================================ 66 | unions 67 | ================================================================================ 68 | -type union() :: a | b | c. 69 | 70 | -type nested_union() :: a | {b | c}. 71 | 72 | -------------------------------------------------------------------------------- 73 | 74 | (source_file 75 | (type_declaration 76 | (atom) 77 | (type_expression 78 | (type_atom 79 | (atom)) 80 | (type_atom 81 | (atom)) 82 | (type_atom 83 | (atom)))) 84 | (type_declaration 85 | (atom) 86 | (type_expression 87 | (type_atom 88 | (atom)) 89 | (type_tuple 90 | (type_expression 91 | (type_atom 92 | (atom)) 93 | (type_atom 94 | (atom))))))) 95 | 96 | ================================================================================ 97 | maps and records 98 | ================================================================================ 99 | 100 | -type empty_map() :: #{}. 101 | 102 | -type record() :: #r{}. 103 | 104 | -------------------------------------------------------------------------------- 105 | 106 | (source_file 107 | (type_declaration 108 | (atom) 109 | (type_expression 110 | (type_map))) 111 | (type_declaration 112 | (atom) 113 | (type_expression 114 | (type_record 115 | (atom))))) 116 | 117 | ================================================================================ 118 | function types 119 | ================================================================================ 120 | 121 | -spec fn() -> unit. 122 | 123 | -callback cb(a()) -> some() | type. 124 | 125 | -------------------------------------------------------------------------------- 126 | 127 | (source_file 128 | (function_spec 129 | (atom) 130 | (type_expression 131 | (type_atom 132 | (atom)))) 133 | (function_spec 134 | (atom) 135 | (type_expression 136 | (type_application 137 | (atom))) 138 | (type_expression 139 | (type_application 140 | (atom)) 141 | (type_atom 142 | (atom))))) 143 | 144 | ================================================================================ 145 | ADTs 146 | ================================================================================ 147 | 148 | -type option(A) :: {some, A} | none. 149 | 150 | -------------------------------------------------------------------------------- 151 | 152 | (source_file 153 | (type_declaration 154 | (atom) 155 | (variable) 156 | (type_expression 157 | (type_tuple 158 | (type_expression 159 | (type_atom 160 | (atom))) 161 | (type_expression 162 | (type_variable 163 | (variable)))) 164 | (type_atom 165 | (atom))))) 166 | -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | nan@^2.14.1: 6 | version "2.14.2" 7 | resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19" 8 | integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ== 9 | 10 | prettier@^2.2.1: 11 | version "2.2.1" 12 | resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5" 13 | integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== 14 | 15 | tree-sitter-cli@^0.17.1: 16 | version "0.17.3" 17 | resolved "https://registry.yarnpkg.com/tree-sitter-cli/-/tree-sitter-cli-0.17.3.tgz#ea03ee93216b0cf3187503d8a4dbff15df4dfc0a" 18 | integrity sha512-AsQhjwRwWK5wtymwVc2H5E8/Q7yzMebSj7CQyeSg50k4h7m8HHwao1i/eKlh8aGTJ3IWbGjSwBAUZTSbzcSW6Q== 19 | --------------------------------------------------------------------------------