├── .gitignore ├── COPYING.txt ├── README.md ├── grammar.js ├── package.json ├── queries └── highlights.scm ├── src ├── grammar.json ├── node-types.json ├── parser.c ├── scanner.c └── tree_sitter │ ├── alloc.h │ ├── array.h │ └── parser.h ├── test └── corpus │ ├── bool_lit.txt │ ├── buf_lit.txt │ ├── comment.txt │ ├── kwd_lit.txt │ ├── long_buf_lit.txt │ ├── long_str_lit.txt │ ├── nil_lit.txt │ ├── num_lit.txt │ ├── par_arr_lit.txt │ ├── par_tup_lit.txt │ ├── qq_lit.txt │ ├── quote_lit.txt │ ├── short_fn_lit.txt │ ├── splice_lit.txt │ ├── sqr_arr_lit.txt │ ├── sqr_tup_lit.txt │ ├── str_lit.txt │ ├── struct_lit.txt │ ├── sym_lit.txt │ ├── tbl_lit.txt │ └── unquote_lit.txt └── tree-sitter.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | *.log 4 | -------------------------------------------------------------------------------- /COPYING.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tree-sitter-janet-simple 2 | 3 | A [Janet](https://janet-lang.org) grammar for tree-sitter. 4 | 5 | ## Status 6 | 7 | Usable, but as tree-sitter is pre-1.0, don't forget the salt. 8 | 9 | ## Content 10 | 11 | This repository currently provides "source" files such as: 12 | 13 | * `grammar.js` - can be used to generate `parser.c` using the 14 | `tree-sitter` `generate` subcommand, but `node` is then required 15 | * `package.json` - without this file, the `tree-sitter` cli's 16 | capabilities will be somewhat impacted. 17 | 18 | Also, things that are provided (which are actually generated) but 19 | might disappear at some point: 20 | 21 | * `src/parser.c` and friends [1] - other projects have come to expect 22 | these to be committed to a grammar repository, but [there are forces 23 | in the world wanting to remove 24 | them](https://github.com/sogaiu/ts-questions/blob/master/questions/should-parser-source-be-committed/README.md), 25 | so depending on how things go, these may disappear. 26 | 27 | --- 28 | 29 | [1] Currently these files are generated to have ABI 14. 30 | 31 | --- 32 | 33 | ## Misc Commentary 34 | 35 | Coincidentally, it appears [another effort by 36 | GrayJack](https://github.com/GrayJack/tree-sitter-janet/) was started 37 | at about the same time. 38 | 39 | The main difference between these two is that GrayJack's grammar 40 | supports higher level constructs (e.g. `def` is recognized by the 41 | grammar) at the cost of accuracy. 42 | 43 | There might end up being different trade-offs in either approach and 44 | my belief is that there is room in the world for multiple attempts 45 | (especially for lisp-like languages). 46 | 47 | ## Credits 48 | 49 | * 314eter - handling null characters 50 | * Aerijo - Guide to your first Tree-sitter grammar 51 | * ahelwer - tree-sitter discussions 52 | * ahlinc - tree-sitter work and discussions 53 | * andrewchambers - janet-uri 54 | * bakpakin - janet 55 | * dannyfreeman - tree-sitter-clojure discussions, investigations, and 56 | work 57 | * GrayJack - tree-sitter-janet 58 | * Grazfather - `short_fn_lit` discussion 59 | * maxbrunsfeld - tree-sitter and related 60 | * NoahTheDuke - tree-sitter-clojure discussions and investigations 61 | * pyrmont - various discussions++ 62 | 63 | -------------------------------------------------------------------------------- /grammar.js: -------------------------------------------------------------------------------- 1 | function regex(patt) { 2 | return RegExp(patt); 3 | } 4 | 5 | // numbers 6 | const SIGN = 7 | choice('-', '+'); 8 | const DIGIT = 9 | regex("[0-9]"); 10 | const DEC_CHUNK = 11 | regex("[0-9][0-9_]*"); 12 | 13 | const HEX_CHUNK = 14 | regex("[a-fA-F0-9][a-fA-F0-9_]*"); 15 | 16 | const RADIX = 17 | choice('2', '3', '4', '5', '6', '7', '8', '9', '10', 18 | '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', 19 | '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', 20 | '31', '32', '33', '34', '35', '36'); 21 | const ALPHA = 22 | regex("[a-zA-Z]"); 23 | const ALPHA_NUM = 24 | regex("[a-zA-Z0-9]"); 25 | const RADIX_CHUNK = 26 | regex("[a-zA-Z0-9][a-zA-Z0-9_]*"); 27 | 28 | // symbols and keywords 29 | const SYM_CHAR_NO_DIGIT_NO_COLON = 30 | regex("[" + 31 | "a-zA-Z" + 32 | "!$%&*+\\-./<=>?@^_" + 33 | "]"); 34 | // see is_symbol_char_gen in janet's tools/symcharsgen.c 35 | const SYM_CHAR = 36 | regex("[" + 37 | "0-9:" + 38 | "a-zA-Z" + 39 | "!$%&*+\\-./<=>?@^_" + 40 | "]"); 41 | 42 | // strings 43 | const STRING_DOUBLE_QUOTE_CONTENT = 44 | repeat(choice(regex("[^" + 45 | "\\\\" + 46 | "\"" + 47 | "]"), 48 | regex("\\\\" + 49 | "(.|\\n)"))); // thanks to tree-sitter-haskell 50 | 51 | module.exports = grammar({ 52 | name: 'janet_simple', 53 | 54 | extras: $ => [ 55 | // see is_whitespace in janet's parser.c 56 | regex("\x00|" + 57 | "\x09|\x0a|\x0b|\x0c|\x0d|" + 58 | "\x20"), 59 | $.comment 60 | ], 61 | 62 | externals: $ => [ 63 | $.long_buf_lit, 64 | $.long_str_lit 65 | ], 66 | 67 | rules: { 68 | // THIS MUST BE FIRST -- even though this doesn't look like it matters 69 | source: $ => 70 | repeat($._lit), 71 | 72 | comment: $ => 73 | regex("#.*"), 74 | 75 | _lit: $ => 76 | choice($.bool_lit, 77 | $.buf_lit, 78 | $.kwd_lit, 79 | $.long_buf_lit, 80 | $.long_str_lit, 81 | $.nil_lit, 82 | $.num_lit, 83 | $.str_lit, 84 | $.sym_lit, 85 | // 86 | $.par_arr_lit, 87 | $.sqr_arr_lit, 88 | $.struct_lit, 89 | $.tbl_lit, 90 | $.par_tup_lit, 91 | $.sqr_tup_lit, 92 | // 93 | $.qq_lit, 94 | $.quote_lit, 95 | $.short_fn_lit, 96 | $.splice_lit, 97 | $.unquote_lit), 98 | 99 | // simplest things 100 | 101 | bool_lit: $ => 102 | choice('false', 103 | 'true'), 104 | 105 | kwd_lit: $ => 106 | prec(2, 107 | token(seq(':', 108 | repeat(SYM_CHAR)))), 109 | 110 | nil_lit: $ => 111 | 'nil', 112 | 113 | num_lit: $ => 114 | prec(5, 115 | choice($._radix, 116 | $._hex, 117 | $._dec)), 118 | 119 | _radix: $ => 120 | token(seq(optional(SIGN), 121 | RADIX, 122 | 'r', 123 | choice(seq(optional('.'), RADIX_CHUNK), 124 | seq(RADIX_CHUNK, '.', optional(RADIX_CHUNK))), 125 | optional(seq('&', 126 | optional(SIGN), 127 | repeat1(ALPHA_NUM))), 128 | optional(seq(':', ALPHA)))), 129 | 130 | _hex: $ => 131 | token(seq(optional(SIGN), 132 | '0x', 133 | choice(seq(optional('.'), HEX_CHUNK), 134 | seq(HEX_CHUNK, '.', optional(HEX_CHUNK))), 135 | optional(seq(choice('p', 'P'), 136 | optional(SIGN), 137 | repeat1(DIGIT))), 138 | optional(seq(':', ALPHA)))), 139 | 140 | _dec: $ => 141 | token(seq(optional(SIGN), 142 | choice(seq(optional('.'), DEC_CHUNK), 143 | seq(DEC_CHUNK, '.', optional(DEC_CHUNK))), 144 | optional(seq(choice('e', 'E'), 145 | optional(SIGN), 146 | repeat1(DIGIT))), 147 | optional(seq(':', ALPHA)))), 148 | 149 | str_lit: $ => 150 | token(seq('"', 151 | STRING_DOUBLE_QUOTE_CONTENT, 152 | '"')), 153 | 154 | buf_lit: $ => 155 | token(seq('@"', 156 | STRING_DOUBLE_QUOTE_CONTENT, 157 | '"')), 158 | 159 | sym_lit: $ => 160 | token(seq(SYM_CHAR_NO_DIGIT_NO_COLON, 161 | repeat(SYM_CHAR))), 162 | 163 | // collection-ish things 164 | 165 | par_arr_lit: $ => 166 | seq('@(', 167 | repeat($._lit), 168 | ')'), 169 | 170 | sqr_arr_lit: $ => 171 | seq('@[', 172 | repeat($._lit), 173 | ']'), 174 | 175 | struct_lit: $ => 176 | seq('{', 177 | repeat($._lit), 178 | '}'), 179 | 180 | tbl_lit: $ => 181 | seq('@{', 182 | repeat($._lit), 183 | '}'), 184 | 185 | par_tup_lit: $ => 186 | seq('(', 187 | repeat($._lit), 188 | ')'), 189 | 190 | sqr_tup_lit: $ => 191 | seq('[', 192 | repeat($._lit), 193 | ']'), 194 | 195 | // macro-related 196 | 197 | qq_lit: $ => 198 | seq('~', 199 | $._lit), 200 | 201 | quote_lit: $ => 202 | seq("'", 203 | $._lit), 204 | 205 | // following all work at the repl.. 206 | // |(= $ 1) 207 | // |[1 2] 208 | // |@[8 9] 209 | // |@(:fun :time) 210 | // |{:a 1} 211 | // |@{:pose :sit} 212 | // |'(0) 213 | // |~(:x) 214 | // |:kwd 215 | // |a-sym 216 | // |"a-str" 217 | // |@"buffer" 218 | // |``long-string`` 219 | // |@``long-buffer`` 220 | // |false 221 | // |nil 222 | // |8 223 | // ||8, |||8, etc. 224 | // |() 225 | short_fn_lit: $ => 226 | seq('|', 227 | $._lit), 228 | 229 | // XXX: ? 230 | splice_lit: $ => 231 | seq(';', 232 | $._lit), 233 | 234 | unquote_lit: $ => 235 | seq(',', 236 | $._lit), 237 | 238 | } 239 | }); 240 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tree-sitter-janet-simple", 3 | "version": "0.0.8", 4 | "description": "A Janet grammar for tree-sitter", 5 | "tree-sitter": [ 6 | { 7 | "scope": "source.janet", 8 | "file-types": [ 9 | "cgen", 10 | "janet", 11 | "jdn" 12 | ] 13 | } 14 | ] 15 | } 16 | 17 | -------------------------------------------------------------------------------- /queries/highlights.scm: -------------------------------------------------------------------------------- 1 | (num_lit) @number 2 | 3 | [ 4 | (buf_lit) 5 | (long_buf_lit) 6 | (long_str_lit) 7 | (str_lit) 8 | ] @string 9 | 10 | [ 11 | (bool_lit) 12 | (nil_lit) 13 | ] @constant.builtin 14 | 15 | (kwd_lit) @constant 16 | 17 | (comment) @comment 18 | 19 | ;; Treat quasiquotation as operators for the purpose of highlighting. 20 | 21 | [ 22 | "'" 23 | "~" 24 | "," 25 | ] @operator 26 | -------------------------------------------------------------------------------- /src/grammar.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json", 3 | "name": "janet_simple", 4 | "rules": { 5 | "source": { 6 | "type": "REPEAT", 7 | "content": { 8 | "type": "SYMBOL", 9 | "name": "_lit" 10 | } 11 | }, 12 | "comment": { 13 | "type": "PATTERN", 14 | "value": "#.*" 15 | }, 16 | "_lit": { 17 | "type": "CHOICE", 18 | "members": [ 19 | { 20 | "type": "SYMBOL", 21 | "name": "bool_lit" 22 | }, 23 | { 24 | "type": "SYMBOL", 25 | "name": "buf_lit" 26 | }, 27 | { 28 | "type": "SYMBOL", 29 | "name": "kwd_lit" 30 | }, 31 | { 32 | "type": "SYMBOL", 33 | "name": "long_buf_lit" 34 | }, 35 | { 36 | "type": "SYMBOL", 37 | "name": "long_str_lit" 38 | }, 39 | { 40 | "type": "SYMBOL", 41 | "name": "nil_lit" 42 | }, 43 | { 44 | "type": "SYMBOL", 45 | "name": "num_lit" 46 | }, 47 | { 48 | "type": "SYMBOL", 49 | "name": "str_lit" 50 | }, 51 | { 52 | "type": "SYMBOL", 53 | "name": "sym_lit" 54 | }, 55 | { 56 | "type": "SYMBOL", 57 | "name": "par_arr_lit" 58 | }, 59 | { 60 | "type": "SYMBOL", 61 | "name": "sqr_arr_lit" 62 | }, 63 | { 64 | "type": "SYMBOL", 65 | "name": "struct_lit" 66 | }, 67 | { 68 | "type": "SYMBOL", 69 | "name": "tbl_lit" 70 | }, 71 | { 72 | "type": "SYMBOL", 73 | "name": "par_tup_lit" 74 | }, 75 | { 76 | "type": "SYMBOL", 77 | "name": "sqr_tup_lit" 78 | }, 79 | { 80 | "type": "SYMBOL", 81 | "name": "qq_lit" 82 | }, 83 | { 84 | "type": "SYMBOL", 85 | "name": "quote_lit" 86 | }, 87 | { 88 | "type": "SYMBOL", 89 | "name": "short_fn_lit" 90 | }, 91 | { 92 | "type": "SYMBOL", 93 | "name": "splice_lit" 94 | }, 95 | { 96 | "type": "SYMBOL", 97 | "name": "unquote_lit" 98 | } 99 | ] 100 | }, 101 | "bool_lit": { 102 | "type": "CHOICE", 103 | "members": [ 104 | { 105 | "type": "STRING", 106 | "value": "false" 107 | }, 108 | { 109 | "type": "STRING", 110 | "value": "true" 111 | } 112 | ] 113 | }, 114 | "kwd_lit": { 115 | "type": "PREC", 116 | "value": 2, 117 | "content": { 118 | "type": "TOKEN", 119 | "content": { 120 | "type": "SEQ", 121 | "members": [ 122 | { 123 | "type": "STRING", 124 | "value": ":" 125 | }, 126 | { 127 | "type": "REPEAT", 128 | "content": { 129 | "type": "PATTERN", 130 | "value": "[0-9:a-zA-Z!$%&*+\\-./<=>?@^_]" 131 | } 132 | } 133 | ] 134 | } 135 | } 136 | }, 137 | "nil_lit": { 138 | "type": "STRING", 139 | "value": "nil" 140 | }, 141 | "num_lit": { 142 | "type": "PREC", 143 | "value": 5, 144 | "content": { 145 | "type": "CHOICE", 146 | "members": [ 147 | { 148 | "type": "SYMBOL", 149 | "name": "_radix" 150 | }, 151 | { 152 | "type": "SYMBOL", 153 | "name": "_hex" 154 | }, 155 | { 156 | "type": "SYMBOL", 157 | "name": "_dec" 158 | } 159 | ] 160 | } 161 | }, 162 | "_radix": { 163 | "type": "TOKEN", 164 | "content": { 165 | "type": "SEQ", 166 | "members": [ 167 | { 168 | "type": "CHOICE", 169 | "members": [ 170 | { 171 | "type": "CHOICE", 172 | "members": [ 173 | { 174 | "type": "STRING", 175 | "value": "-" 176 | }, 177 | { 178 | "type": "STRING", 179 | "value": "+" 180 | } 181 | ] 182 | }, 183 | { 184 | "type": "BLANK" 185 | } 186 | ] 187 | }, 188 | { 189 | "type": "CHOICE", 190 | "members": [ 191 | { 192 | "type": "STRING", 193 | "value": "2" 194 | }, 195 | { 196 | "type": "STRING", 197 | "value": "3" 198 | }, 199 | { 200 | "type": "STRING", 201 | "value": "4" 202 | }, 203 | { 204 | "type": "STRING", 205 | "value": "5" 206 | }, 207 | { 208 | "type": "STRING", 209 | "value": "6" 210 | }, 211 | { 212 | "type": "STRING", 213 | "value": "7" 214 | }, 215 | { 216 | "type": "STRING", 217 | "value": "8" 218 | }, 219 | { 220 | "type": "STRING", 221 | "value": "9" 222 | }, 223 | { 224 | "type": "STRING", 225 | "value": "10" 226 | }, 227 | { 228 | "type": "STRING", 229 | "value": "11" 230 | }, 231 | { 232 | "type": "STRING", 233 | "value": "12" 234 | }, 235 | { 236 | "type": "STRING", 237 | "value": "13" 238 | }, 239 | { 240 | "type": "STRING", 241 | "value": "14" 242 | }, 243 | { 244 | "type": "STRING", 245 | "value": "15" 246 | }, 247 | { 248 | "type": "STRING", 249 | "value": "16" 250 | }, 251 | { 252 | "type": "STRING", 253 | "value": "17" 254 | }, 255 | { 256 | "type": "STRING", 257 | "value": "18" 258 | }, 259 | { 260 | "type": "STRING", 261 | "value": "19" 262 | }, 263 | { 264 | "type": "STRING", 265 | "value": "20" 266 | }, 267 | { 268 | "type": "STRING", 269 | "value": "21" 270 | }, 271 | { 272 | "type": "STRING", 273 | "value": "22" 274 | }, 275 | { 276 | "type": "STRING", 277 | "value": "23" 278 | }, 279 | { 280 | "type": "STRING", 281 | "value": "24" 282 | }, 283 | { 284 | "type": "STRING", 285 | "value": "25" 286 | }, 287 | { 288 | "type": "STRING", 289 | "value": "26" 290 | }, 291 | { 292 | "type": "STRING", 293 | "value": "27" 294 | }, 295 | { 296 | "type": "STRING", 297 | "value": "28" 298 | }, 299 | { 300 | "type": "STRING", 301 | "value": "29" 302 | }, 303 | { 304 | "type": "STRING", 305 | "value": "30" 306 | }, 307 | { 308 | "type": "STRING", 309 | "value": "31" 310 | }, 311 | { 312 | "type": "STRING", 313 | "value": "32" 314 | }, 315 | { 316 | "type": "STRING", 317 | "value": "33" 318 | }, 319 | { 320 | "type": "STRING", 321 | "value": "34" 322 | }, 323 | { 324 | "type": "STRING", 325 | "value": "35" 326 | }, 327 | { 328 | "type": "STRING", 329 | "value": "36" 330 | } 331 | ] 332 | }, 333 | { 334 | "type": "STRING", 335 | "value": "r" 336 | }, 337 | { 338 | "type": "CHOICE", 339 | "members": [ 340 | { 341 | "type": "SEQ", 342 | "members": [ 343 | { 344 | "type": "CHOICE", 345 | "members": [ 346 | { 347 | "type": "STRING", 348 | "value": "." 349 | }, 350 | { 351 | "type": "BLANK" 352 | } 353 | ] 354 | }, 355 | { 356 | "type": "PATTERN", 357 | "value": "[a-zA-Z0-9][a-zA-Z0-9_]*" 358 | } 359 | ] 360 | }, 361 | { 362 | "type": "SEQ", 363 | "members": [ 364 | { 365 | "type": "PATTERN", 366 | "value": "[a-zA-Z0-9][a-zA-Z0-9_]*" 367 | }, 368 | { 369 | "type": "STRING", 370 | "value": "." 371 | }, 372 | { 373 | "type": "CHOICE", 374 | "members": [ 375 | { 376 | "type": "PATTERN", 377 | "value": "[a-zA-Z0-9][a-zA-Z0-9_]*" 378 | }, 379 | { 380 | "type": "BLANK" 381 | } 382 | ] 383 | } 384 | ] 385 | } 386 | ] 387 | }, 388 | { 389 | "type": "CHOICE", 390 | "members": [ 391 | { 392 | "type": "SEQ", 393 | "members": [ 394 | { 395 | "type": "STRING", 396 | "value": "&" 397 | }, 398 | { 399 | "type": "CHOICE", 400 | "members": [ 401 | { 402 | "type": "CHOICE", 403 | "members": [ 404 | { 405 | "type": "STRING", 406 | "value": "-" 407 | }, 408 | { 409 | "type": "STRING", 410 | "value": "+" 411 | } 412 | ] 413 | }, 414 | { 415 | "type": "BLANK" 416 | } 417 | ] 418 | }, 419 | { 420 | "type": "REPEAT1", 421 | "content": { 422 | "type": "PATTERN", 423 | "value": "[a-zA-Z0-9]" 424 | } 425 | } 426 | ] 427 | }, 428 | { 429 | "type": "BLANK" 430 | } 431 | ] 432 | }, 433 | { 434 | "type": "CHOICE", 435 | "members": [ 436 | { 437 | "type": "SEQ", 438 | "members": [ 439 | { 440 | "type": "STRING", 441 | "value": ":" 442 | }, 443 | { 444 | "type": "PATTERN", 445 | "value": "[a-zA-Z]" 446 | } 447 | ] 448 | }, 449 | { 450 | "type": "BLANK" 451 | } 452 | ] 453 | } 454 | ] 455 | } 456 | }, 457 | "_hex": { 458 | "type": "TOKEN", 459 | "content": { 460 | "type": "SEQ", 461 | "members": [ 462 | { 463 | "type": "CHOICE", 464 | "members": [ 465 | { 466 | "type": "CHOICE", 467 | "members": [ 468 | { 469 | "type": "STRING", 470 | "value": "-" 471 | }, 472 | { 473 | "type": "STRING", 474 | "value": "+" 475 | } 476 | ] 477 | }, 478 | { 479 | "type": "BLANK" 480 | } 481 | ] 482 | }, 483 | { 484 | "type": "STRING", 485 | "value": "0x" 486 | }, 487 | { 488 | "type": "CHOICE", 489 | "members": [ 490 | { 491 | "type": "SEQ", 492 | "members": [ 493 | { 494 | "type": "CHOICE", 495 | "members": [ 496 | { 497 | "type": "STRING", 498 | "value": "." 499 | }, 500 | { 501 | "type": "BLANK" 502 | } 503 | ] 504 | }, 505 | { 506 | "type": "PATTERN", 507 | "value": "[a-fA-F0-9][a-fA-F0-9_]*" 508 | } 509 | ] 510 | }, 511 | { 512 | "type": "SEQ", 513 | "members": [ 514 | { 515 | "type": "PATTERN", 516 | "value": "[a-fA-F0-9][a-fA-F0-9_]*" 517 | }, 518 | { 519 | "type": "STRING", 520 | "value": "." 521 | }, 522 | { 523 | "type": "CHOICE", 524 | "members": [ 525 | { 526 | "type": "PATTERN", 527 | "value": "[a-fA-F0-9][a-fA-F0-9_]*" 528 | }, 529 | { 530 | "type": "BLANK" 531 | } 532 | ] 533 | } 534 | ] 535 | } 536 | ] 537 | }, 538 | { 539 | "type": "CHOICE", 540 | "members": [ 541 | { 542 | "type": "SEQ", 543 | "members": [ 544 | { 545 | "type": "CHOICE", 546 | "members": [ 547 | { 548 | "type": "STRING", 549 | "value": "p" 550 | }, 551 | { 552 | "type": "STRING", 553 | "value": "P" 554 | } 555 | ] 556 | }, 557 | { 558 | "type": "CHOICE", 559 | "members": [ 560 | { 561 | "type": "CHOICE", 562 | "members": [ 563 | { 564 | "type": "STRING", 565 | "value": "-" 566 | }, 567 | { 568 | "type": "STRING", 569 | "value": "+" 570 | } 571 | ] 572 | }, 573 | { 574 | "type": "BLANK" 575 | } 576 | ] 577 | }, 578 | { 579 | "type": "REPEAT1", 580 | "content": { 581 | "type": "PATTERN", 582 | "value": "[0-9]" 583 | } 584 | } 585 | ] 586 | }, 587 | { 588 | "type": "BLANK" 589 | } 590 | ] 591 | }, 592 | { 593 | "type": "CHOICE", 594 | "members": [ 595 | { 596 | "type": "SEQ", 597 | "members": [ 598 | { 599 | "type": "STRING", 600 | "value": ":" 601 | }, 602 | { 603 | "type": "PATTERN", 604 | "value": "[a-zA-Z]" 605 | } 606 | ] 607 | }, 608 | { 609 | "type": "BLANK" 610 | } 611 | ] 612 | } 613 | ] 614 | } 615 | }, 616 | "_dec": { 617 | "type": "TOKEN", 618 | "content": { 619 | "type": "SEQ", 620 | "members": [ 621 | { 622 | "type": "CHOICE", 623 | "members": [ 624 | { 625 | "type": "CHOICE", 626 | "members": [ 627 | { 628 | "type": "STRING", 629 | "value": "-" 630 | }, 631 | { 632 | "type": "STRING", 633 | "value": "+" 634 | } 635 | ] 636 | }, 637 | { 638 | "type": "BLANK" 639 | } 640 | ] 641 | }, 642 | { 643 | "type": "CHOICE", 644 | "members": [ 645 | { 646 | "type": "SEQ", 647 | "members": [ 648 | { 649 | "type": "CHOICE", 650 | "members": [ 651 | { 652 | "type": "STRING", 653 | "value": "." 654 | }, 655 | { 656 | "type": "BLANK" 657 | } 658 | ] 659 | }, 660 | { 661 | "type": "PATTERN", 662 | "value": "[0-9][0-9_]*" 663 | } 664 | ] 665 | }, 666 | { 667 | "type": "SEQ", 668 | "members": [ 669 | { 670 | "type": "PATTERN", 671 | "value": "[0-9][0-9_]*" 672 | }, 673 | { 674 | "type": "STRING", 675 | "value": "." 676 | }, 677 | { 678 | "type": "CHOICE", 679 | "members": [ 680 | { 681 | "type": "PATTERN", 682 | "value": "[0-9][0-9_]*" 683 | }, 684 | { 685 | "type": "BLANK" 686 | } 687 | ] 688 | } 689 | ] 690 | } 691 | ] 692 | }, 693 | { 694 | "type": "CHOICE", 695 | "members": [ 696 | { 697 | "type": "SEQ", 698 | "members": [ 699 | { 700 | "type": "CHOICE", 701 | "members": [ 702 | { 703 | "type": "STRING", 704 | "value": "e" 705 | }, 706 | { 707 | "type": "STRING", 708 | "value": "E" 709 | } 710 | ] 711 | }, 712 | { 713 | "type": "CHOICE", 714 | "members": [ 715 | { 716 | "type": "CHOICE", 717 | "members": [ 718 | { 719 | "type": "STRING", 720 | "value": "-" 721 | }, 722 | { 723 | "type": "STRING", 724 | "value": "+" 725 | } 726 | ] 727 | }, 728 | { 729 | "type": "BLANK" 730 | } 731 | ] 732 | }, 733 | { 734 | "type": "REPEAT1", 735 | "content": { 736 | "type": "PATTERN", 737 | "value": "[0-9]" 738 | } 739 | } 740 | ] 741 | }, 742 | { 743 | "type": "BLANK" 744 | } 745 | ] 746 | }, 747 | { 748 | "type": "CHOICE", 749 | "members": [ 750 | { 751 | "type": "SEQ", 752 | "members": [ 753 | { 754 | "type": "STRING", 755 | "value": ":" 756 | }, 757 | { 758 | "type": "PATTERN", 759 | "value": "[a-zA-Z]" 760 | } 761 | ] 762 | }, 763 | { 764 | "type": "BLANK" 765 | } 766 | ] 767 | } 768 | ] 769 | } 770 | }, 771 | "str_lit": { 772 | "type": "TOKEN", 773 | "content": { 774 | "type": "SEQ", 775 | "members": [ 776 | { 777 | "type": "STRING", 778 | "value": "\"" 779 | }, 780 | { 781 | "type": "REPEAT", 782 | "content": { 783 | "type": "CHOICE", 784 | "members": [ 785 | { 786 | "type": "PATTERN", 787 | "value": "[^\\\\\"]" 788 | }, 789 | { 790 | "type": "PATTERN", 791 | "value": "\\\\(.|\\n)" 792 | } 793 | ] 794 | } 795 | }, 796 | { 797 | "type": "STRING", 798 | "value": "\"" 799 | } 800 | ] 801 | } 802 | }, 803 | "buf_lit": { 804 | "type": "TOKEN", 805 | "content": { 806 | "type": "SEQ", 807 | "members": [ 808 | { 809 | "type": "STRING", 810 | "value": "@\"" 811 | }, 812 | { 813 | "type": "REPEAT", 814 | "content": { 815 | "type": "CHOICE", 816 | "members": [ 817 | { 818 | "type": "PATTERN", 819 | "value": "[^\\\\\"]" 820 | }, 821 | { 822 | "type": "PATTERN", 823 | "value": "\\\\(.|\\n)" 824 | } 825 | ] 826 | } 827 | }, 828 | { 829 | "type": "STRING", 830 | "value": "\"" 831 | } 832 | ] 833 | } 834 | }, 835 | "sym_lit": { 836 | "type": "TOKEN", 837 | "content": { 838 | "type": "SEQ", 839 | "members": [ 840 | { 841 | "type": "PATTERN", 842 | "value": "[a-zA-Z!$%&*+\\-./<=>?@^_]" 843 | }, 844 | { 845 | "type": "REPEAT", 846 | "content": { 847 | "type": "PATTERN", 848 | "value": "[0-9:a-zA-Z!$%&*+\\-./<=>?@^_]" 849 | } 850 | } 851 | ] 852 | } 853 | }, 854 | "par_arr_lit": { 855 | "type": "SEQ", 856 | "members": [ 857 | { 858 | "type": "STRING", 859 | "value": "@(" 860 | }, 861 | { 862 | "type": "REPEAT", 863 | "content": { 864 | "type": "SYMBOL", 865 | "name": "_lit" 866 | } 867 | }, 868 | { 869 | "type": "STRING", 870 | "value": ")" 871 | } 872 | ] 873 | }, 874 | "sqr_arr_lit": { 875 | "type": "SEQ", 876 | "members": [ 877 | { 878 | "type": "STRING", 879 | "value": "@[" 880 | }, 881 | { 882 | "type": "REPEAT", 883 | "content": { 884 | "type": "SYMBOL", 885 | "name": "_lit" 886 | } 887 | }, 888 | { 889 | "type": "STRING", 890 | "value": "]" 891 | } 892 | ] 893 | }, 894 | "struct_lit": { 895 | "type": "SEQ", 896 | "members": [ 897 | { 898 | "type": "STRING", 899 | "value": "{" 900 | }, 901 | { 902 | "type": "REPEAT", 903 | "content": { 904 | "type": "SYMBOL", 905 | "name": "_lit" 906 | } 907 | }, 908 | { 909 | "type": "STRING", 910 | "value": "}" 911 | } 912 | ] 913 | }, 914 | "tbl_lit": { 915 | "type": "SEQ", 916 | "members": [ 917 | { 918 | "type": "STRING", 919 | "value": "@{" 920 | }, 921 | { 922 | "type": "REPEAT", 923 | "content": { 924 | "type": "SYMBOL", 925 | "name": "_lit" 926 | } 927 | }, 928 | { 929 | "type": "STRING", 930 | "value": "}" 931 | } 932 | ] 933 | }, 934 | "par_tup_lit": { 935 | "type": "SEQ", 936 | "members": [ 937 | { 938 | "type": "STRING", 939 | "value": "(" 940 | }, 941 | { 942 | "type": "REPEAT", 943 | "content": { 944 | "type": "SYMBOL", 945 | "name": "_lit" 946 | } 947 | }, 948 | { 949 | "type": "STRING", 950 | "value": ")" 951 | } 952 | ] 953 | }, 954 | "sqr_tup_lit": { 955 | "type": "SEQ", 956 | "members": [ 957 | { 958 | "type": "STRING", 959 | "value": "[" 960 | }, 961 | { 962 | "type": "REPEAT", 963 | "content": { 964 | "type": "SYMBOL", 965 | "name": "_lit" 966 | } 967 | }, 968 | { 969 | "type": "STRING", 970 | "value": "]" 971 | } 972 | ] 973 | }, 974 | "qq_lit": { 975 | "type": "SEQ", 976 | "members": [ 977 | { 978 | "type": "STRING", 979 | "value": "~" 980 | }, 981 | { 982 | "type": "SYMBOL", 983 | "name": "_lit" 984 | } 985 | ] 986 | }, 987 | "quote_lit": { 988 | "type": "SEQ", 989 | "members": [ 990 | { 991 | "type": "STRING", 992 | "value": "'" 993 | }, 994 | { 995 | "type": "SYMBOL", 996 | "name": "_lit" 997 | } 998 | ] 999 | }, 1000 | "short_fn_lit": { 1001 | "type": "SEQ", 1002 | "members": [ 1003 | { 1004 | "type": "STRING", 1005 | "value": "|" 1006 | }, 1007 | { 1008 | "type": "SYMBOL", 1009 | "name": "_lit" 1010 | } 1011 | ] 1012 | }, 1013 | "splice_lit": { 1014 | "type": "SEQ", 1015 | "members": [ 1016 | { 1017 | "type": "STRING", 1018 | "value": ";" 1019 | }, 1020 | { 1021 | "type": "SYMBOL", 1022 | "name": "_lit" 1023 | } 1024 | ] 1025 | }, 1026 | "unquote_lit": { 1027 | "type": "SEQ", 1028 | "members": [ 1029 | { 1030 | "type": "STRING", 1031 | "value": "," 1032 | }, 1033 | { 1034 | "type": "SYMBOL", 1035 | "name": "_lit" 1036 | } 1037 | ] 1038 | } 1039 | }, 1040 | "extras": [ 1041 | { 1042 | "type": "PATTERN", 1043 | "value": "\u0000|\t|\\n|\u000b|\f|\\r| " 1044 | }, 1045 | { 1046 | "type": "SYMBOL", 1047 | "name": "comment" 1048 | } 1049 | ], 1050 | "conflicts": [], 1051 | "precedences": [], 1052 | "externals": [ 1053 | { 1054 | "type": "SYMBOL", 1055 | "name": "long_buf_lit" 1056 | }, 1057 | { 1058 | "type": "SYMBOL", 1059 | "name": "long_str_lit" 1060 | } 1061 | ], 1062 | "inline": [], 1063 | "supertypes": [], 1064 | "reserved": {} 1065 | } -------------------------------------------------------------------------------- /src/node-types.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "bool_lit", 4 | "named": true, 5 | "fields": {} 6 | }, 7 | { 8 | "type": "kwd_lit", 9 | "named": true, 10 | "fields": {} 11 | }, 12 | { 13 | "type": "num_lit", 14 | "named": true, 15 | "fields": {} 16 | }, 17 | { 18 | "type": "par_arr_lit", 19 | "named": true, 20 | "fields": {}, 21 | "children": { 22 | "multiple": true, 23 | "required": false, 24 | "types": [ 25 | { 26 | "type": "bool_lit", 27 | "named": true 28 | }, 29 | { 30 | "type": "buf_lit", 31 | "named": true 32 | }, 33 | { 34 | "type": "kwd_lit", 35 | "named": true 36 | }, 37 | { 38 | "type": "long_buf_lit", 39 | "named": true 40 | }, 41 | { 42 | "type": "long_str_lit", 43 | "named": true 44 | }, 45 | { 46 | "type": "nil_lit", 47 | "named": true 48 | }, 49 | { 50 | "type": "num_lit", 51 | "named": true 52 | }, 53 | { 54 | "type": "par_arr_lit", 55 | "named": true 56 | }, 57 | { 58 | "type": "par_tup_lit", 59 | "named": true 60 | }, 61 | { 62 | "type": "qq_lit", 63 | "named": true 64 | }, 65 | { 66 | "type": "quote_lit", 67 | "named": true 68 | }, 69 | { 70 | "type": "short_fn_lit", 71 | "named": true 72 | }, 73 | { 74 | "type": "splice_lit", 75 | "named": true 76 | }, 77 | { 78 | "type": "sqr_arr_lit", 79 | "named": true 80 | }, 81 | { 82 | "type": "sqr_tup_lit", 83 | "named": true 84 | }, 85 | { 86 | "type": "str_lit", 87 | "named": true 88 | }, 89 | { 90 | "type": "struct_lit", 91 | "named": true 92 | }, 93 | { 94 | "type": "sym_lit", 95 | "named": true 96 | }, 97 | { 98 | "type": "tbl_lit", 99 | "named": true 100 | }, 101 | { 102 | "type": "unquote_lit", 103 | "named": true 104 | } 105 | ] 106 | } 107 | }, 108 | { 109 | "type": "par_tup_lit", 110 | "named": true, 111 | "fields": {}, 112 | "children": { 113 | "multiple": true, 114 | "required": false, 115 | "types": [ 116 | { 117 | "type": "bool_lit", 118 | "named": true 119 | }, 120 | { 121 | "type": "buf_lit", 122 | "named": true 123 | }, 124 | { 125 | "type": "kwd_lit", 126 | "named": true 127 | }, 128 | { 129 | "type": "long_buf_lit", 130 | "named": true 131 | }, 132 | { 133 | "type": "long_str_lit", 134 | "named": true 135 | }, 136 | { 137 | "type": "nil_lit", 138 | "named": true 139 | }, 140 | { 141 | "type": "num_lit", 142 | "named": true 143 | }, 144 | { 145 | "type": "par_arr_lit", 146 | "named": true 147 | }, 148 | { 149 | "type": "par_tup_lit", 150 | "named": true 151 | }, 152 | { 153 | "type": "qq_lit", 154 | "named": true 155 | }, 156 | { 157 | "type": "quote_lit", 158 | "named": true 159 | }, 160 | { 161 | "type": "short_fn_lit", 162 | "named": true 163 | }, 164 | { 165 | "type": "splice_lit", 166 | "named": true 167 | }, 168 | { 169 | "type": "sqr_arr_lit", 170 | "named": true 171 | }, 172 | { 173 | "type": "sqr_tup_lit", 174 | "named": true 175 | }, 176 | { 177 | "type": "str_lit", 178 | "named": true 179 | }, 180 | { 181 | "type": "struct_lit", 182 | "named": true 183 | }, 184 | { 185 | "type": "sym_lit", 186 | "named": true 187 | }, 188 | { 189 | "type": "tbl_lit", 190 | "named": true 191 | }, 192 | { 193 | "type": "unquote_lit", 194 | "named": true 195 | } 196 | ] 197 | } 198 | }, 199 | { 200 | "type": "qq_lit", 201 | "named": true, 202 | "fields": {}, 203 | "children": { 204 | "multiple": false, 205 | "required": true, 206 | "types": [ 207 | { 208 | "type": "bool_lit", 209 | "named": true 210 | }, 211 | { 212 | "type": "buf_lit", 213 | "named": true 214 | }, 215 | { 216 | "type": "kwd_lit", 217 | "named": true 218 | }, 219 | { 220 | "type": "long_buf_lit", 221 | "named": true 222 | }, 223 | { 224 | "type": "long_str_lit", 225 | "named": true 226 | }, 227 | { 228 | "type": "nil_lit", 229 | "named": true 230 | }, 231 | { 232 | "type": "num_lit", 233 | "named": true 234 | }, 235 | { 236 | "type": "par_arr_lit", 237 | "named": true 238 | }, 239 | { 240 | "type": "par_tup_lit", 241 | "named": true 242 | }, 243 | { 244 | "type": "qq_lit", 245 | "named": true 246 | }, 247 | { 248 | "type": "quote_lit", 249 | "named": true 250 | }, 251 | { 252 | "type": "short_fn_lit", 253 | "named": true 254 | }, 255 | { 256 | "type": "splice_lit", 257 | "named": true 258 | }, 259 | { 260 | "type": "sqr_arr_lit", 261 | "named": true 262 | }, 263 | { 264 | "type": "sqr_tup_lit", 265 | "named": true 266 | }, 267 | { 268 | "type": "str_lit", 269 | "named": true 270 | }, 271 | { 272 | "type": "struct_lit", 273 | "named": true 274 | }, 275 | { 276 | "type": "sym_lit", 277 | "named": true 278 | }, 279 | { 280 | "type": "tbl_lit", 281 | "named": true 282 | }, 283 | { 284 | "type": "unquote_lit", 285 | "named": true 286 | } 287 | ] 288 | } 289 | }, 290 | { 291 | "type": "quote_lit", 292 | "named": true, 293 | "fields": {}, 294 | "children": { 295 | "multiple": false, 296 | "required": true, 297 | "types": [ 298 | { 299 | "type": "bool_lit", 300 | "named": true 301 | }, 302 | { 303 | "type": "buf_lit", 304 | "named": true 305 | }, 306 | { 307 | "type": "kwd_lit", 308 | "named": true 309 | }, 310 | { 311 | "type": "long_buf_lit", 312 | "named": true 313 | }, 314 | { 315 | "type": "long_str_lit", 316 | "named": true 317 | }, 318 | { 319 | "type": "nil_lit", 320 | "named": true 321 | }, 322 | { 323 | "type": "num_lit", 324 | "named": true 325 | }, 326 | { 327 | "type": "par_arr_lit", 328 | "named": true 329 | }, 330 | { 331 | "type": "par_tup_lit", 332 | "named": true 333 | }, 334 | { 335 | "type": "qq_lit", 336 | "named": true 337 | }, 338 | { 339 | "type": "quote_lit", 340 | "named": true 341 | }, 342 | { 343 | "type": "short_fn_lit", 344 | "named": true 345 | }, 346 | { 347 | "type": "splice_lit", 348 | "named": true 349 | }, 350 | { 351 | "type": "sqr_arr_lit", 352 | "named": true 353 | }, 354 | { 355 | "type": "sqr_tup_lit", 356 | "named": true 357 | }, 358 | { 359 | "type": "str_lit", 360 | "named": true 361 | }, 362 | { 363 | "type": "struct_lit", 364 | "named": true 365 | }, 366 | { 367 | "type": "sym_lit", 368 | "named": true 369 | }, 370 | { 371 | "type": "tbl_lit", 372 | "named": true 373 | }, 374 | { 375 | "type": "unquote_lit", 376 | "named": true 377 | } 378 | ] 379 | } 380 | }, 381 | { 382 | "type": "short_fn_lit", 383 | "named": true, 384 | "fields": {}, 385 | "children": { 386 | "multiple": false, 387 | "required": true, 388 | "types": [ 389 | { 390 | "type": "bool_lit", 391 | "named": true 392 | }, 393 | { 394 | "type": "buf_lit", 395 | "named": true 396 | }, 397 | { 398 | "type": "kwd_lit", 399 | "named": true 400 | }, 401 | { 402 | "type": "long_buf_lit", 403 | "named": true 404 | }, 405 | { 406 | "type": "long_str_lit", 407 | "named": true 408 | }, 409 | { 410 | "type": "nil_lit", 411 | "named": true 412 | }, 413 | { 414 | "type": "num_lit", 415 | "named": true 416 | }, 417 | { 418 | "type": "par_arr_lit", 419 | "named": true 420 | }, 421 | { 422 | "type": "par_tup_lit", 423 | "named": true 424 | }, 425 | { 426 | "type": "qq_lit", 427 | "named": true 428 | }, 429 | { 430 | "type": "quote_lit", 431 | "named": true 432 | }, 433 | { 434 | "type": "short_fn_lit", 435 | "named": true 436 | }, 437 | { 438 | "type": "splice_lit", 439 | "named": true 440 | }, 441 | { 442 | "type": "sqr_arr_lit", 443 | "named": true 444 | }, 445 | { 446 | "type": "sqr_tup_lit", 447 | "named": true 448 | }, 449 | { 450 | "type": "str_lit", 451 | "named": true 452 | }, 453 | { 454 | "type": "struct_lit", 455 | "named": true 456 | }, 457 | { 458 | "type": "sym_lit", 459 | "named": true 460 | }, 461 | { 462 | "type": "tbl_lit", 463 | "named": true 464 | }, 465 | { 466 | "type": "unquote_lit", 467 | "named": true 468 | } 469 | ] 470 | } 471 | }, 472 | { 473 | "type": "source", 474 | "named": true, 475 | "root": true, 476 | "fields": {}, 477 | "children": { 478 | "multiple": true, 479 | "required": false, 480 | "types": [ 481 | { 482 | "type": "bool_lit", 483 | "named": true 484 | }, 485 | { 486 | "type": "buf_lit", 487 | "named": true 488 | }, 489 | { 490 | "type": "kwd_lit", 491 | "named": true 492 | }, 493 | { 494 | "type": "long_buf_lit", 495 | "named": true 496 | }, 497 | { 498 | "type": "long_str_lit", 499 | "named": true 500 | }, 501 | { 502 | "type": "nil_lit", 503 | "named": true 504 | }, 505 | { 506 | "type": "num_lit", 507 | "named": true 508 | }, 509 | { 510 | "type": "par_arr_lit", 511 | "named": true 512 | }, 513 | { 514 | "type": "par_tup_lit", 515 | "named": true 516 | }, 517 | { 518 | "type": "qq_lit", 519 | "named": true 520 | }, 521 | { 522 | "type": "quote_lit", 523 | "named": true 524 | }, 525 | { 526 | "type": "short_fn_lit", 527 | "named": true 528 | }, 529 | { 530 | "type": "splice_lit", 531 | "named": true 532 | }, 533 | { 534 | "type": "sqr_arr_lit", 535 | "named": true 536 | }, 537 | { 538 | "type": "sqr_tup_lit", 539 | "named": true 540 | }, 541 | { 542 | "type": "str_lit", 543 | "named": true 544 | }, 545 | { 546 | "type": "struct_lit", 547 | "named": true 548 | }, 549 | { 550 | "type": "sym_lit", 551 | "named": true 552 | }, 553 | { 554 | "type": "tbl_lit", 555 | "named": true 556 | }, 557 | { 558 | "type": "unquote_lit", 559 | "named": true 560 | } 561 | ] 562 | } 563 | }, 564 | { 565 | "type": "splice_lit", 566 | "named": true, 567 | "fields": {}, 568 | "children": { 569 | "multiple": false, 570 | "required": true, 571 | "types": [ 572 | { 573 | "type": "bool_lit", 574 | "named": true 575 | }, 576 | { 577 | "type": "buf_lit", 578 | "named": true 579 | }, 580 | { 581 | "type": "kwd_lit", 582 | "named": true 583 | }, 584 | { 585 | "type": "long_buf_lit", 586 | "named": true 587 | }, 588 | { 589 | "type": "long_str_lit", 590 | "named": true 591 | }, 592 | { 593 | "type": "nil_lit", 594 | "named": true 595 | }, 596 | { 597 | "type": "num_lit", 598 | "named": true 599 | }, 600 | { 601 | "type": "par_arr_lit", 602 | "named": true 603 | }, 604 | { 605 | "type": "par_tup_lit", 606 | "named": true 607 | }, 608 | { 609 | "type": "qq_lit", 610 | "named": true 611 | }, 612 | { 613 | "type": "quote_lit", 614 | "named": true 615 | }, 616 | { 617 | "type": "short_fn_lit", 618 | "named": true 619 | }, 620 | { 621 | "type": "splice_lit", 622 | "named": true 623 | }, 624 | { 625 | "type": "sqr_arr_lit", 626 | "named": true 627 | }, 628 | { 629 | "type": "sqr_tup_lit", 630 | "named": true 631 | }, 632 | { 633 | "type": "str_lit", 634 | "named": true 635 | }, 636 | { 637 | "type": "struct_lit", 638 | "named": true 639 | }, 640 | { 641 | "type": "sym_lit", 642 | "named": true 643 | }, 644 | { 645 | "type": "tbl_lit", 646 | "named": true 647 | }, 648 | { 649 | "type": "unquote_lit", 650 | "named": true 651 | } 652 | ] 653 | } 654 | }, 655 | { 656 | "type": "sqr_arr_lit", 657 | "named": true, 658 | "fields": {}, 659 | "children": { 660 | "multiple": true, 661 | "required": false, 662 | "types": [ 663 | { 664 | "type": "bool_lit", 665 | "named": true 666 | }, 667 | { 668 | "type": "buf_lit", 669 | "named": true 670 | }, 671 | { 672 | "type": "kwd_lit", 673 | "named": true 674 | }, 675 | { 676 | "type": "long_buf_lit", 677 | "named": true 678 | }, 679 | { 680 | "type": "long_str_lit", 681 | "named": true 682 | }, 683 | { 684 | "type": "nil_lit", 685 | "named": true 686 | }, 687 | { 688 | "type": "num_lit", 689 | "named": true 690 | }, 691 | { 692 | "type": "par_arr_lit", 693 | "named": true 694 | }, 695 | { 696 | "type": "par_tup_lit", 697 | "named": true 698 | }, 699 | { 700 | "type": "qq_lit", 701 | "named": true 702 | }, 703 | { 704 | "type": "quote_lit", 705 | "named": true 706 | }, 707 | { 708 | "type": "short_fn_lit", 709 | "named": true 710 | }, 711 | { 712 | "type": "splice_lit", 713 | "named": true 714 | }, 715 | { 716 | "type": "sqr_arr_lit", 717 | "named": true 718 | }, 719 | { 720 | "type": "sqr_tup_lit", 721 | "named": true 722 | }, 723 | { 724 | "type": "str_lit", 725 | "named": true 726 | }, 727 | { 728 | "type": "struct_lit", 729 | "named": true 730 | }, 731 | { 732 | "type": "sym_lit", 733 | "named": true 734 | }, 735 | { 736 | "type": "tbl_lit", 737 | "named": true 738 | }, 739 | { 740 | "type": "unquote_lit", 741 | "named": true 742 | } 743 | ] 744 | } 745 | }, 746 | { 747 | "type": "sqr_tup_lit", 748 | "named": true, 749 | "fields": {}, 750 | "children": { 751 | "multiple": true, 752 | "required": false, 753 | "types": [ 754 | { 755 | "type": "bool_lit", 756 | "named": true 757 | }, 758 | { 759 | "type": "buf_lit", 760 | "named": true 761 | }, 762 | { 763 | "type": "kwd_lit", 764 | "named": true 765 | }, 766 | { 767 | "type": "long_buf_lit", 768 | "named": true 769 | }, 770 | { 771 | "type": "long_str_lit", 772 | "named": true 773 | }, 774 | { 775 | "type": "nil_lit", 776 | "named": true 777 | }, 778 | { 779 | "type": "num_lit", 780 | "named": true 781 | }, 782 | { 783 | "type": "par_arr_lit", 784 | "named": true 785 | }, 786 | { 787 | "type": "par_tup_lit", 788 | "named": true 789 | }, 790 | { 791 | "type": "qq_lit", 792 | "named": true 793 | }, 794 | { 795 | "type": "quote_lit", 796 | "named": true 797 | }, 798 | { 799 | "type": "short_fn_lit", 800 | "named": true 801 | }, 802 | { 803 | "type": "splice_lit", 804 | "named": true 805 | }, 806 | { 807 | "type": "sqr_arr_lit", 808 | "named": true 809 | }, 810 | { 811 | "type": "sqr_tup_lit", 812 | "named": true 813 | }, 814 | { 815 | "type": "str_lit", 816 | "named": true 817 | }, 818 | { 819 | "type": "struct_lit", 820 | "named": true 821 | }, 822 | { 823 | "type": "sym_lit", 824 | "named": true 825 | }, 826 | { 827 | "type": "tbl_lit", 828 | "named": true 829 | }, 830 | { 831 | "type": "unquote_lit", 832 | "named": true 833 | } 834 | ] 835 | } 836 | }, 837 | { 838 | "type": "struct_lit", 839 | "named": true, 840 | "fields": {}, 841 | "children": { 842 | "multiple": true, 843 | "required": false, 844 | "types": [ 845 | { 846 | "type": "bool_lit", 847 | "named": true 848 | }, 849 | { 850 | "type": "buf_lit", 851 | "named": true 852 | }, 853 | { 854 | "type": "kwd_lit", 855 | "named": true 856 | }, 857 | { 858 | "type": "long_buf_lit", 859 | "named": true 860 | }, 861 | { 862 | "type": "long_str_lit", 863 | "named": true 864 | }, 865 | { 866 | "type": "nil_lit", 867 | "named": true 868 | }, 869 | { 870 | "type": "num_lit", 871 | "named": true 872 | }, 873 | { 874 | "type": "par_arr_lit", 875 | "named": true 876 | }, 877 | { 878 | "type": "par_tup_lit", 879 | "named": true 880 | }, 881 | { 882 | "type": "qq_lit", 883 | "named": true 884 | }, 885 | { 886 | "type": "quote_lit", 887 | "named": true 888 | }, 889 | { 890 | "type": "short_fn_lit", 891 | "named": true 892 | }, 893 | { 894 | "type": "splice_lit", 895 | "named": true 896 | }, 897 | { 898 | "type": "sqr_arr_lit", 899 | "named": true 900 | }, 901 | { 902 | "type": "sqr_tup_lit", 903 | "named": true 904 | }, 905 | { 906 | "type": "str_lit", 907 | "named": true 908 | }, 909 | { 910 | "type": "struct_lit", 911 | "named": true 912 | }, 913 | { 914 | "type": "sym_lit", 915 | "named": true 916 | }, 917 | { 918 | "type": "tbl_lit", 919 | "named": true 920 | }, 921 | { 922 | "type": "unquote_lit", 923 | "named": true 924 | } 925 | ] 926 | } 927 | }, 928 | { 929 | "type": "tbl_lit", 930 | "named": true, 931 | "fields": {}, 932 | "children": { 933 | "multiple": true, 934 | "required": false, 935 | "types": [ 936 | { 937 | "type": "bool_lit", 938 | "named": true 939 | }, 940 | { 941 | "type": "buf_lit", 942 | "named": true 943 | }, 944 | { 945 | "type": "kwd_lit", 946 | "named": true 947 | }, 948 | { 949 | "type": "long_buf_lit", 950 | "named": true 951 | }, 952 | { 953 | "type": "long_str_lit", 954 | "named": true 955 | }, 956 | { 957 | "type": "nil_lit", 958 | "named": true 959 | }, 960 | { 961 | "type": "num_lit", 962 | "named": true 963 | }, 964 | { 965 | "type": "par_arr_lit", 966 | "named": true 967 | }, 968 | { 969 | "type": "par_tup_lit", 970 | "named": true 971 | }, 972 | { 973 | "type": "qq_lit", 974 | "named": true 975 | }, 976 | { 977 | "type": "quote_lit", 978 | "named": true 979 | }, 980 | { 981 | "type": "short_fn_lit", 982 | "named": true 983 | }, 984 | { 985 | "type": "splice_lit", 986 | "named": true 987 | }, 988 | { 989 | "type": "sqr_arr_lit", 990 | "named": true 991 | }, 992 | { 993 | "type": "sqr_tup_lit", 994 | "named": true 995 | }, 996 | { 997 | "type": "str_lit", 998 | "named": true 999 | }, 1000 | { 1001 | "type": "struct_lit", 1002 | "named": true 1003 | }, 1004 | { 1005 | "type": "sym_lit", 1006 | "named": true 1007 | }, 1008 | { 1009 | "type": "tbl_lit", 1010 | "named": true 1011 | }, 1012 | { 1013 | "type": "unquote_lit", 1014 | "named": true 1015 | } 1016 | ] 1017 | } 1018 | }, 1019 | { 1020 | "type": "unquote_lit", 1021 | "named": true, 1022 | "fields": {}, 1023 | "children": { 1024 | "multiple": false, 1025 | "required": true, 1026 | "types": [ 1027 | { 1028 | "type": "bool_lit", 1029 | "named": true 1030 | }, 1031 | { 1032 | "type": "buf_lit", 1033 | "named": true 1034 | }, 1035 | { 1036 | "type": "kwd_lit", 1037 | "named": true 1038 | }, 1039 | { 1040 | "type": "long_buf_lit", 1041 | "named": true 1042 | }, 1043 | { 1044 | "type": "long_str_lit", 1045 | "named": true 1046 | }, 1047 | { 1048 | "type": "nil_lit", 1049 | "named": true 1050 | }, 1051 | { 1052 | "type": "num_lit", 1053 | "named": true 1054 | }, 1055 | { 1056 | "type": "par_arr_lit", 1057 | "named": true 1058 | }, 1059 | { 1060 | "type": "par_tup_lit", 1061 | "named": true 1062 | }, 1063 | { 1064 | "type": "qq_lit", 1065 | "named": true 1066 | }, 1067 | { 1068 | "type": "quote_lit", 1069 | "named": true 1070 | }, 1071 | { 1072 | "type": "short_fn_lit", 1073 | "named": true 1074 | }, 1075 | { 1076 | "type": "splice_lit", 1077 | "named": true 1078 | }, 1079 | { 1080 | "type": "sqr_arr_lit", 1081 | "named": true 1082 | }, 1083 | { 1084 | "type": "sqr_tup_lit", 1085 | "named": true 1086 | }, 1087 | { 1088 | "type": "str_lit", 1089 | "named": true 1090 | }, 1091 | { 1092 | "type": "struct_lit", 1093 | "named": true 1094 | }, 1095 | { 1096 | "type": "sym_lit", 1097 | "named": true 1098 | }, 1099 | { 1100 | "type": "tbl_lit", 1101 | "named": true 1102 | }, 1103 | { 1104 | "type": "unquote_lit", 1105 | "named": true 1106 | } 1107 | ] 1108 | } 1109 | }, 1110 | { 1111 | "type": "'", 1112 | "named": false 1113 | }, 1114 | { 1115 | "type": "(", 1116 | "named": false 1117 | }, 1118 | { 1119 | "type": ")", 1120 | "named": false 1121 | }, 1122 | { 1123 | "type": ",", 1124 | "named": false 1125 | }, 1126 | { 1127 | "type": ";", 1128 | "named": false 1129 | }, 1130 | { 1131 | "type": "@(", 1132 | "named": false 1133 | }, 1134 | { 1135 | "type": "@[", 1136 | "named": false 1137 | }, 1138 | { 1139 | "type": "@{", 1140 | "named": false 1141 | }, 1142 | { 1143 | "type": "[", 1144 | "named": false 1145 | }, 1146 | { 1147 | "type": "]", 1148 | "named": false 1149 | }, 1150 | { 1151 | "type": "buf_lit", 1152 | "named": true 1153 | }, 1154 | { 1155 | "type": "comment", 1156 | "named": true, 1157 | "extra": true 1158 | }, 1159 | { 1160 | "type": "false", 1161 | "named": false 1162 | }, 1163 | { 1164 | "type": "long_buf_lit", 1165 | "named": true 1166 | }, 1167 | { 1168 | "type": "long_str_lit", 1169 | "named": true 1170 | }, 1171 | { 1172 | "type": "nil_lit", 1173 | "named": true 1174 | }, 1175 | { 1176 | "type": "str_lit", 1177 | "named": true 1178 | }, 1179 | { 1180 | "type": "sym_lit", 1181 | "named": true 1182 | }, 1183 | { 1184 | "type": "true", 1185 | "named": false 1186 | }, 1187 | { 1188 | "type": "{", 1189 | "named": false 1190 | }, 1191 | { 1192 | "type": "|", 1193 | "named": false 1194 | }, 1195 | { 1196 | "type": "}", 1197 | "named": false 1198 | }, 1199 | { 1200 | "type": "~", 1201 | "named": false 1202 | } 1203 | ] -------------------------------------------------------------------------------- /src/scanner.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | enum TokenType { 5 | LONG_BUF_LIT, 6 | LONG_STR_LIT 7 | }; 8 | 9 | void* tree_sitter_janet_simple_external_scanner_create( 10 | void 11 | ) 12 | { 13 | return NULL; 14 | } 15 | 16 | void tree_sitter_janet_simple_external_scanner_destroy( 17 | void* payload 18 | ) 19 | { 20 | } 21 | 22 | void tree_sitter_janet_simple_external_scanner_reset( 23 | void* payload 24 | ) 25 | { 26 | } 27 | 28 | unsigned tree_sitter_janet_simple_external_scanner_serialize( 29 | void* payload, 30 | char* buffer 31 | ) 32 | { 33 | return 0; 34 | } 35 | 36 | void tree_sitter_janet_simple_external_scanner_deserialize( 37 | void *payload, 38 | const char *buffer, 39 | unsigned length 40 | ) 41 | { 42 | } 43 | 44 | bool tree_sitter_janet_simple_external_scanner_scan( 45 | void *payload, 46 | TSLexer *lexer, 47 | const bool *valid_symbols 48 | ) 49 | { 50 | // skip a bit brother 51 | while (iswspace(lexer->lookahead)) { 52 | lexer->advance(lexer, true); 53 | } 54 | // there can be only...two? 55 | if (valid_symbols[LONG_BUF_LIT] || valid_symbols[LONG_STR_LIT]) { 56 | // so which one was it? 57 | if (lexer->lookahead == '@') { 58 | lexer->result_symbol = LONG_BUF_LIT; 59 | lexer->advance(lexer, false); 60 | } else { 61 | lexer->result_symbol = LONG_STR_LIT; 62 | } 63 | // * long strings start with one or more backticks 64 | // * for a long buffer, the leading @ has been skipped (see above) 65 | // to arrive at the first backtick 66 | // consume the first backtick 67 | if (lexer->lookahead != '`') { 68 | return false; 69 | } 70 | // getting here means a backtick was encountered 71 | lexer->advance(lexer, false); 72 | uint32_t n_backticks = 1; 73 | // arrive at a total number of backticks 74 | for (;;) { 75 | if (lexer->eof(lexer)) { 76 | return false; 77 | } 78 | // found one! 79 | if (lexer->lookahead == '`') { 80 | n_backticks++; 81 | lexer->advance(lexer, false); 82 | continue; 83 | } else { // nope, time to bail 84 | lexer->advance(lexer, false); 85 | break; 86 | } 87 | } 88 | // getting here means the last character examined was NOT a backtick. 89 | // now keep looking until n_backticks are found 90 | uint32_t cbt = 0; // consecutive backticks 91 | for (;;) { 92 | if (lexer->eof(lexer)) { 93 | return false; 94 | } 95 | // found one! 96 | if (lexer->lookahead == '`') { 97 | cbt++; 98 | // are we there yet? 99 | if (cbt == n_backticks) { 100 | lexer->advance(lexer, false); 101 | return true; 102 | } 103 | } else { // nope, better reset the count 104 | cbt = 0; 105 | } 106 | // next! 107 | lexer->advance(lexer, false); 108 | } 109 | 110 | } 111 | 112 | return false; 113 | } 114 | -------------------------------------------------------------------------------- /src/tree_sitter/alloc.h: -------------------------------------------------------------------------------- 1 | #ifndef TREE_SITTER_ALLOC_H_ 2 | #define TREE_SITTER_ALLOC_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | // Allow clients to override allocation functions 13 | #ifdef TREE_SITTER_REUSE_ALLOCATOR 14 | 15 | extern void *(*ts_current_malloc)(size_t size); 16 | extern void *(*ts_current_calloc)(size_t count, size_t size); 17 | extern void *(*ts_current_realloc)(void *ptr, size_t size); 18 | extern void (*ts_current_free)(void *ptr); 19 | 20 | #ifndef ts_malloc 21 | #define ts_malloc ts_current_malloc 22 | #endif 23 | #ifndef ts_calloc 24 | #define ts_calloc ts_current_calloc 25 | #endif 26 | #ifndef ts_realloc 27 | #define ts_realloc ts_current_realloc 28 | #endif 29 | #ifndef ts_free 30 | #define ts_free ts_current_free 31 | #endif 32 | 33 | #else 34 | 35 | #ifndef ts_malloc 36 | #define ts_malloc malloc 37 | #endif 38 | #ifndef ts_calloc 39 | #define ts_calloc calloc 40 | #endif 41 | #ifndef ts_realloc 42 | #define ts_realloc realloc 43 | #endif 44 | #ifndef ts_free 45 | #define ts_free free 46 | #endif 47 | 48 | #endif 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif // TREE_SITTER_ALLOC_H_ 55 | -------------------------------------------------------------------------------- /src/tree_sitter/array.h: -------------------------------------------------------------------------------- 1 | #ifndef TREE_SITTER_ARRAY_H_ 2 | #define TREE_SITTER_ARRAY_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include "./alloc.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef _MSC_VER 17 | #pragma warning(push) 18 | #pragma warning(disable : 4101) 19 | #elif defined(__GNUC__) || defined(__clang__) 20 | #pragma GCC diagnostic push 21 | #pragma GCC diagnostic ignored "-Wunused-variable" 22 | #endif 23 | 24 | #define Array(T) \ 25 | struct { \ 26 | T *contents; \ 27 | uint32_t size; \ 28 | uint32_t capacity; \ 29 | } 30 | 31 | /// Initialize an array. 32 | #define array_init(self) \ 33 | ((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL) 34 | 35 | /// Create an empty array. 36 | #define array_new() \ 37 | { NULL, 0, 0 } 38 | 39 | /// Get a pointer to the element at a given `index` in the array. 40 | #define array_get(self, _index) \ 41 | (assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index]) 42 | 43 | /// Get a pointer to the first element in the array. 44 | #define array_front(self) array_get(self, 0) 45 | 46 | /// Get a pointer to the last element in the array. 47 | #define array_back(self) array_get(self, (self)->size - 1) 48 | 49 | /// Clear the array, setting its size to zero. Note that this does not free any 50 | /// memory allocated for the array's contents. 51 | #define array_clear(self) ((self)->size = 0) 52 | 53 | /// Reserve `new_capacity` elements of space in the array. If `new_capacity` is 54 | /// less than the array's current capacity, this function has no effect. 55 | #define array_reserve(self, new_capacity) \ 56 | _array__reserve((Array *)(self), array_elem_size(self), new_capacity) 57 | 58 | /// Free any memory allocated for this array. Note that this does not free any 59 | /// memory allocated for the array's contents. 60 | #define array_delete(self) _array__delete((Array *)(self)) 61 | 62 | /// Push a new `element` onto the end of the array. 63 | #define array_push(self, element) \ 64 | (_array__grow((Array *)(self), 1, array_elem_size(self)), \ 65 | (self)->contents[(self)->size++] = (element)) 66 | 67 | /// Increase the array's size by `count` elements. 68 | /// New elements are zero-initialized. 69 | #define array_grow_by(self, count) \ 70 | do { \ 71 | if ((count) == 0) break; \ 72 | _array__grow((Array *)(self), count, array_elem_size(self)); \ 73 | memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \ 74 | (self)->size += (count); \ 75 | } while (0) 76 | 77 | /// Append all elements from one array to the end of another. 78 | #define array_push_all(self, other) \ 79 | array_extend((self), (other)->size, (other)->contents) 80 | 81 | /// Append `count` elements to the end of the array, reading their values from the 82 | /// `contents` pointer. 83 | #define array_extend(self, count, contents) \ 84 | _array__splice( \ 85 | (Array *)(self), array_elem_size(self), (self)->size, \ 86 | 0, count, contents \ 87 | ) 88 | 89 | /// Remove `old_count` elements from the array starting at the given `index`. At 90 | /// the same index, insert `new_count` new elements, reading their values from the 91 | /// `new_contents` pointer. 92 | #define array_splice(self, _index, old_count, new_count, new_contents) \ 93 | _array__splice( \ 94 | (Array *)(self), array_elem_size(self), _index, \ 95 | old_count, new_count, new_contents \ 96 | ) 97 | 98 | /// Insert one `element` into the array at the given `index`. 99 | #define array_insert(self, _index, element) \ 100 | _array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element)) 101 | 102 | /// Remove one element from the array at the given `index`. 103 | #define array_erase(self, _index) \ 104 | _array__erase((Array *)(self), array_elem_size(self), _index) 105 | 106 | /// Pop the last element off the array, returning the element by value. 107 | #define array_pop(self) ((self)->contents[--(self)->size]) 108 | 109 | /// Assign the contents of one array to another, reallocating if necessary. 110 | #define array_assign(self, other) \ 111 | _array__assign((Array *)(self), (const Array *)(other), array_elem_size(self)) 112 | 113 | /// Swap one array with another 114 | #define array_swap(self, other) \ 115 | _array__swap((Array *)(self), (Array *)(other)) 116 | 117 | /// Get the size of the array contents 118 | #define array_elem_size(self) (sizeof *(self)->contents) 119 | 120 | /// Search a sorted array for a given `needle` value, using the given `compare` 121 | /// callback to determine the order. 122 | /// 123 | /// If an existing element is found to be equal to `needle`, then the `index` 124 | /// out-parameter is set to the existing value's index, and the `exists` 125 | /// out-parameter is set to true. Otherwise, `index` is set to an index where 126 | /// `needle` should be inserted in order to preserve the sorting, and `exists` 127 | /// is set to false. 128 | #define array_search_sorted_with(self, compare, needle, _index, _exists) \ 129 | _array__search_sorted(self, 0, compare, , needle, _index, _exists) 130 | 131 | /// Search a sorted array for a given `needle` value, using integer comparisons 132 | /// of a given struct field (specified with a leading dot) to determine the order. 133 | /// 134 | /// See also `array_search_sorted_with`. 135 | #define array_search_sorted_by(self, field, needle, _index, _exists) \ 136 | _array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists) 137 | 138 | /// Insert a given `value` into a sorted array, using the given `compare` 139 | /// callback to determine the order. 140 | #define array_insert_sorted_with(self, compare, value) \ 141 | do { \ 142 | unsigned _index, _exists; \ 143 | array_search_sorted_with(self, compare, &(value), &_index, &_exists); \ 144 | if (!_exists) array_insert(self, _index, value); \ 145 | } while (0) 146 | 147 | /// Insert a given `value` into a sorted array, using integer comparisons of 148 | /// a given struct field (specified with a leading dot) to determine the order. 149 | /// 150 | /// See also `array_search_sorted_by`. 151 | #define array_insert_sorted_by(self, field, value) \ 152 | do { \ 153 | unsigned _index, _exists; \ 154 | array_search_sorted_by(self, field, (value) field, &_index, &_exists); \ 155 | if (!_exists) array_insert(self, _index, value); \ 156 | } while (0) 157 | 158 | // Private 159 | 160 | typedef Array(void) Array; 161 | 162 | /// This is not what you're looking for, see `array_delete`. 163 | static inline void _array__delete(Array *self) { 164 | if (self->contents) { 165 | ts_free(self->contents); 166 | self->contents = NULL; 167 | self->size = 0; 168 | self->capacity = 0; 169 | } 170 | } 171 | 172 | /// This is not what you're looking for, see `array_erase`. 173 | static inline void _array__erase(Array *self, size_t element_size, 174 | uint32_t index) { 175 | assert(index < self->size); 176 | char *contents = (char *)self->contents; 177 | memmove(contents + index * element_size, contents + (index + 1) * element_size, 178 | (self->size - index - 1) * element_size); 179 | self->size--; 180 | } 181 | 182 | /// This is not what you're looking for, see `array_reserve`. 183 | static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) { 184 | if (new_capacity > self->capacity) { 185 | if (self->contents) { 186 | self->contents = ts_realloc(self->contents, new_capacity * element_size); 187 | } else { 188 | self->contents = ts_malloc(new_capacity * element_size); 189 | } 190 | self->capacity = new_capacity; 191 | } 192 | } 193 | 194 | /// This is not what you're looking for, see `array_assign`. 195 | static inline void _array__assign(Array *self, const Array *other, size_t element_size) { 196 | _array__reserve(self, element_size, other->size); 197 | self->size = other->size; 198 | memcpy(self->contents, other->contents, self->size * element_size); 199 | } 200 | 201 | /// This is not what you're looking for, see `array_swap`. 202 | static inline void _array__swap(Array *self, Array *other) { 203 | Array swap = *other; 204 | *other = *self; 205 | *self = swap; 206 | } 207 | 208 | /// This is not what you're looking for, see `array_push` or `array_grow_by`. 209 | static inline void _array__grow(Array *self, uint32_t count, size_t element_size) { 210 | uint32_t new_size = self->size + count; 211 | if (new_size > self->capacity) { 212 | uint32_t new_capacity = self->capacity * 2; 213 | if (new_capacity < 8) new_capacity = 8; 214 | if (new_capacity < new_size) new_capacity = new_size; 215 | _array__reserve(self, element_size, new_capacity); 216 | } 217 | } 218 | 219 | /// This is not what you're looking for, see `array_splice`. 220 | static inline void _array__splice(Array *self, size_t element_size, 221 | uint32_t index, uint32_t old_count, 222 | uint32_t new_count, const void *elements) { 223 | uint32_t new_size = self->size + new_count - old_count; 224 | uint32_t old_end = index + old_count; 225 | uint32_t new_end = index + new_count; 226 | assert(old_end <= self->size); 227 | 228 | _array__reserve(self, element_size, new_size); 229 | 230 | char *contents = (char *)self->contents; 231 | if (self->size > old_end) { 232 | memmove( 233 | contents + new_end * element_size, 234 | contents + old_end * element_size, 235 | (self->size - old_end) * element_size 236 | ); 237 | } 238 | if (new_count > 0) { 239 | if (elements) { 240 | memcpy( 241 | (contents + index * element_size), 242 | elements, 243 | new_count * element_size 244 | ); 245 | } else { 246 | memset( 247 | (contents + index * element_size), 248 | 0, 249 | new_count * element_size 250 | ); 251 | } 252 | } 253 | self->size += new_count - old_count; 254 | } 255 | 256 | /// A binary search routine, based on Rust's `std::slice::binary_search_by`. 257 | /// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`. 258 | #define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \ 259 | do { \ 260 | *(_index) = start; \ 261 | *(_exists) = false; \ 262 | uint32_t size = (self)->size - *(_index); \ 263 | if (size == 0) break; \ 264 | int comparison; \ 265 | while (size > 1) { \ 266 | uint32_t half_size = size / 2; \ 267 | uint32_t mid_index = *(_index) + half_size; \ 268 | comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \ 269 | if (comparison <= 0) *(_index) = mid_index; \ 270 | size -= half_size; \ 271 | } \ 272 | comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \ 273 | if (comparison == 0) *(_exists) = true; \ 274 | else if (comparison < 0) *(_index) += 1; \ 275 | } while (0) 276 | 277 | /// Helper macro for the `_sorted_by` routines below. This takes the left (existing) 278 | /// parameter by reference in order to work with the generic sorting function above. 279 | #define _compare_int(a, b) ((int)*(a) - (int)(b)) 280 | 281 | #ifdef _MSC_VER 282 | #pragma warning(pop) 283 | #elif defined(__GNUC__) || defined(__clang__) 284 | #pragma GCC diagnostic pop 285 | #endif 286 | 287 | #ifdef __cplusplus 288 | } 289 | #endif 290 | 291 | #endif // TREE_SITTER_ARRAY_H_ 292 | -------------------------------------------------------------------------------- /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 | #ifndef TREE_SITTER_API_H_ 17 | typedef uint16_t TSStateId; 18 | typedef uint16_t TSSymbol; 19 | typedef uint16_t TSFieldId; 20 | typedef struct TSLanguage TSLanguage; 21 | typedef struct TSLanguageMetadata TSLanguageMetadata; 22 | typedef struct TSLanguageMetadata { 23 | uint8_t major_version; 24 | uint8_t minor_version; 25 | uint8_t patch_version; 26 | } TSLanguageMetadata; 27 | #endif 28 | 29 | typedef struct { 30 | TSFieldId field_id; 31 | uint8_t child_index; 32 | bool inherited; 33 | } TSFieldMapEntry; 34 | 35 | // Used to index the field and supertype maps. 36 | typedef struct { 37 | uint16_t index; 38 | uint16_t length; 39 | } TSMapSlice; 40 | 41 | typedef struct { 42 | bool visible; 43 | bool named; 44 | bool supertype; 45 | } TSSymbolMetadata; 46 | 47 | typedef struct TSLexer TSLexer; 48 | 49 | struct TSLexer { 50 | int32_t lookahead; 51 | TSSymbol result_symbol; 52 | void (*advance)(TSLexer *, bool); 53 | void (*mark_end)(TSLexer *); 54 | uint32_t (*get_column)(TSLexer *); 55 | bool (*is_at_included_range_start)(const TSLexer *); 56 | bool (*eof)(const TSLexer *); 57 | void (*log)(const TSLexer *, const char *, ...); 58 | }; 59 | 60 | typedef enum { 61 | TSParseActionTypeShift, 62 | TSParseActionTypeReduce, 63 | TSParseActionTypeAccept, 64 | TSParseActionTypeRecover, 65 | } TSParseActionType; 66 | 67 | typedef union { 68 | struct { 69 | uint8_t type; 70 | TSStateId state; 71 | bool extra; 72 | bool repetition; 73 | } shift; 74 | struct { 75 | uint8_t type; 76 | uint8_t child_count; 77 | TSSymbol symbol; 78 | int16_t dynamic_precedence; 79 | uint16_t production_id; 80 | } reduce; 81 | uint8_t type; 82 | } TSParseAction; 83 | 84 | typedef struct { 85 | uint16_t lex_state; 86 | uint16_t external_lex_state; 87 | } TSLexMode; 88 | 89 | typedef struct { 90 | uint16_t lex_state; 91 | uint16_t external_lex_state; 92 | uint16_t reserved_word_set_id; 93 | } TSLexerMode; 94 | 95 | typedef union { 96 | TSParseAction action; 97 | struct { 98 | uint8_t count; 99 | bool reusable; 100 | } entry; 101 | } TSParseActionEntry; 102 | 103 | typedef struct { 104 | int32_t start; 105 | int32_t end; 106 | } TSCharacterRange; 107 | 108 | struct TSLanguage { 109 | uint32_t abi_version; 110 | uint32_t symbol_count; 111 | uint32_t alias_count; 112 | uint32_t token_count; 113 | uint32_t external_token_count; 114 | uint32_t state_count; 115 | uint32_t large_state_count; 116 | uint32_t production_id_count; 117 | uint32_t field_count; 118 | uint16_t max_alias_sequence_length; 119 | const uint16_t *parse_table; 120 | const uint16_t *small_parse_table; 121 | const uint32_t *small_parse_table_map; 122 | const TSParseActionEntry *parse_actions; 123 | const char * const *symbol_names; 124 | const char * const *field_names; 125 | const TSMapSlice *field_map_slices; 126 | const TSFieldMapEntry *field_map_entries; 127 | const TSSymbolMetadata *symbol_metadata; 128 | const TSSymbol *public_symbol_map; 129 | const uint16_t *alias_map; 130 | const TSSymbol *alias_sequences; 131 | const TSLexerMode *lex_modes; 132 | bool (*lex_fn)(TSLexer *, TSStateId); 133 | bool (*keyword_lex_fn)(TSLexer *, TSStateId); 134 | TSSymbol keyword_capture_token; 135 | struct { 136 | const bool *states; 137 | const TSSymbol *symbol_map; 138 | void *(*create)(void); 139 | void (*destroy)(void *); 140 | bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); 141 | unsigned (*serialize)(void *, char *); 142 | void (*deserialize)(void *, const char *, unsigned); 143 | } external_scanner; 144 | const TSStateId *primary_state_ids; 145 | const char *name; 146 | const TSSymbol *reserved_words; 147 | uint16_t max_reserved_word_set_size; 148 | uint32_t supertype_count; 149 | const TSSymbol *supertype_symbols; 150 | const TSMapSlice *supertype_map_slices; 151 | const TSSymbol *supertype_map_entries; 152 | TSLanguageMetadata metadata; 153 | }; 154 | 155 | static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { 156 | uint32_t index = 0; 157 | uint32_t size = len - index; 158 | while (size > 1) { 159 | uint32_t half_size = size / 2; 160 | uint32_t mid_index = index + half_size; 161 | const TSCharacterRange *range = &ranges[mid_index]; 162 | if (lookahead >= range->start && lookahead <= range->end) { 163 | return true; 164 | } else if (lookahead > range->end) { 165 | index = mid_index; 166 | } 167 | size -= half_size; 168 | } 169 | const TSCharacterRange *range = &ranges[index]; 170 | return (lookahead >= range->start && lookahead <= range->end); 171 | } 172 | 173 | /* 174 | * Lexer Macros 175 | */ 176 | 177 | #ifdef _MSC_VER 178 | #define UNUSED __pragma(warning(suppress : 4101)) 179 | #else 180 | #define UNUSED __attribute__((unused)) 181 | #endif 182 | 183 | #define START_LEXER() \ 184 | bool result = false; \ 185 | bool skip = false; \ 186 | UNUSED \ 187 | bool eof = false; \ 188 | int32_t lookahead; \ 189 | goto start; \ 190 | next_state: \ 191 | lexer->advance(lexer, skip); \ 192 | start: \ 193 | skip = false; \ 194 | lookahead = lexer->lookahead; 195 | 196 | #define ADVANCE(state_value) \ 197 | { \ 198 | state = state_value; \ 199 | goto next_state; \ 200 | } 201 | 202 | #define ADVANCE_MAP(...) \ 203 | { \ 204 | static const uint16_t map[] = { __VA_ARGS__ }; \ 205 | for (uint32_t i = 0; i < sizeof(map) / sizeof(map[0]); i += 2) { \ 206 | if (map[i] == lookahead) { \ 207 | state = map[i + 1]; \ 208 | goto next_state; \ 209 | } \ 210 | } \ 211 | } 212 | 213 | #define SKIP(state_value) \ 214 | { \ 215 | skip = true; \ 216 | state = state_value; \ 217 | goto next_state; \ 218 | } 219 | 220 | #define ACCEPT_TOKEN(symbol_value) \ 221 | result = true; \ 222 | lexer->result_symbol = symbol_value; \ 223 | lexer->mark_end(lexer); 224 | 225 | #define END_STATE() return result; 226 | 227 | /* 228 | * Parse Table Macros 229 | */ 230 | 231 | #define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT) 232 | 233 | #define STATE(id) id 234 | 235 | #define ACTIONS(id) id 236 | 237 | #define SHIFT(state_value) \ 238 | {{ \ 239 | .shift = { \ 240 | .type = TSParseActionTypeShift, \ 241 | .state = (state_value) \ 242 | } \ 243 | }} 244 | 245 | #define SHIFT_REPEAT(state_value) \ 246 | {{ \ 247 | .shift = { \ 248 | .type = TSParseActionTypeShift, \ 249 | .state = (state_value), \ 250 | .repetition = true \ 251 | } \ 252 | }} 253 | 254 | #define SHIFT_EXTRA() \ 255 | {{ \ 256 | .shift = { \ 257 | .type = TSParseActionTypeShift, \ 258 | .extra = true \ 259 | } \ 260 | }} 261 | 262 | #define REDUCE(symbol_name, children, precedence, prod_id) \ 263 | {{ \ 264 | .reduce = { \ 265 | .type = TSParseActionTypeReduce, \ 266 | .symbol = symbol_name, \ 267 | .child_count = children, \ 268 | .dynamic_precedence = precedence, \ 269 | .production_id = prod_id \ 270 | }, \ 271 | }} 272 | 273 | #define RECOVER() \ 274 | {{ \ 275 | .type = TSParseActionTypeRecover \ 276 | }} 277 | 278 | #define ACCEPT_INPUT() \ 279 | {{ \ 280 | .type = TSParseActionTypeAccept \ 281 | }} 282 | 283 | #ifdef __cplusplus 284 | } 285 | #endif 286 | 287 | #endif // TREE_SITTER_PARSER_H_ 288 | -------------------------------------------------------------------------------- /test/corpus/bool_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | True 3 | ======================================================================== 4 | 5 | true 6 | ------------------------------------------------------------------------ 7 | 8 | (source 9 | (bool_lit)) 10 | 11 | ======================================================================== 12 | False 13 | ======================================================================== 14 | 15 | false 16 | ------------------------------------------------------------------------ 17 | 18 | (source 19 | (bool_lit)) 20 | 21 | -------------------------------------------------------------------------------- /test/corpus/buf_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | With Escape 3 | ======================================================================== 4 | 5 | @"ant\fbee\rcougar" 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (buf_lit)) 11 | 12 | ======================================================================== 13 | With Utf8 Six Hex Digits Escape 14 | ======================================================================== 15 | 16 | @"\U01f6aa" 17 | 18 | ------------------------------------------------------------------------ 19 | 20 | (source 21 | (buf_lit)) 22 | 23 | ======================================================================== 24 | With Hex Escape 25 | ======================================================================== 26 | 27 | @"\x0f" 28 | 29 | ------------------------------------------------------------------------ 30 | 31 | (source 32 | (buf_lit)) 33 | 34 | ======================================================================== 35 | Simple 36 | ======================================================================== 37 | 38 | @"good bye" 39 | 40 | ------------------------------------------------------------------------ 41 | 42 | (source 43 | (buf_lit)) 44 | 45 | ======================================================================== 46 | With Utf8 Four Hex Digits Escape 47 | ======================================================================== 48 | 49 | @"\u89ee" 50 | 51 | ------------------------------------------------------------------------ 52 | 53 | (source 54 | (buf_lit)) 55 | 56 | ======================================================================== 57 | Multiline 58 | ======================================================================== 59 | 60 | @"this is the first line 61 | and what is this one?" 62 | 63 | ------------------------------------------------------------------------ 64 | 65 | (source 66 | (buf_lit)) 67 | 68 | -------------------------------------------------------------------------------- /test/corpus/comment.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Multiple 3 | ======================================================================== 4 | 5 | # first line 6 | # second line 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (comment) 11 | (comment)) 12 | 13 | ======================================================================== 14 | Simple 15 | ======================================================================== 16 | 17 | # a comment 18 | ------------------------------------------------------------------------ 19 | 20 | (source 21 | (comment)) 22 | 23 | -------------------------------------------------------------------------------- /test/corpus/kwd_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | With Numbers 3 | ======================================================================== 4 | 5 | :0x0x0x0 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (kwd_lit)) 11 | 12 | ======================================================================== 13 | Just A Colon 14 | ======================================================================== 15 | 16 | : 17 | 18 | ------------------------------------------------------------------------ 19 | 20 | (source 21 | (kwd_lit)) 22 | 23 | ======================================================================== 24 | Just Two Colons 25 | ======================================================================== 26 | 27 | :: 28 | 29 | ------------------------------------------------------------------------ 30 | 31 | (source 32 | (kwd_lit)) 33 | 34 | ======================================================================== 35 | Simple 36 | ======================================================================== 37 | 38 | :breathe 39 | ------------------------------------------------------------------------ 40 | 41 | (source 42 | (kwd_lit)) 43 | 44 | -------------------------------------------------------------------------------- /test/corpus/long_buf_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Simple 3 | ======================================================================== 4 | 5 | @`An ordinary 6 | long-buffer` 7 | 8 | ------------------------------------------------------------------------ 9 | 10 | (source 11 | (long_buf_lit)) 12 | 13 | ======================================================================== 14 | More Than One Backtick Per Delim 15 | ======================================================================== 16 | 17 | @````Look, 18 | more than three 19 | backticks can be 20 | used... 21 | kinda poetic... 22 | but not really 23 | ```` 24 | 25 | ------------------------------------------------------------------------ 26 | 27 | (source 28 | (long_buf_lit)) 29 | 30 | -------------------------------------------------------------------------------- /test/corpus/long_str_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Simple 3 | ======================================================================== 4 | 5 | `A nice 6 | long-string` 7 | 8 | ------------------------------------------------------------------------ 9 | 10 | (source 11 | (long_str_lit)) 12 | 13 | ======================================================================== 14 | More Than One Backtick Per Delim 15 | ======================================================================== 16 | 17 | ```More than 18 | one backtick 19 | can be used 20 | ``` 21 | 22 | ------------------------------------------------------------------------ 23 | 24 | (source 25 | (long_str_lit)) 26 | 27 | -------------------------------------------------------------------------------- /test/corpus/nil_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | The Only 3 | ======================================================================== 4 | 5 | nil 6 | ------------------------------------------------------------------------ 7 | 8 | (source 9 | (nil_lit)) 10 | 11 | -------------------------------------------------------------------------------- /test/corpus/num_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Hex With Underscores 3 | ======================================================================== 4 | 5 | 0xF_F__F___F____ 6 | ------------------------------------------------------------------------ 7 | 8 | (source 9 | (num_lit)) 10 | 11 | ======================================================================== 12 | Radix With Exponent 13 | ======================================================================== 14 | 15 | 3r01&02 16 | ------------------------------------------------------------------------ 17 | 18 | (source 19 | (num_lit)) 20 | 21 | ======================================================================== 22 | Radix With Alphabetical Exponent 23 | ======================================================================== 24 | 25 | 11r1&a 26 | ------------------------------------------------------------------------ 27 | 28 | (source 29 | (num_lit)) 30 | 31 | ======================================================================== 32 | Radix 33 | ======================================================================== 34 | 35 | 2r0101010001 36 | ------------------------------------------------------------------------ 37 | 38 | (source 39 | (num_lit)) 40 | 41 | ======================================================================== 42 | Hex With Fractional Part 43 | ======================================================================== 44 | 45 | 0x09.1F 46 | ------------------------------------------------------------------------ 47 | 48 | (source 49 | (num_lit)) 50 | 51 | ======================================================================== 52 | Double 53 | ======================================================================== 54 | 55 | 1.0 56 | ------------------------------------------------------------------------ 57 | 58 | (source 59 | (num_lit)) 60 | 61 | ======================================================================== 62 | Integer Ending With Underscores 63 | ======================================================================== 64 | 65 | 1_3__0890__100__ 66 | ------------------------------------------------------------------------ 67 | 68 | (source 69 | (num_lit)) 70 | 71 | ======================================================================== 72 | Negative Integer 73 | ======================================================================== 74 | 75 | -2 76 | ------------------------------------------------------------------------ 77 | 78 | (source 79 | (num_lit)) 80 | 81 | ======================================================================== 82 | Double With Negative Exponent 83 | ======================================================================== 84 | 85 | 2e-1 86 | ------------------------------------------------------------------------ 87 | 88 | (source 89 | (num_lit)) 90 | 91 | ======================================================================== 92 | Hex With Fractional Part And Underscores 93 | ======================================================================== 94 | 95 | 0x0_9_.1_f__ 96 | ------------------------------------------------------------------------ 97 | 98 | (source 99 | (num_lit)) 100 | 101 | ======================================================================== 102 | Negative Hex 103 | ======================================================================== 104 | 105 | -0xFF 106 | ------------------------------------------------------------------------ 107 | 108 | (source 109 | (num_lit)) 110 | 111 | ======================================================================== 112 | Negative Radix 113 | ======================================================================== 114 | 115 | -36r20 116 | ------------------------------------------------------------------------ 117 | 118 | (source 119 | (num_lit)) 120 | 121 | ======================================================================== 122 | Shouting Double With Exponent 123 | ======================================================================== 124 | 125 | 1E9 126 | ------------------------------------------------------------------------ 127 | 128 | (source 129 | (num_lit)) 130 | 131 | ======================================================================== 132 | Negative Double 133 | ======================================================================== 134 | 135 | -2.71828 136 | ------------------------------------------------------------------------ 137 | 138 | (source 139 | (num_lit)) 140 | 141 | ======================================================================== 142 | Hex 143 | ======================================================================== 144 | 145 | 0xaB 146 | ------------------------------------------------------------------------ 147 | 148 | (source 149 | (num_lit)) 150 | 151 | ======================================================================== 152 | Integer With Sequential Underscores 153 | ======================================================================== 154 | 155 | 3__0890__100 156 | ------------------------------------------------------------------------ 157 | 158 | (source 159 | (num_lit)) 160 | 161 | ======================================================================== 162 | Double With Exponent 163 | ======================================================================== 164 | 165 | 3e8 166 | ------------------------------------------------------------------------ 167 | 168 | (source 169 | (num_lit)) 170 | 171 | ======================================================================== 172 | Integer With Underscores 173 | ======================================================================== 174 | 175 | 1_000_000 176 | ------------------------------------------------------------------------ 177 | 178 | (source 179 | (num_lit)) 180 | 181 | ======================================================================== 182 | Integer 183 | ======================================================================== 184 | 185 | 1 186 | ------------------------------------------------------------------------ 187 | 188 | (source 189 | (num_lit)) 190 | 191 | ======================================================================== 192 | Signed and Unsigned 64 Bit Integers 193 | ======================================================================== 194 | 195 | -1:s 196 | -0xff:s 197 | 123:u 198 | 2r01:u 199 | ------------------------------------------------------------------------ 200 | 201 | (source 202 | (num_lit) 203 | (num_lit) 204 | (num_lit) 205 | (num_lit)) 206 | 207 | ======================================================================== 208 | Normals / IEEE 754 Doubles 209 | ======================================================================== 210 | 211 | 3.1415926535:n 212 | 1.3e2:n 213 | 3r01&02:n 214 | ------------------------------------------------------------------------ 215 | 216 | (source 217 | (num_lit) 218 | (num_lit) 219 | (num_lit)) 220 | 221 | ======================================================================== 222 | Hexadecimal Exponential Notation 223 | ======================================================================== 224 | 225 | 0x1.3DEp42 226 | 0x1p2 227 | 0x1p+1 228 | 0x2p-1 229 | -0x1_1.0p1 230 | 0x1_1.0_0P11 231 | +0x1.0000000000000p+0000 232 | +0x0.0000000000000p+0000 233 | -0x0.0000000000000p+0000 234 | +0x1.5555555555555p-0002 235 | -0x1.2492492492492p-0001 236 | +0x1.999999999999ap-0004 237 | +0x1.9e3779b97f4a8p+0000 238 | +0x1.6a09e667f3bcdp-0001 239 | +0x1.921fb54442d18p+0001 240 | +0x1.5bf0a8b145769p+0001 241 | +0x1.62e42fefa39efp-0001 242 | +0x1.71547652b82fep+0000 243 | +0x1.0000000000000p-0052 244 | +0x1.0000000000000p-1074 245 | +0x1.fffffffffffffp+1023 246 | -0x1.fffffffffffffp+0052 247 | +0x1.fffffffffffffp+0052 248 | ------------------------------------------------------------------------ 249 | 250 | (source 251 | (num_lit) 252 | (num_lit) 253 | (num_lit) 254 | (num_lit) 255 | (num_lit) 256 | (num_lit) 257 | (num_lit) 258 | (num_lit) 259 | (num_lit) 260 | (num_lit) 261 | (num_lit) 262 | (num_lit) 263 | (num_lit) 264 | (num_lit) 265 | (num_lit) 266 | (num_lit) 267 | (num_lit) 268 | (num_lit) 269 | (num_lit) 270 | (num_lit) 271 | (num_lit) 272 | (num_lit) 273 | (num_lit)) 274 | 275 | -------------------------------------------------------------------------------- /test/corpus/par_arr_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Empty 3 | ======================================================================== 4 | 5 | @() 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (par_arr_lit)) 11 | 12 | ======================================================================== 13 | Simple 14 | ======================================================================== 15 | 16 | @(:hello :there :friend) 17 | 18 | ------------------------------------------------------------------------ 19 | 20 | (source 21 | (par_arr_lit 22 | (kwd_lit) 23 | (kwd_lit) 24 | (kwd_lit))) 25 | 26 | ======================================================================== 27 | Recursive 28 | ======================================================================== 29 | 30 | @(@(3 0 3) 8 @(3 0 3)) 31 | 32 | ------------------------------------------------------------------------ 33 | 34 | (source 35 | (par_arr_lit 36 | (par_arr_lit 37 | (num_lit) 38 | (num_lit) 39 | (num_lit)) 40 | (num_lit) 41 | (par_arr_lit 42 | (num_lit) 43 | (num_lit) 44 | (num_lit)))) 45 | 46 | -------------------------------------------------------------------------------- /test/corpus/par_tup_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Simple 3 | ======================================================================== 4 | 5 | (+ 1 2 3) 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (par_tup_lit 11 | (sym_lit) 12 | (num_lit) 13 | (num_lit) 14 | (num_lit))) 15 | 16 | ======================================================================== 17 | Empty 18 | ======================================================================== 19 | 20 | () 21 | 22 | ------------------------------------------------------------------------ 23 | 24 | (source 25 | (par_tup_lit)) 26 | 27 | ======================================================================== 28 | Recurisve 29 | ======================================================================== 30 | 31 | (+ 1 2 (- 9 8)) 32 | 33 | ------------------------------------------------------------------------ 34 | 35 | (source 36 | (par_tup_lit 37 | (sym_lit) 38 | (num_lit) 39 | (num_lit) 40 | (par_tup_lit 41 | (sym_lit) 42 | (num_lit) 43 | (num_lit)))) 44 | 45 | -------------------------------------------------------------------------------- /test/corpus/qq_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Paren Tuple 3 | ======================================================================== 4 | 5 | ~(1 2 3) 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (qq_lit 11 | (par_tup_lit 12 | (num_lit) 13 | (num_lit) 14 | (num_lit)))) 15 | 16 | ======================================================================== 17 | Simple 18 | ======================================================================== 19 | 20 | ~1 21 | 22 | ------------------------------------------------------------------------ 23 | 24 | (source 25 | (qq_lit 26 | (num_lit))) 27 | 28 | -------------------------------------------------------------------------------- /test/corpus/quote_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Tuple 3 | ======================================================================== 4 | 5 | '(:a :b :c) 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (quote_lit 11 | (par_tup_lit 12 | (kwd_lit) 13 | (kwd_lit) 14 | (kwd_lit)))) 15 | 16 | ======================================================================== 17 | Simple 18 | ======================================================================== 19 | 20 | ':hobbes 21 | 22 | ------------------------------------------------------------------------ 23 | 24 | (source 25 | (quote_lit 26 | (kwd_lit))) 27 | 28 | -------------------------------------------------------------------------------- /test/corpus/short_fn_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Struct 3 | ======================================================================== 4 | 5 | |{:a 1} 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (short_fn_lit 11 | (struct_lit 12 | (kwd_lit) 13 | (num_lit)))) 14 | 15 | ======================================================================== 16 | String 17 | ======================================================================== 18 | 19 | |"nice string" 20 | 21 | ------------------------------------------------------------------------ 22 | 23 | (source 24 | (short_fn_lit 25 | (str_lit))) 26 | 27 | ======================================================================== 28 | Call 29 | ======================================================================== 30 | 31 | |(= $ 1) 32 | 33 | ------------------------------------------------------------------------ 34 | 35 | (source 36 | (short_fn_lit 37 | (par_tup_lit 38 | (sym_lit) 39 | (sym_lit) 40 | (num_lit)))) 41 | 42 | ======================================================================== 43 | Square Bracket Array 44 | ======================================================================== 45 | 46 | |@[8 9] 47 | 48 | ------------------------------------------------------------------------ 49 | 50 | (source 51 | (short_fn_lit 52 | (sqr_arr_lit 53 | (num_lit) 54 | (num_lit)))) 55 | 56 | ======================================================================== 57 | Symbol 58 | ======================================================================== 59 | 60 | |a-sym 61 | 62 | ------------------------------------------------------------------------ 63 | 64 | (source 65 | (short_fn_lit 66 | (sym_lit))) 67 | 68 | ======================================================================== 69 | Square Bracket Tuple 70 | ======================================================================== 71 | 72 | |[1 2] 73 | 74 | ------------------------------------------------------------------------ 75 | 76 | (source 77 | (short_fn_lit 78 | (sqr_tup_lit 79 | (num_lit) 80 | (num_lit)))) 81 | 82 | ======================================================================== 83 | Keyword 84 | ======================================================================== 85 | 86 | |:a-fine-keyword 87 | 88 | ------------------------------------------------------------------------ 89 | 90 | (source 91 | (short_fn_lit 92 | (kwd_lit))) 93 | 94 | ======================================================================== 95 | Number 96 | ======================================================================== 97 | 98 | |8 99 | 100 | ------------------------------------------------------------------------ 101 | 102 | (source 103 | (short_fn_lit 104 | (num_lit))) 105 | 106 | -------------------------------------------------------------------------------- /test/corpus/splice_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | In Call 3 | ======================================================================== 4 | 5 | (+ ;[1 2 3]) 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (par_tup_lit 11 | (sym_lit) 12 | (splice_lit 13 | (sqr_tup_lit 14 | (num_lit) 15 | (num_lit) 16 | (num_lit))))) 17 | 18 | -------------------------------------------------------------------------------- /test/corpus/sqr_arr_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Recursive 3 | ======================================================================== 4 | 5 | @[1 @[2 @[3 8]] @[9 0]] 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (sqr_arr_lit 11 | (num_lit) 12 | (sqr_arr_lit 13 | (num_lit) 14 | (sqr_arr_lit 15 | (num_lit) 16 | (num_lit))) 17 | (sqr_arr_lit 18 | (num_lit) 19 | (num_lit)))) 20 | 21 | ======================================================================== 22 | Empty 23 | ======================================================================== 24 | 25 | @[] 26 | 27 | ------------------------------------------------------------------------ 28 | 29 | (source 30 | (sqr_arr_lit)) 31 | 32 | ======================================================================== 33 | Simple 34 | ======================================================================== 35 | 36 | @[2 7 1 8 2 8] 37 | 38 | ------------------------------------------------------------------------ 39 | 40 | (source 41 | (sqr_arr_lit 42 | (num_lit) 43 | (num_lit) 44 | (num_lit) 45 | (num_lit) 46 | (num_lit) 47 | (num_lit))) 48 | 49 | -------------------------------------------------------------------------------- /test/corpus/sqr_tup_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Empty 3 | ======================================================================== 4 | 5 | [] 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (sqr_tup_lit)) 11 | 12 | ======================================================================== 13 | Recursive 14 | ======================================================================== 15 | 16 | [:html [:body [:p "surely you must be joking"]]] 17 | 18 | ------------------------------------------------------------------------ 19 | 20 | (source 21 | (sqr_tup_lit 22 | (kwd_lit) 23 | (sqr_tup_lit 24 | (kwd_lit) 25 | (sqr_tup_lit 26 | (kwd_lit) 27 | (str_lit))))) 28 | 29 | ======================================================================== 30 | Simple 31 | ======================================================================== 32 | 33 | [:alice :bob :carol] 34 | 35 | ------------------------------------------------------------------------ 36 | 37 | (source 38 | (sqr_tup_lit 39 | (kwd_lit) 40 | (kwd_lit) 41 | (kwd_lit))) 42 | 43 | -------------------------------------------------------------------------------- /test/corpus/str_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | With Escapes 3 | ======================================================================== 4 | 5 | "first line\nsecond\tline" 6 | ------------------------------------------------------------------------ 7 | 8 | (source 9 | (str_lit)) 10 | 11 | ======================================================================== 12 | Multiline 13 | ======================================================================== 14 | 15 | "this is the first line 16 | and what is this one?" 17 | ------------------------------------------------------------------------ 18 | 19 | (source 20 | (str_lit)) 21 | 22 | ======================================================================== 23 | With Hex Escape 24 | ======================================================================== 25 | 26 | "\xAB" 27 | 28 | ------------------------------------------------------------------------ 29 | 30 | (source 31 | (str_lit)) 32 | 33 | ======================================================================== 34 | With Utf8 Four Hex Digits Escape 35 | ======================================================================== 36 | 37 | "\u23f1" 38 | 39 | ------------------------------------------------------------------------ 40 | 41 | (source 42 | (str_lit)) 43 | 44 | ======================================================================== 45 | Simple 46 | ======================================================================== 47 | 48 | "hello there" 49 | ------------------------------------------------------------------------ 50 | 51 | (source 52 | (str_lit)) 53 | 54 | ======================================================================== 55 | With Utf8 Six Hex Digits Escape 56 | ======================================================================== 57 | 58 | "\U01F609" 59 | 60 | ------------------------------------------------------------------------ 61 | 62 | (source 63 | (str_lit)) 64 | 65 | -------------------------------------------------------------------------------- /test/corpus/struct_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Recursive 3 | ======================================================================== 4 | 5 | {:alice {:likes :bob} :bob {:likes :carol} :carol {:likes :alice}} 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (struct_lit 11 | (kwd_lit) 12 | (struct_lit 13 | (kwd_lit) 14 | (kwd_lit)) 15 | (kwd_lit) 16 | (struct_lit 17 | (kwd_lit) 18 | (kwd_lit)) 19 | (kwd_lit) 20 | (struct_lit 21 | (kwd_lit) 22 | (kwd_lit)))) 23 | 24 | ======================================================================== 25 | Empty 26 | ======================================================================== 27 | 28 | {} 29 | 30 | ------------------------------------------------------------------------ 31 | 32 | (source 33 | (struct_lit)) 34 | 35 | ======================================================================== 36 | Simple 37 | ======================================================================== 38 | 39 | {:a 1 :b 2} 40 | 41 | ------------------------------------------------------------------------ 42 | 43 | (source 44 | (struct_lit 45 | (kwd_lit) 46 | (num_lit) 47 | (kwd_lit) 48 | (num_lit))) 49 | 50 | -------------------------------------------------------------------------------- /test/corpus/sym_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Kebab Case 3 | ======================================================================== 4 | 5 | kebab-case-symbol 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (sym_lit)) 11 | 12 | ======================================================================== 13 | Name With Module Name 14 | ======================================================================== 15 | 16 | my-module/my-function 17 | 18 | ------------------------------------------------------------------------ 19 | 20 | (source 21 | (sym_lit)) 22 | 23 | ======================================================================== 24 | Ear Muffs 25 | ======================================================================== 26 | 27 | *global-var* 28 | 29 | ------------------------------------------------------------------------ 30 | 31 | (source 32 | (sym_lit)) 33 | 34 | ======================================================================== 35 | Snake Case 36 | ======================================================================== 37 | 38 | snake_case_symbol 39 | 40 | ------------------------------------------------------------------------ 41 | 42 | (source 43 | (sym_lit)) 44 | 45 | ======================================================================== 46 | Full Of Stars 47 | ======================================================================== 48 | 49 | ***** 50 | 51 | ------------------------------------------------------------------------ 52 | 53 | (source 54 | (sym_lit)) 55 | 56 | ======================================================================== 57 | Alphabetic 58 | ======================================================================== 59 | 60 | var 61 | ------------------------------------------------------------------------ 62 | 63 | (source 64 | (sym_lit)) 65 | 66 | ======================================================================== 67 | Legal But Hard To Read 68 | ======================================================================== 69 | 70 | !%$^*__--__._+++===-crazy-symbol 71 | 72 | ------------------------------------------------------------------------ 73 | 74 | (source 75 | (sym_lit)) 76 | 77 | -------------------------------------------------------------------------------- /test/corpus/tbl_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | Empty 3 | ======================================================================== 4 | 5 | @{} 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (tbl_lit)) 11 | 12 | ======================================================================== 13 | Recursive 14 | ======================================================================== 15 | 16 | @{:ant @{:legs 6} :bee @{:legs 6} :cheetah @{:legs 4}} 17 | 18 | ------------------------------------------------------------------------ 19 | 20 | (source 21 | (tbl_lit 22 | (kwd_lit) 23 | (tbl_lit 24 | (kwd_lit) 25 | (num_lit)) 26 | (kwd_lit) 27 | (tbl_lit 28 | (kwd_lit) 29 | (num_lit)) 30 | (kwd_lit) 31 | (tbl_lit 32 | (kwd_lit) 33 | (num_lit)))) 34 | 35 | ======================================================================== 36 | Simple 37 | ======================================================================== 38 | 39 | @{:x 0 :y 100 :z -80} 40 | 41 | ------------------------------------------------------------------------ 42 | 43 | (source 44 | (tbl_lit 45 | (kwd_lit) 46 | (num_lit) 47 | (kwd_lit) 48 | (num_lit) 49 | (kwd_lit) 50 | (num_lit))) 51 | 52 | -------------------------------------------------------------------------------- /test/corpus/unquote_lit.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | In Compile Call 3 | ======================================================================== 4 | 5 | ((compile (let [a 1] ~(+ ,a 1)))) 6 | 7 | ------------------------------------------------------------------------ 8 | 9 | (source 10 | (par_tup_lit 11 | (par_tup_lit 12 | (sym_lit) 13 | (par_tup_lit 14 | (sym_lit) 15 | (sqr_tup_lit 16 | (sym_lit) 17 | (num_lit)) 18 | (qq_lit 19 | (par_tup_lit 20 | (sym_lit) 21 | (unquote_lit 22 | (sym_lit)) 23 | (num_lit))))))) 24 | 25 | ======================================================================== 26 | In Quasiquote 27 | ======================================================================== 28 | 29 | ~(+ ,a 1) 30 | 31 | ------------------------------------------------------------------------ 32 | 33 | (source 34 | (qq_lit 35 | (par_tup_lit 36 | (sym_lit) 37 | (unquote_lit 38 | (sym_lit)) 39 | (num_lit)))) 40 | 41 | -------------------------------------------------------------------------------- /tree-sitter.json: -------------------------------------------------------------------------------- 1 | { 2 | "grammars": [ 3 | { 4 | "name": "janet-simple", 5 | "camelcase": "JanetSimple", 6 | "scope": "source.janet", 7 | "path": ".", 8 | "file-types": [ 9 | "cgen", 10 | "janet", 11 | "jdn" 12 | ] 13 | } 14 | ], 15 | "metadata": { 16 | "version": "0.0.8", 17 | "description": "A Janet grammar for tree-sitter" 18 | } 19 | } 20 | --------------------------------------------------------------------------------