0sec-cli 0.21.4 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/0.js +56 -56
- package/README.md +48 -63
- package/chunks/{adapt-loop-IGBRQAXO.js → adapt-loop-J6QCZZTB.js} +4 -4
- package/chunks/{artifact-scraper-LNQJUORS.js → artifact-scraper-MFKT6OI4.js} +2 -2
- package/chunks/{assumption-mining-4MJTP6H5.js → assumption-mining-646LYSJY.js} +16 -16
- package/chunks/{chunk-Z3IKZX3X.js → chunk-23DG5YKS.js} +1 -1
- package/chunks/{chunk-2WSXFFJZ.js → chunk-3E2KALZ5.js} +2 -2
- package/chunks/{chunk-TF46UWFU.js → chunk-4G7OVYJX.js} +1 -1
- package/chunks/{chunk-E2UOY5PJ.js → chunk-5BTJMINS.js} +12 -70
- package/chunks/{chunk-QZVG3BG4.js → chunk-5IBCBQEH.js} +1 -2
- package/chunks/{chunk-YA4PUM4H.js → chunk-7XCKYNLO.js} +1 -1
- package/chunks/{chunk-BACXRTQ4.js → chunk-AV2LG2L7.js} +87 -767
- package/chunks/{chunk-IMGWPNQM.js → chunk-BCSRRQG5.js} +76 -593
- package/chunks/{chunk-NOPBXZUV.js → chunk-BOUGKEKA.js} +1 -1
- package/chunks/{chunk-RF5QGKLR.js → chunk-CPWA6RWE.js} +3 -3
- package/chunks/{chunk-P6YG6TEZ.js → chunk-DKSCN2AB.js} +1 -1
- package/chunks/{chunk-YPOA3W4O.js → chunk-GOEA3NW6.js} +877 -110
- package/chunks/{chunk-ANDKY54G.js → chunk-HHPWRY2M.js} +4019 -7299
- package/chunks/{chunk-NDJU5ZZ7.js → chunk-IFME676H.js} +3 -3
- package/chunks/{chunk-HBKCGJAV.js → chunk-IVQV574Y.js} +1 -1
- package/chunks/{chunk-W4JOXE4N.js → chunk-IXT64DV5.js} +709 -1929
- package/chunks/{chunk-PC6RCKQV.js → chunk-KAU6NLGP.js} +59 -26
- package/chunks/{chunk-FAH6V4QM.js → chunk-LGCASF2C.js} +1117 -2291
- package/chunks/{chunk-CAJJRUTV.js → chunk-NLH4LMWH.js} +1 -1
- package/chunks/chunk-OHHCGDJ2.js +5523 -0
- package/chunks/{chunk-YHWWF4QY.js → chunk-OSBPGWTE.js} +3 -3
- package/chunks/{chunk-G34QP2XW.js → chunk-TM74SSHC.js} +1 -1
- package/chunks/{chunk-VOAXLO4A.js → chunk-TO35Y326.js} +5 -721
- package/chunks/{chunk-FWAYJ2IV.js → chunk-TV27OWIW.js} +8 -8
- package/chunks/chunk-UELXHK2Y.js +1950 -0
- package/chunks/{chunk-CL5KAUM6.js → chunk-V6GHX34G.js} +274 -8
- package/chunks/{chunk-WZISK5VC.js → chunk-VWITLWXB.js} +53 -7
- package/chunks/{chunk-ER3SUMYJ.js → chunk-W6UWZFKL.js} +0 -195
- package/chunks/chunk-WSDDGFA6.js +114 -0
- package/chunks/{chunk-5T6D5BVY.js → chunk-WZRVS7SB.js} +1 -1
- package/chunks/chunk-X7LAEEUW.js +2143 -0
- package/chunks/chunk-XA2O4WXA.js +1228 -0
- package/chunks/{chunk-Y5H6E24H.js → chunk-XCISCI4T.js} +1 -1
- package/chunks/{chunk-WPQLBN4S.js → chunk-XDKB2P5X.js} +1 -1
- package/chunks/{chunk-SBMB4OL3.js → chunk-YL6YAGLL.js} +62 -8
- package/chunks/{chunk-O6SD4A36.js → chunk-ZKQ2I3S2.js} +1 -1
- package/chunks/{codex-models-TYYV4JNN.js → codex-models-NHQW45SO.js} +5 -3
- package/chunks/{commands-WF5RG4I2.js → commands-N6GN5SBF.js} +2152 -3643
- package/chunks/{db-U3WQZVAO.js → db-5IWEJUYV.js} +3 -3
- package/chunks/{disclose-67GZCDBO.js → disclose-LDNKAVRH.js} +10 -8
- package/chunks/{dist-ACC3DZUZ.js → dist-BS4CY4RG.js} +3 -1
- package/chunks/{dist-EVTN3UTT.js → dist-FSS7MBDF.js} +2 -2
- package/chunks/{dist-F6X62TQK.js → dist-L3XJWWZ6.js} +225 -192
- package/chunks/{eval-runner-SA6OUGHZ.js → eval-runner-EMEGF24P.js} +11 -11
- package/chunks/{exploit-agent-36Q7XQFP.js → exploit-agent-KW4EB7BE.js} +1 -1
- package/chunks/{exploit-autoclimb-J4OTSTZ6.js → exploit-autoclimb-CXJ2ERRO.js} +1 -1
- package/chunks/{exploit-climb-PYEJDIC4.js → exploit-climb-TJWLY4XC.js} +2 -2
- package/chunks/fix-UUKPXCFB.js +26 -0
- package/chunks/{harness-GDUMKGSE.js → harness-C5HOKIEV.js} +3 -3
- package/chunks/{hunt-scan-UDJSCISU.js → hunt-scan-KZZ444V2.js} +14 -14
- package/chunks/{identity-JTIVJSV7.js → identity-62SVRW4H.js} +1 -1
- package/chunks/{kernel-primitive-F2IXUFAX.js → kernel-primitive-Z77IR7YS.js} +2 -2
- package/chunks/{kernel-vm-runner-276LHIOV.js → kernel-vm-runner-JW77P276.js} +2 -2
- package/chunks/{memsafety-scan-NHUOGTEX.js → memsafety-scan-FCPAXIZE.js} +2 -2
- package/chunks/{native-loop-3BSYVDUI.js → native-loop-P6P5GYVJ.js} +10 -10
- package/chunks/{npm-detectors-VIYJXKFQ.js → npm-detectors-Z2ZIQCN4.js} +2 -2
- package/chunks/orchestrate-DWWUT5RC.js +58 -0
- package/chunks/{process-PNMC36JI.js → process-N245QIQG.js} +1 -4
- package/chunks/{run-CBGE6DRQ.js → run-GAFKBCTN.js} +14935 -17598
- package/chunks/{runtime-PXO5G6UV.js → runtime-H7YBR5IZ.js} +4 -5
- package/chunks/{scope-NJHIDDTN.js → scope-QWY4VQZ7.js} +4 -1
- package/chunks/{session-store-46WBZM22.js → session-store-XIDFGG7K.js} +2 -2
- package/chunks/{variant-candidates-UH2WC2HA.js → variant-candidates-7D4F5E4H.js} +3 -3
- package/chunks/{web-recon-prepass-SFXU44SS.js → web-recon-prepass-VXXBPDAV.js} +3 -3
- package/cli-path-traversal-fixture.js +352 -0
- package/dashboard/assets/bot-Bg1Tp9_d.js +1 -0
- package/dashboard/assets/dist-B_dDCPbu.js +1 -0
- package/dashboard/assets/findings-page-mayGhNx6.js +5 -0
- package/dashboard/assets/format--susmHX7.js +1 -0
- package/dashboard/assets/input-TuVPR3Zl.js +1 -0
- package/dashboard/assets/jsx-runtime-MGseXjj5.js +3 -0
- package/dashboard/assets/live-page-HWWHX99U.js +1 -0
- package/dashboard/assets/meta-tile-ckHo-w7k.js +1 -0
- package/dashboard/assets/operations-BxZ0OoXO.js +10 -0
- package/dashboard/assets/operations-app-D3d35rgo.js +46 -0
- package/dashboard/assets/overview-page-W_4IteEr.js +1 -0
- package/dashboard/assets/page-header-Bw9AJgBV.js +1 -0
- package/dashboard/assets/scans-page-CgzVXHnn.js +1 -0
- package/dashboard/assets/siren-KQj8QAnJ.js +1 -0
- package/dashboard/assets/table-8EDklulN.js +1 -0
- package/dashboard/assets/tabs-CFHPOwg8.js +1 -0
- package/dashboard/index.html +2 -3
- package/node_modules/node-addon-api/LICENSE.md +9 -0
- package/node_modules/node-addon-api/README.md +95 -0
- package/node_modules/node-addon-api/common.gypi +21 -0
- package/node_modules/node-addon-api/except.gypi +25 -0
- package/node_modules/node-addon-api/index.js +14 -0
- package/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
- package/node_modules/node-addon-api/napi-inl.h +7250 -0
- package/node_modules/node-addon-api/napi.h +3463 -0
- package/node_modules/node-addon-api/node_addon_api.gyp +42 -0
- package/node_modules/node-addon-api/node_api.gyp +9 -0
- package/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/node_modules/node-addon-api/nothing.c +0 -0
- package/node_modules/node-addon-api/package-support.json +21 -0
- package/node_modules/node-addon-api/package.json +481 -0
- package/node_modules/node-addon-api/tools/README.md +73 -0
- package/node_modules/node-addon-api/tools/check-napi.js +99 -0
- package/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/node_modules/node-addon-api/tools/conversion.js +301 -0
- package/node_modules/node-gyp-build/LICENSE +21 -0
- package/node_modules/node-gyp-build/README.md +58 -0
- package/node_modules/node-gyp-build/SECURITY.md +5 -0
- package/node_modules/node-gyp-build/bin.js +84 -0
- package/node_modules/node-gyp-build/build-test.js +19 -0
- package/node_modules/node-gyp-build/index.js +6 -0
- package/node_modules/node-gyp-build/node-gyp-build.js +207 -0
- package/node_modules/node-gyp-build/optional.js +7 -0
- package/node_modules/node-gyp-build/package.json +43 -0
- package/node_modules/tree-sitter/LICENSE +21 -0
- package/node_modules/tree-sitter/README.md +90 -0
- package/node_modules/tree-sitter/binding.gyp +76 -0
- package/node_modules/tree-sitter/index.js +895 -0
- package/node_modules/tree-sitter/package.json +62 -0
- package/node_modules/tree-sitter/prebuilds/darwin-arm64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/darwin-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/linux-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/prebuilds/win32-x64/tree-sitter.node +0 -0
- package/node_modules/tree-sitter/src/addon_data.h +47 -0
- package/node_modules/tree-sitter/src/binding.cc +35 -0
- package/node_modules/tree-sitter/src/conversions.cc +140 -0
- package/node_modules/tree-sitter/src/conversions.h +22 -0
- package/node_modules/tree-sitter/src/language.cc +106 -0
- package/node_modules/tree-sitter/src/language.h +17 -0
- package/node_modules/tree-sitter/src/logger.cc +70 -0
- package/node_modules/tree-sitter/src/logger.h +19 -0
- package/node_modules/tree-sitter/src/lookaheaditerator.cc +122 -0
- package/node_modules/tree-sitter/src/lookaheaditerator.h +33 -0
- package/node_modules/tree-sitter/src/node.cc +1056 -0
- package/node_modules/tree-sitter/src/node.h +30 -0
- package/node_modules/tree-sitter/src/parser.cc +298 -0
- package/node_modules/tree-sitter/src/parser.h +35 -0
- package/node_modules/tree-sitter/src/query.cc +383 -0
- package/node_modules/tree-sitter/src/query.h +39 -0
- package/node_modules/tree-sitter/src/tree.cc +307 -0
- package/node_modules/tree-sitter/src/tree.h +45 -0
- package/node_modules/tree-sitter/src/tree_cursor.cc +213 -0
- package/node_modules/tree-sitter/src/tree_cursor.h +52 -0
- package/node_modules/tree-sitter/tree-sitter.d.ts +211 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/LICENSE +21 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/README.md +21 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/README.md +6 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/include/tree_sitter/api.h +1266 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.c +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/alloc.h +41 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/array.h +290 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/atomic.h +68 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/clock.h +146 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/error_costs.h +11 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.c +501 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/get_changed_ranges.h +36 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/host.h +21 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.c +221 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/language.h +299 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/length.h +52 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.c +419 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lexer.h +49 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/lib.c +14 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/node.c +774 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.c +2151 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/parser.h +230 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/point.h +62 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/query.c +4134 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reduce_action.h +34 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/reusable_node.h +95 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.c +899 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/stack.h +133 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.c +1060 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/subtree.h +382 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.c +165 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree.h +31 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.c +714 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/tree_cursor.h +48 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ICU_SHA +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/LICENSE +414 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/README.md +29 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/ptypes.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/umachine.h +448 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/urename.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf.h +1 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf16.h +733 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode/utf8.h +881 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/unicode.h +50 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib-symbols.txt +23 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/stdlib.c +109 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm/wasm-stdlib.h +1294 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.c +1823 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/lib/src/wasm_store.h +31 -0
- package/node_modules/tree-sitter/vendor/tree-sitter/test/fixtures/grammars/.gitkeep +0 -0
- package/node_modules/tree-sitter-c/LICENSE +21 -0
- package/node_modules/tree-sitter-c/README.md +18 -0
- package/node_modules/tree-sitter-c/binding.gyp +20 -0
- package/node_modules/tree-sitter-c/bindings/node/binding.cc +20 -0
- package/node_modules/tree-sitter-c/bindings/node/index.d.ts +28 -0
- package/node_modules/tree-sitter-c/bindings/node/index.js +7 -0
- package/node_modules/tree-sitter-c/grammar.js +1463 -0
- package/node_modules/tree-sitter-c/package.json +108 -0
- package/node_modules/tree-sitter-c/prebuilds/darwin-arm64/tree-sitter-c.node +0 -0
- package/node_modules/tree-sitter-c/prebuilds/darwin-x64/tree-sitter-c.node +0 -0
- package/node_modules/tree-sitter-c/prebuilds/linux-x64/tree-sitter-c.node +0 -0
- package/node_modules/tree-sitter-c/prebuilds/win32-x64/tree-sitter-c.node +0 -0
- package/node_modules/tree-sitter-c/queries/highlights.scm +81 -0
- package/node_modules/tree-sitter-c/queries/tags.scm +9 -0
- package/node_modules/tree-sitter-c/src/grammar.json +9682 -0
- package/node_modules/tree-sitter-c/src/node-types.json +4556 -0
- package/node_modules/tree-sitter-c/src/parser.c +113852 -0
- package/node_modules/tree-sitter-c/src/tree_sitter/alloc.h +54 -0
- package/node_modules/tree-sitter-c/src/tree_sitter/array.h +290 -0
- package/node_modules/tree-sitter-c/src/tree_sitter/parser.h +265 -0
- package/package.json +10 -3
- package/vendor/tree-sitter-0.21.1-node24.json +16 -0
- package/vendor/tree-sitter-0.21.1-node24.tgz +0 -0
- package/chunks/chunk-CGHCEN7W.js +0 -169
- package/chunks/chunk-CXKDWFNO.js +0 -102
- package/chunks/chunk-GIQKESMN.js +0 -687
- package/chunks/chunk-HPQZHOIU.js +0 -67
- package/chunks/chunk-PD2BBBKT.js +0 -245
- package/chunks/chunk-WF5W75WY.js +0 -1070
- package/chunks/fix-J2KBRJDV.js +0 -12
- package/chunks/orchestrate-DHBFRTSI.js +0 -59
- package/chunks/replay-runner-LK2XFIVG.js +0 -39
- package/dashboard/assets/bot-yILPnRgD.js +0 -1
- package/dashboard/assets/chevron-down-BeDJ-Vka.js +0 -1
- package/dashboard/assets/circle-alert-BEnMBMT-.js +0 -1
- package/dashboard/assets/client-DRYsuOGl.js +0 -9
- package/dashboard/assets/copy-Bi5vzoF9.js +0 -1
- package/dashboard/assets/desktop-BT7RkC4q.js +0 -32
- package/dashboard/assets/desktop-OaBI0E0e.css +0 -1
- package/dashboard/assets/dist-CmX-h7a4.js +0 -1
- package/dashboard/assets/dist-DAwYQmf_.js +0 -45
- package/dashboard/assets/findings-page-B4rwF6fZ.js +0 -5
- package/dashboard/assets/format-LNQSSpn6.js +0 -1
- package/dashboard/assets/jsx-runtime-C7oxC63R.js +0 -1
- package/dashboard/assets/live-page-DoNwpPAO.js +0 -1
- package/dashboard/assets/meta-tile-BMtBC-Qq.js +0 -1
- package/dashboard/assets/operations-app-ER0gg7GN.js +0 -2
- package/dashboard/assets/operations-e2CGYKB1.js +0 -4
- package/dashboard/assets/overview-page-CmeWH17A.js +0 -1
- package/dashboard/assets/page-header-CIJyycfz.js +0 -1
- package/dashboard/assets/play-Dwo-9xt6.js +0 -1
- package/dashboard/assets/scans-page-CuhzWhHx.js +0 -1
- package/dashboard/assets/search-CiooTLck.js +0 -1
- package/dashboard/assets/siren-CCBwTSuk.js +0 -1
- package/dashboard/assets/table-BgsSBdke.js +0 -1
- package/dashboard/assets/tabs-vn6v7Bk6.js +0 -1
- package/dashboard/desktop.html +0 -21
|
@@ -0,0 +1,1463 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file C grammar for tree-sitter
|
|
3
|
+
* @author Max Brunsfeld <maxbrunsfeld@gmail.com>
|
|
4
|
+
* @author Amaan Qureshi <amaanq12@gmail.com>
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/// <reference types="tree-sitter-cli/dsl" />
|
|
9
|
+
// @ts-check
|
|
10
|
+
|
|
11
|
+
const PREC = {
|
|
12
|
+
PAREN_DECLARATOR: -10,
|
|
13
|
+
ASSIGNMENT: -2,
|
|
14
|
+
CONDITIONAL: -1,
|
|
15
|
+
DEFAULT: 0,
|
|
16
|
+
LOGICAL_OR: 1,
|
|
17
|
+
LOGICAL_AND: 2,
|
|
18
|
+
INCLUSIVE_OR: 3,
|
|
19
|
+
EXCLUSIVE_OR: 4,
|
|
20
|
+
BITWISE_AND: 5,
|
|
21
|
+
EQUAL: 6,
|
|
22
|
+
RELATIONAL: 7,
|
|
23
|
+
OFFSETOF: 8,
|
|
24
|
+
SHIFT: 9,
|
|
25
|
+
ADD: 10,
|
|
26
|
+
MULTIPLY: 11,
|
|
27
|
+
CAST: 12,
|
|
28
|
+
SIZEOF: 13,
|
|
29
|
+
UNARY: 14,
|
|
30
|
+
CALL: 15,
|
|
31
|
+
FIELD: 16,
|
|
32
|
+
SUBSCRIPT: 17,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
module.exports = grammar({
|
|
36
|
+
name: 'c',
|
|
37
|
+
|
|
38
|
+
conflicts: $ => [
|
|
39
|
+
[$.type_specifier, $._declarator],
|
|
40
|
+
[$.type_specifier, $._declarator, $.macro_type_specifier],
|
|
41
|
+
[$.type_specifier, $.expression],
|
|
42
|
+
[$.type_specifier, $.expression, $.macro_type_specifier],
|
|
43
|
+
[$.type_specifier, $.macro_type_specifier],
|
|
44
|
+
[$.type_specifier, $.sized_type_specifier],
|
|
45
|
+
[$.sized_type_specifier],
|
|
46
|
+
[$.attributed_statement],
|
|
47
|
+
[$._declaration_modifiers, $.attributed_statement],
|
|
48
|
+
[$.enum_specifier],
|
|
49
|
+
[$.type_specifier, $._old_style_parameter_list],
|
|
50
|
+
[$.parameter_list, $._old_style_parameter_list],
|
|
51
|
+
[$.function_declarator, $._function_declaration_declarator],
|
|
52
|
+
[$._block_item, $.statement],
|
|
53
|
+
[$._top_level_item, $._top_level_statement],
|
|
54
|
+
[$.type_specifier, $._top_level_expression_statement],
|
|
55
|
+
],
|
|
56
|
+
|
|
57
|
+
extras: $ => [
|
|
58
|
+
/\s|\\\r?\n/,
|
|
59
|
+
$.comment,
|
|
60
|
+
],
|
|
61
|
+
|
|
62
|
+
inline: $ => [
|
|
63
|
+
$._type_identifier,
|
|
64
|
+
$._field_identifier,
|
|
65
|
+
$._statement_identifier,
|
|
66
|
+
$._non_case_statement,
|
|
67
|
+
$._assignment_left_expression,
|
|
68
|
+
$._expression_not_binary,
|
|
69
|
+
],
|
|
70
|
+
|
|
71
|
+
supertypes: $ => [
|
|
72
|
+
$.expression,
|
|
73
|
+
$.statement,
|
|
74
|
+
$.type_specifier,
|
|
75
|
+
$._declarator,
|
|
76
|
+
$._field_declarator,
|
|
77
|
+
$._type_declarator,
|
|
78
|
+
$._abstract_declarator,
|
|
79
|
+
],
|
|
80
|
+
|
|
81
|
+
word: $ => $.identifier,
|
|
82
|
+
|
|
83
|
+
rules: {
|
|
84
|
+
translation_unit: $ => repeat($._top_level_item),
|
|
85
|
+
|
|
86
|
+
// Top level items are block items with the exception of the expression statement
|
|
87
|
+
_top_level_item: $ => choice(
|
|
88
|
+
$.function_definition,
|
|
89
|
+
alias($._old_style_function_definition, $.function_definition),
|
|
90
|
+
$.linkage_specification,
|
|
91
|
+
$.declaration,
|
|
92
|
+
$._top_level_statement,
|
|
93
|
+
$.attributed_statement,
|
|
94
|
+
$.type_definition,
|
|
95
|
+
$._empty_declaration,
|
|
96
|
+
$.preproc_if,
|
|
97
|
+
$.preproc_ifdef,
|
|
98
|
+
$.preproc_include,
|
|
99
|
+
$.preproc_def,
|
|
100
|
+
$.preproc_function_def,
|
|
101
|
+
$.preproc_call,
|
|
102
|
+
),
|
|
103
|
+
|
|
104
|
+
_block_item: $ => choice(
|
|
105
|
+
$.function_definition,
|
|
106
|
+
alias($._old_style_function_definition, $.function_definition),
|
|
107
|
+
$.linkage_specification,
|
|
108
|
+
$.declaration,
|
|
109
|
+
$.statement,
|
|
110
|
+
$.attributed_statement,
|
|
111
|
+
$.type_definition,
|
|
112
|
+
$._empty_declaration,
|
|
113
|
+
$.preproc_if,
|
|
114
|
+
$.preproc_ifdef,
|
|
115
|
+
$.preproc_include,
|
|
116
|
+
$.preproc_def,
|
|
117
|
+
$.preproc_function_def,
|
|
118
|
+
$.preproc_call,
|
|
119
|
+
),
|
|
120
|
+
|
|
121
|
+
// Preprocesser
|
|
122
|
+
|
|
123
|
+
preproc_include: $ => seq(
|
|
124
|
+
preprocessor('include'),
|
|
125
|
+
field('path', choice(
|
|
126
|
+
$.string_literal,
|
|
127
|
+
$.system_lib_string,
|
|
128
|
+
$.identifier,
|
|
129
|
+
alias($.preproc_call_expression, $.call_expression),
|
|
130
|
+
)),
|
|
131
|
+
token.immediate(/\r?\n/),
|
|
132
|
+
),
|
|
133
|
+
|
|
134
|
+
preproc_def: $ => seq(
|
|
135
|
+
preprocessor('define'),
|
|
136
|
+
field('name', $.identifier),
|
|
137
|
+
field('value', optional($.preproc_arg)),
|
|
138
|
+
token.immediate(/\r?\n/),
|
|
139
|
+
),
|
|
140
|
+
|
|
141
|
+
preproc_function_def: $ => seq(
|
|
142
|
+
preprocessor('define'),
|
|
143
|
+
field('name', $.identifier),
|
|
144
|
+
field('parameters', $.preproc_params),
|
|
145
|
+
field('value', optional($.preproc_arg)),
|
|
146
|
+
token.immediate(/\r?\n/),
|
|
147
|
+
),
|
|
148
|
+
|
|
149
|
+
preproc_params: $ => seq(
|
|
150
|
+
token.immediate('('), commaSep(choice($.identifier, '...')), ')',
|
|
151
|
+
),
|
|
152
|
+
|
|
153
|
+
preproc_call: $ => seq(
|
|
154
|
+
field('directive', $.preproc_directive),
|
|
155
|
+
field('argument', optional($.preproc_arg)),
|
|
156
|
+
token.immediate(/\r?\n/),
|
|
157
|
+
),
|
|
158
|
+
|
|
159
|
+
...preprocIf('', $ => $._block_item),
|
|
160
|
+
...preprocIf('_in_field_declaration_list', $ => $._field_declaration_list_item),
|
|
161
|
+
...preprocIf('_in_enumerator_list', $ => seq($.enumerator, ',')),
|
|
162
|
+
...preprocIf('_in_enumerator_list_no_comma', $ => $.enumerator, -1),
|
|
163
|
+
|
|
164
|
+
preproc_arg: _ => token(prec(-1, /\S([^/\n]|\/[^*]|\\\r?\n)*/)),
|
|
165
|
+
preproc_directive: _ => /#[ \t]*[a-zA-Z0-9]\w*/,
|
|
166
|
+
|
|
167
|
+
_preproc_expression: $ => choice(
|
|
168
|
+
$.identifier,
|
|
169
|
+
alias($.preproc_call_expression, $.call_expression),
|
|
170
|
+
$.number_literal,
|
|
171
|
+
$.char_literal,
|
|
172
|
+
$.preproc_defined,
|
|
173
|
+
alias($.preproc_unary_expression, $.unary_expression),
|
|
174
|
+
alias($.preproc_binary_expression, $.binary_expression),
|
|
175
|
+
alias($.preproc_parenthesized_expression, $.parenthesized_expression),
|
|
176
|
+
),
|
|
177
|
+
|
|
178
|
+
preproc_parenthesized_expression: $ => seq(
|
|
179
|
+
'(',
|
|
180
|
+
$._preproc_expression,
|
|
181
|
+
')',
|
|
182
|
+
),
|
|
183
|
+
|
|
184
|
+
preproc_defined: $ => choice(
|
|
185
|
+
prec(PREC.CALL, seq('defined', '(', $.identifier, ')')),
|
|
186
|
+
seq('defined', $.identifier),
|
|
187
|
+
),
|
|
188
|
+
|
|
189
|
+
preproc_unary_expression: $ => prec.left(PREC.UNARY, seq(
|
|
190
|
+
field('operator', choice('!', '~', '-', '+')),
|
|
191
|
+
field('argument', $._preproc_expression),
|
|
192
|
+
)),
|
|
193
|
+
|
|
194
|
+
preproc_call_expression: $ => prec(PREC.CALL, seq(
|
|
195
|
+
field('function', $.identifier),
|
|
196
|
+
field('arguments', alias($.preproc_argument_list, $.argument_list)),
|
|
197
|
+
)),
|
|
198
|
+
|
|
199
|
+
preproc_argument_list: $ => seq(
|
|
200
|
+
'(',
|
|
201
|
+
commaSep($._preproc_expression),
|
|
202
|
+
')',
|
|
203
|
+
),
|
|
204
|
+
|
|
205
|
+
preproc_binary_expression: $ => {
|
|
206
|
+
const table = [
|
|
207
|
+
['+', PREC.ADD],
|
|
208
|
+
['-', PREC.ADD],
|
|
209
|
+
['*', PREC.MULTIPLY],
|
|
210
|
+
['/', PREC.MULTIPLY],
|
|
211
|
+
['%', PREC.MULTIPLY],
|
|
212
|
+
['||', PREC.LOGICAL_OR],
|
|
213
|
+
['&&', PREC.LOGICAL_AND],
|
|
214
|
+
['|', PREC.INCLUSIVE_OR],
|
|
215
|
+
['^', PREC.EXCLUSIVE_OR],
|
|
216
|
+
['&', PREC.BITWISE_AND],
|
|
217
|
+
['==', PREC.EQUAL],
|
|
218
|
+
['!=', PREC.EQUAL],
|
|
219
|
+
['>', PREC.RELATIONAL],
|
|
220
|
+
['>=', PREC.RELATIONAL],
|
|
221
|
+
['<=', PREC.RELATIONAL],
|
|
222
|
+
['<', PREC.RELATIONAL],
|
|
223
|
+
['<<', PREC.SHIFT],
|
|
224
|
+
['>>', PREC.SHIFT],
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
return choice(...table.map(([operator, precedence]) => {
|
|
228
|
+
return prec.left(precedence, seq(
|
|
229
|
+
field('left', $._preproc_expression),
|
|
230
|
+
// @ts-ignore
|
|
231
|
+
field('operator', operator),
|
|
232
|
+
field('right', $._preproc_expression),
|
|
233
|
+
));
|
|
234
|
+
}));
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
// Main Grammar
|
|
238
|
+
|
|
239
|
+
function_definition: $ => seq(
|
|
240
|
+
optional($.ms_call_modifier),
|
|
241
|
+
$._declaration_specifiers,
|
|
242
|
+
optional($.ms_call_modifier),
|
|
243
|
+
field('declarator', $._declarator),
|
|
244
|
+
field('body', $.compound_statement),
|
|
245
|
+
),
|
|
246
|
+
|
|
247
|
+
_old_style_function_definition: $ => seq(
|
|
248
|
+
optional($.ms_call_modifier),
|
|
249
|
+
$._declaration_specifiers,
|
|
250
|
+
field('declarator', alias($._old_style_function_declarator, $.function_declarator)),
|
|
251
|
+
repeat($.declaration),
|
|
252
|
+
field('body', $.compound_statement),
|
|
253
|
+
),
|
|
254
|
+
|
|
255
|
+
declaration: $ => seq(
|
|
256
|
+
$._declaration_specifiers,
|
|
257
|
+
commaSep1(field('declarator', choice(
|
|
258
|
+
seq(
|
|
259
|
+
optional($.ms_call_modifier),
|
|
260
|
+
$._declaration_declarator,
|
|
261
|
+
optional($.gnu_asm_expression),
|
|
262
|
+
),
|
|
263
|
+
$.init_declarator,
|
|
264
|
+
))),
|
|
265
|
+
';',
|
|
266
|
+
),
|
|
267
|
+
|
|
268
|
+
type_definition: $ => seq(
|
|
269
|
+
optional('__extension__'),
|
|
270
|
+
'typedef',
|
|
271
|
+
$._type_definition_type,
|
|
272
|
+
$._type_definition_declarators,
|
|
273
|
+
repeat($.attribute_specifier),
|
|
274
|
+
';',
|
|
275
|
+
),
|
|
276
|
+
_type_definition_type: $ => seq(repeat($.type_qualifier), field('type', $.type_specifier), repeat($.type_qualifier)),
|
|
277
|
+
_type_definition_declarators: $ => commaSep1(field('declarator', $._type_declarator)),
|
|
278
|
+
|
|
279
|
+
_declaration_modifiers: $ => choice(
|
|
280
|
+
$.storage_class_specifier,
|
|
281
|
+
$.type_qualifier,
|
|
282
|
+
$.attribute_specifier,
|
|
283
|
+
$.attribute_declaration,
|
|
284
|
+
$.ms_declspec_modifier,
|
|
285
|
+
),
|
|
286
|
+
|
|
287
|
+
_declaration_specifiers: $ => prec.right(seq(
|
|
288
|
+
repeat($._declaration_modifiers),
|
|
289
|
+
field('type', $.type_specifier),
|
|
290
|
+
repeat($._declaration_modifiers),
|
|
291
|
+
)),
|
|
292
|
+
|
|
293
|
+
linkage_specification: $ => seq(
|
|
294
|
+
'extern',
|
|
295
|
+
field('value', $.string_literal),
|
|
296
|
+
field('body', choice(
|
|
297
|
+
$.function_definition,
|
|
298
|
+
$.declaration,
|
|
299
|
+
$.declaration_list,
|
|
300
|
+
)),
|
|
301
|
+
),
|
|
302
|
+
|
|
303
|
+
attribute_specifier: $ => seq(
|
|
304
|
+
'__attribute__',
|
|
305
|
+
'(',
|
|
306
|
+
$.argument_list,
|
|
307
|
+
')',
|
|
308
|
+
),
|
|
309
|
+
|
|
310
|
+
attribute: $ => seq(
|
|
311
|
+
optional(seq(field('prefix', $.identifier), '::')),
|
|
312
|
+
field('name', $.identifier),
|
|
313
|
+
optional($.argument_list),
|
|
314
|
+
),
|
|
315
|
+
|
|
316
|
+
attribute_declaration: $ => seq(
|
|
317
|
+
'[[',
|
|
318
|
+
commaSep1($.attribute),
|
|
319
|
+
']]',
|
|
320
|
+
),
|
|
321
|
+
|
|
322
|
+
ms_declspec_modifier: $ => seq(
|
|
323
|
+
'__declspec',
|
|
324
|
+
'(',
|
|
325
|
+
$.identifier,
|
|
326
|
+
')',
|
|
327
|
+
),
|
|
328
|
+
|
|
329
|
+
ms_based_modifier: $ => seq(
|
|
330
|
+
'__based',
|
|
331
|
+
$.argument_list,
|
|
332
|
+
),
|
|
333
|
+
|
|
334
|
+
ms_call_modifier: _ => choice(
|
|
335
|
+
'__cdecl',
|
|
336
|
+
'__clrcall',
|
|
337
|
+
'__stdcall',
|
|
338
|
+
'__fastcall',
|
|
339
|
+
'__thiscall',
|
|
340
|
+
'__vectorcall',
|
|
341
|
+
),
|
|
342
|
+
|
|
343
|
+
ms_restrict_modifier: _ => '__restrict',
|
|
344
|
+
|
|
345
|
+
ms_unsigned_ptr_modifier: _ => '__uptr',
|
|
346
|
+
|
|
347
|
+
ms_signed_ptr_modifier: _ => '__sptr',
|
|
348
|
+
|
|
349
|
+
ms_unaligned_ptr_modifier: _ => choice('_unaligned', '__unaligned'),
|
|
350
|
+
|
|
351
|
+
ms_pointer_modifier: $ => choice(
|
|
352
|
+
$.ms_unaligned_ptr_modifier,
|
|
353
|
+
$.ms_restrict_modifier,
|
|
354
|
+
$.ms_unsigned_ptr_modifier,
|
|
355
|
+
$.ms_signed_ptr_modifier,
|
|
356
|
+
),
|
|
357
|
+
|
|
358
|
+
declaration_list: $ => seq(
|
|
359
|
+
'{',
|
|
360
|
+
repeat($._block_item),
|
|
361
|
+
'}',
|
|
362
|
+
),
|
|
363
|
+
|
|
364
|
+
_declarator: $ => choice(
|
|
365
|
+
$.attributed_declarator,
|
|
366
|
+
$.pointer_declarator,
|
|
367
|
+
$.function_declarator,
|
|
368
|
+
$.array_declarator,
|
|
369
|
+
$.parenthesized_declarator,
|
|
370
|
+
$.identifier,
|
|
371
|
+
),
|
|
372
|
+
|
|
373
|
+
_declaration_declarator: $ => choice(
|
|
374
|
+
$.attributed_declarator,
|
|
375
|
+
$.pointer_declarator,
|
|
376
|
+
alias($._function_declaration_declarator, $.function_declarator),
|
|
377
|
+
$.array_declarator,
|
|
378
|
+
$.parenthesized_declarator,
|
|
379
|
+
$.identifier,
|
|
380
|
+
),
|
|
381
|
+
|
|
382
|
+
_field_declarator: $ => choice(
|
|
383
|
+
alias($.attributed_field_declarator, $.attributed_declarator),
|
|
384
|
+
alias($.pointer_field_declarator, $.pointer_declarator),
|
|
385
|
+
alias($.function_field_declarator, $.function_declarator),
|
|
386
|
+
alias($.array_field_declarator, $.array_declarator),
|
|
387
|
+
alias($.parenthesized_field_declarator, $.parenthesized_declarator),
|
|
388
|
+
$._field_identifier,
|
|
389
|
+
),
|
|
390
|
+
|
|
391
|
+
_type_declarator: $ => choice(
|
|
392
|
+
alias($.attributed_type_declarator, $.attributed_declarator),
|
|
393
|
+
alias($.pointer_type_declarator, $.pointer_declarator),
|
|
394
|
+
alias($.function_type_declarator, $.function_declarator),
|
|
395
|
+
alias($.array_type_declarator, $.array_declarator),
|
|
396
|
+
alias($.parenthesized_type_declarator, $.parenthesized_declarator),
|
|
397
|
+
$._type_identifier,
|
|
398
|
+
alias(choice('signed', 'unsigned', 'long', 'short'), $.primitive_type),
|
|
399
|
+
$.primitive_type,
|
|
400
|
+
),
|
|
401
|
+
|
|
402
|
+
_abstract_declarator: $ => choice(
|
|
403
|
+
$.abstract_pointer_declarator,
|
|
404
|
+
$.abstract_function_declarator,
|
|
405
|
+
$.abstract_array_declarator,
|
|
406
|
+
$.abstract_parenthesized_declarator,
|
|
407
|
+
),
|
|
408
|
+
|
|
409
|
+
parenthesized_declarator: $ => prec.dynamic(PREC.PAREN_DECLARATOR, seq(
|
|
410
|
+
'(',
|
|
411
|
+
optional($.ms_call_modifier),
|
|
412
|
+
$._declarator,
|
|
413
|
+
')',
|
|
414
|
+
)),
|
|
415
|
+
parenthesized_field_declarator: $ => prec.dynamic(PREC.PAREN_DECLARATOR, seq(
|
|
416
|
+
'(',
|
|
417
|
+
optional($.ms_call_modifier),
|
|
418
|
+
$._field_declarator,
|
|
419
|
+
')',
|
|
420
|
+
)),
|
|
421
|
+
parenthesized_type_declarator: $ => prec.dynamic(PREC.PAREN_DECLARATOR, seq(
|
|
422
|
+
'(',
|
|
423
|
+
optional($.ms_call_modifier),
|
|
424
|
+
$._type_declarator,
|
|
425
|
+
')',
|
|
426
|
+
)),
|
|
427
|
+
abstract_parenthesized_declarator: $ => prec(1, seq(
|
|
428
|
+
'(',
|
|
429
|
+
optional($.ms_call_modifier),
|
|
430
|
+
$._abstract_declarator,
|
|
431
|
+
')',
|
|
432
|
+
)),
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
attributed_declarator: $ => prec.right(seq(
|
|
436
|
+
$._declarator,
|
|
437
|
+
repeat1($.attribute_declaration),
|
|
438
|
+
)),
|
|
439
|
+
attributed_field_declarator: $ => prec.right(seq(
|
|
440
|
+
$._field_declarator,
|
|
441
|
+
repeat1($.attribute_declaration),
|
|
442
|
+
)),
|
|
443
|
+
attributed_type_declarator: $ => prec.right(seq(
|
|
444
|
+
$._type_declarator,
|
|
445
|
+
repeat1($.attribute_declaration),
|
|
446
|
+
)),
|
|
447
|
+
|
|
448
|
+
pointer_declarator: $ => prec.dynamic(1, prec.right(seq(
|
|
449
|
+
optional($.ms_based_modifier),
|
|
450
|
+
'*',
|
|
451
|
+
repeat($.ms_pointer_modifier),
|
|
452
|
+
repeat($.type_qualifier),
|
|
453
|
+
field('declarator', $._declarator),
|
|
454
|
+
))),
|
|
455
|
+
pointer_field_declarator: $ => prec.dynamic(1, prec.right(seq(
|
|
456
|
+
optional($.ms_based_modifier),
|
|
457
|
+
'*',
|
|
458
|
+
repeat($.ms_pointer_modifier),
|
|
459
|
+
repeat($.type_qualifier),
|
|
460
|
+
field('declarator', $._field_declarator),
|
|
461
|
+
))),
|
|
462
|
+
pointer_type_declarator: $ => prec.dynamic(1, prec.right(seq(
|
|
463
|
+
optional($.ms_based_modifier),
|
|
464
|
+
'*',
|
|
465
|
+
repeat($.ms_pointer_modifier),
|
|
466
|
+
repeat($.type_qualifier),
|
|
467
|
+
field('declarator', $._type_declarator),
|
|
468
|
+
))),
|
|
469
|
+
abstract_pointer_declarator: $ => prec.dynamic(1, prec.right(seq('*',
|
|
470
|
+
repeat($.ms_pointer_modifier),
|
|
471
|
+
repeat($.type_qualifier),
|
|
472
|
+
field('declarator', optional($._abstract_declarator)),
|
|
473
|
+
))),
|
|
474
|
+
|
|
475
|
+
function_declarator: $ => prec.right(1,
|
|
476
|
+
seq(
|
|
477
|
+
field('declarator', $._declarator),
|
|
478
|
+
field('parameters', $.parameter_list),
|
|
479
|
+
optional($.gnu_asm_expression),
|
|
480
|
+
repeat(choice(
|
|
481
|
+
$.attribute_specifier,
|
|
482
|
+
$.identifier,
|
|
483
|
+
alias($.preproc_call_expression, $.call_expression),
|
|
484
|
+
)),
|
|
485
|
+
),
|
|
486
|
+
),
|
|
487
|
+
|
|
488
|
+
_function_declaration_declarator: $ => prec.right(1,
|
|
489
|
+
seq(
|
|
490
|
+
field('declarator', $._declarator),
|
|
491
|
+
field('parameters', $.parameter_list),
|
|
492
|
+
optional($.gnu_asm_expression),
|
|
493
|
+
repeat($.attribute_specifier),
|
|
494
|
+
)),
|
|
495
|
+
|
|
496
|
+
function_field_declarator: $ => prec(1, seq(
|
|
497
|
+
field('declarator', $._field_declarator),
|
|
498
|
+
field('parameters', $.parameter_list),
|
|
499
|
+
)),
|
|
500
|
+
function_type_declarator: $ => prec(1, seq(
|
|
501
|
+
field('declarator', $._type_declarator),
|
|
502
|
+
field('parameters', $.parameter_list),
|
|
503
|
+
)),
|
|
504
|
+
abstract_function_declarator: $ => prec(1, seq(
|
|
505
|
+
field('declarator', optional($._abstract_declarator)),
|
|
506
|
+
field('parameters', $.parameter_list),
|
|
507
|
+
)),
|
|
508
|
+
|
|
509
|
+
_old_style_function_declarator: $ => seq(
|
|
510
|
+
field('declarator', $._declarator),
|
|
511
|
+
field('parameters', alias($._old_style_parameter_list, $.parameter_list)),
|
|
512
|
+
),
|
|
513
|
+
|
|
514
|
+
array_declarator: $ => prec(1, seq(
|
|
515
|
+
field('declarator', $._declarator),
|
|
516
|
+
'[',
|
|
517
|
+
repeat(choice($.type_qualifier, 'static')),
|
|
518
|
+
field('size', optional(choice($.expression, '*'))),
|
|
519
|
+
']',
|
|
520
|
+
)),
|
|
521
|
+
array_field_declarator: $ => prec(1, seq(
|
|
522
|
+
field('declarator', $._field_declarator),
|
|
523
|
+
'[',
|
|
524
|
+
repeat(choice($.type_qualifier, 'static')),
|
|
525
|
+
field('size', optional(choice($.expression, '*'))),
|
|
526
|
+
']',
|
|
527
|
+
)),
|
|
528
|
+
array_type_declarator: $ => prec(1, seq(
|
|
529
|
+
field('declarator', $._type_declarator),
|
|
530
|
+
'[',
|
|
531
|
+
repeat(choice($.type_qualifier, 'static')),
|
|
532
|
+
field('size', optional(choice($.expression, '*'))),
|
|
533
|
+
']',
|
|
534
|
+
)),
|
|
535
|
+
abstract_array_declarator: $ => prec(1, seq(
|
|
536
|
+
field('declarator', optional($._abstract_declarator)),
|
|
537
|
+
'[',
|
|
538
|
+
repeat(choice($.type_qualifier, 'static')),
|
|
539
|
+
field('size', optional(choice($.expression, '*'))),
|
|
540
|
+
']',
|
|
541
|
+
)),
|
|
542
|
+
|
|
543
|
+
init_declarator: $ => seq(
|
|
544
|
+
field('declarator', $._declarator),
|
|
545
|
+
'=',
|
|
546
|
+
field('value', choice($.initializer_list, $.expression)),
|
|
547
|
+
),
|
|
548
|
+
|
|
549
|
+
compound_statement: $ => seq(
|
|
550
|
+
'{',
|
|
551
|
+
repeat($._block_item),
|
|
552
|
+
'}',
|
|
553
|
+
),
|
|
554
|
+
|
|
555
|
+
storage_class_specifier: _ => choice(
|
|
556
|
+
'extern',
|
|
557
|
+
'static',
|
|
558
|
+
'auto',
|
|
559
|
+
'register',
|
|
560
|
+
'inline',
|
|
561
|
+
'__inline',
|
|
562
|
+
'__inline__',
|
|
563
|
+
'__forceinline',
|
|
564
|
+
'thread_local',
|
|
565
|
+
'__thread',
|
|
566
|
+
),
|
|
567
|
+
|
|
568
|
+
type_qualifier: $ => choice(
|
|
569
|
+
'const',
|
|
570
|
+
'constexpr',
|
|
571
|
+
'volatile',
|
|
572
|
+
'restrict',
|
|
573
|
+
'__restrict__',
|
|
574
|
+
'__extension__',
|
|
575
|
+
'_Atomic',
|
|
576
|
+
'_Noreturn',
|
|
577
|
+
'noreturn',
|
|
578
|
+
$.alignas_qualifier,
|
|
579
|
+
),
|
|
580
|
+
|
|
581
|
+
alignas_qualifier: $ => seq(
|
|
582
|
+
choice('alignas', '_Alignas'),
|
|
583
|
+
'(',
|
|
584
|
+
choice($.expression, $.type_descriptor),
|
|
585
|
+
')',
|
|
586
|
+
),
|
|
587
|
+
|
|
588
|
+
type_specifier: $ => choice(
|
|
589
|
+
$.struct_specifier,
|
|
590
|
+
$.union_specifier,
|
|
591
|
+
$.enum_specifier,
|
|
592
|
+
$.macro_type_specifier,
|
|
593
|
+
$.sized_type_specifier,
|
|
594
|
+
$.primitive_type,
|
|
595
|
+
$._type_identifier,
|
|
596
|
+
),
|
|
597
|
+
|
|
598
|
+
sized_type_specifier: $ => choice(
|
|
599
|
+
seq(
|
|
600
|
+
repeat(choice(
|
|
601
|
+
'signed',
|
|
602
|
+
'unsigned',
|
|
603
|
+
'long',
|
|
604
|
+
'short',
|
|
605
|
+
)),
|
|
606
|
+
field('type', optional(choice(
|
|
607
|
+
prec.dynamic(-1, $._type_identifier),
|
|
608
|
+
$.primitive_type,
|
|
609
|
+
))),
|
|
610
|
+
repeat1(choice(
|
|
611
|
+
'signed',
|
|
612
|
+
'unsigned',
|
|
613
|
+
'long',
|
|
614
|
+
'short',
|
|
615
|
+
)),
|
|
616
|
+
),
|
|
617
|
+
seq(
|
|
618
|
+
repeat1(choice(
|
|
619
|
+
'signed',
|
|
620
|
+
'unsigned',
|
|
621
|
+
'long',
|
|
622
|
+
'short',
|
|
623
|
+
)),
|
|
624
|
+
field('type', optional(choice(
|
|
625
|
+
prec.dynamic(-1, $._type_identifier),
|
|
626
|
+
$.primitive_type,
|
|
627
|
+
))),
|
|
628
|
+
repeat(choice(
|
|
629
|
+
'signed',
|
|
630
|
+
'unsigned',
|
|
631
|
+
'long',
|
|
632
|
+
'short',
|
|
633
|
+
)),
|
|
634
|
+
),
|
|
635
|
+
),
|
|
636
|
+
|
|
637
|
+
primitive_type: _ => token(choice(
|
|
638
|
+
'bool',
|
|
639
|
+
'char',
|
|
640
|
+
'int',
|
|
641
|
+
'float',
|
|
642
|
+
'double',
|
|
643
|
+
'void',
|
|
644
|
+
'size_t',
|
|
645
|
+
'ssize_t',
|
|
646
|
+
'ptrdiff_t',
|
|
647
|
+
'intptr_t',
|
|
648
|
+
'uintptr_t',
|
|
649
|
+
'charptr_t',
|
|
650
|
+
'nullptr_t',
|
|
651
|
+
'max_align_t',
|
|
652
|
+
...[8, 16, 32, 64].map(n => `int${n}_t`),
|
|
653
|
+
...[8, 16, 32, 64].map(n => `uint${n}_t`),
|
|
654
|
+
...[8, 16, 32, 64].map(n => `char${n}_t`),
|
|
655
|
+
)),
|
|
656
|
+
|
|
657
|
+
enum_specifier: $ => seq(
|
|
658
|
+
'enum',
|
|
659
|
+
choice(
|
|
660
|
+
seq(
|
|
661
|
+
field('name', $._type_identifier),
|
|
662
|
+
optional(seq(':', field('underlying_type', $.primitive_type))),
|
|
663
|
+
field('body', optional($.enumerator_list)),
|
|
664
|
+
),
|
|
665
|
+
field('body', $.enumerator_list),
|
|
666
|
+
),
|
|
667
|
+
optional($.attribute_specifier),
|
|
668
|
+
),
|
|
669
|
+
|
|
670
|
+
enumerator_list: $ => seq(
|
|
671
|
+
'{',
|
|
672
|
+
repeat(choice(
|
|
673
|
+
seq($.enumerator, ','),
|
|
674
|
+
alias($.preproc_if_in_enumerator_list, $.preproc_if),
|
|
675
|
+
alias($.preproc_ifdef_in_enumerator_list, $.preproc_ifdef),
|
|
676
|
+
seq($.preproc_call, ','),
|
|
677
|
+
)),
|
|
678
|
+
optional(seq(
|
|
679
|
+
choice(
|
|
680
|
+
$.enumerator,
|
|
681
|
+
alias($.preproc_if_in_enumerator_list_no_comma, $.preproc_if),
|
|
682
|
+
alias($.preproc_ifdef_in_enumerator_list_no_comma, $.preproc_ifdef),
|
|
683
|
+
$.preproc_call,
|
|
684
|
+
),
|
|
685
|
+
)),
|
|
686
|
+
'}',
|
|
687
|
+
),
|
|
688
|
+
|
|
689
|
+
struct_specifier: $ => prec.right(seq(
|
|
690
|
+
'struct',
|
|
691
|
+
optional($.attribute_specifier),
|
|
692
|
+
optional($.ms_declspec_modifier),
|
|
693
|
+
choice(
|
|
694
|
+
seq(
|
|
695
|
+
field('name', $._type_identifier),
|
|
696
|
+
field('body', optional($.field_declaration_list)),
|
|
697
|
+
),
|
|
698
|
+
field('body', $.field_declaration_list),
|
|
699
|
+
),
|
|
700
|
+
optional($.attribute_specifier),
|
|
701
|
+
)),
|
|
702
|
+
|
|
703
|
+
union_specifier: $ => prec.right(seq(
|
|
704
|
+
'union',
|
|
705
|
+
optional($.ms_declspec_modifier),
|
|
706
|
+
choice(
|
|
707
|
+
seq(
|
|
708
|
+
field('name', $._type_identifier),
|
|
709
|
+
field('body', optional($.field_declaration_list)),
|
|
710
|
+
),
|
|
711
|
+
field('body', $.field_declaration_list),
|
|
712
|
+
),
|
|
713
|
+
optional($.attribute_specifier),
|
|
714
|
+
)),
|
|
715
|
+
|
|
716
|
+
field_declaration_list: $ => seq(
|
|
717
|
+
'{',
|
|
718
|
+
repeat($._field_declaration_list_item),
|
|
719
|
+
'}',
|
|
720
|
+
),
|
|
721
|
+
|
|
722
|
+
_field_declaration_list_item: $ => choice(
|
|
723
|
+
$.field_declaration,
|
|
724
|
+
$.preproc_def,
|
|
725
|
+
$.preproc_function_def,
|
|
726
|
+
$.preproc_call,
|
|
727
|
+
alias($.preproc_if_in_field_declaration_list, $.preproc_if),
|
|
728
|
+
alias($.preproc_ifdef_in_field_declaration_list, $.preproc_ifdef),
|
|
729
|
+
),
|
|
730
|
+
|
|
731
|
+
field_declaration: $ => seq(
|
|
732
|
+
$._declaration_specifiers,
|
|
733
|
+
optional($._field_declaration_declarator),
|
|
734
|
+
optional($.attribute_specifier),
|
|
735
|
+
';',
|
|
736
|
+
),
|
|
737
|
+
_field_declaration_declarator: $ => commaSep1(seq(
|
|
738
|
+
field('declarator', $._field_declarator),
|
|
739
|
+
optional($.bitfield_clause),
|
|
740
|
+
)),
|
|
741
|
+
|
|
742
|
+
bitfield_clause: $ => seq(':', $.expression),
|
|
743
|
+
|
|
744
|
+
enumerator: $ => seq(
|
|
745
|
+
field('name', $.identifier),
|
|
746
|
+
optional(seq('=', field('value', $.expression))),
|
|
747
|
+
),
|
|
748
|
+
|
|
749
|
+
variadic_parameter: _ => '...',
|
|
750
|
+
|
|
751
|
+
parameter_list: $ => seq(
|
|
752
|
+
'(',
|
|
753
|
+
commaSep(choice($.parameter_declaration, $.variadic_parameter)),
|
|
754
|
+
')',
|
|
755
|
+
),
|
|
756
|
+
_old_style_parameter_list: $ => seq(
|
|
757
|
+
'(',
|
|
758
|
+
commaSep(choice($.identifier, $.variadic_parameter)),
|
|
759
|
+
')',
|
|
760
|
+
),
|
|
761
|
+
|
|
762
|
+
parameter_declaration: $ => seq(
|
|
763
|
+
$._declaration_specifiers,
|
|
764
|
+
optional(field('declarator', choice(
|
|
765
|
+
$._declarator,
|
|
766
|
+
$._abstract_declarator,
|
|
767
|
+
))),
|
|
768
|
+
),
|
|
769
|
+
|
|
770
|
+
// Statements
|
|
771
|
+
|
|
772
|
+
attributed_statement: $ => seq(
|
|
773
|
+
repeat1($.attribute_declaration),
|
|
774
|
+
$.statement,
|
|
775
|
+
),
|
|
776
|
+
|
|
777
|
+
statement: $ => choice(
|
|
778
|
+
$.case_statement,
|
|
779
|
+
$._non_case_statement,
|
|
780
|
+
),
|
|
781
|
+
|
|
782
|
+
_non_case_statement: $ => choice(
|
|
783
|
+
$.attributed_statement,
|
|
784
|
+
$.labeled_statement,
|
|
785
|
+
$.compound_statement,
|
|
786
|
+
$.expression_statement,
|
|
787
|
+
$.if_statement,
|
|
788
|
+
$.switch_statement,
|
|
789
|
+
$.do_statement,
|
|
790
|
+
$.while_statement,
|
|
791
|
+
$.for_statement,
|
|
792
|
+
$.return_statement,
|
|
793
|
+
$.break_statement,
|
|
794
|
+
$.continue_statement,
|
|
795
|
+
$.goto_statement,
|
|
796
|
+
$.seh_try_statement,
|
|
797
|
+
$.seh_leave_statement,
|
|
798
|
+
),
|
|
799
|
+
|
|
800
|
+
_top_level_statement: $ => choice(
|
|
801
|
+
$.case_statement,
|
|
802
|
+
$.attributed_statement,
|
|
803
|
+
$.labeled_statement,
|
|
804
|
+
$.compound_statement,
|
|
805
|
+
alias($._top_level_expression_statement, $.expression_statement),
|
|
806
|
+
$.if_statement,
|
|
807
|
+
$.switch_statement,
|
|
808
|
+
$.do_statement,
|
|
809
|
+
$.while_statement,
|
|
810
|
+
$.for_statement,
|
|
811
|
+
$.return_statement,
|
|
812
|
+
$.break_statement,
|
|
813
|
+
$.continue_statement,
|
|
814
|
+
$.goto_statement,
|
|
815
|
+
),
|
|
816
|
+
|
|
817
|
+
labeled_statement: $ => seq(
|
|
818
|
+
field('label', $._statement_identifier),
|
|
819
|
+
':',
|
|
820
|
+
$.statement,
|
|
821
|
+
),
|
|
822
|
+
|
|
823
|
+
// This is missing binary expressions, others were kept so that macro code can be parsed better and code examples
|
|
824
|
+
_top_level_expression_statement: $ => seq(
|
|
825
|
+
$._expression_not_binary,
|
|
826
|
+
';',
|
|
827
|
+
),
|
|
828
|
+
|
|
829
|
+
expression_statement: $ => seq(
|
|
830
|
+
optional(choice(
|
|
831
|
+
$.expression,
|
|
832
|
+
$.comma_expression,
|
|
833
|
+
)),
|
|
834
|
+
';',
|
|
835
|
+
),
|
|
836
|
+
|
|
837
|
+
if_statement: $ => prec.right(seq(
|
|
838
|
+
'if',
|
|
839
|
+
field('condition', $.parenthesized_expression),
|
|
840
|
+
field('consequence', $.statement),
|
|
841
|
+
optional(field('alternative', $.else_clause)),
|
|
842
|
+
)),
|
|
843
|
+
|
|
844
|
+
else_clause: $ => seq('else', $.statement),
|
|
845
|
+
|
|
846
|
+
switch_statement: $ => seq(
|
|
847
|
+
'switch',
|
|
848
|
+
field('condition', $.parenthesized_expression),
|
|
849
|
+
field('body', $.compound_statement),
|
|
850
|
+
),
|
|
851
|
+
|
|
852
|
+
case_statement: $ => prec.right(seq(
|
|
853
|
+
choice(
|
|
854
|
+
seq('case', field('value', $.expression)),
|
|
855
|
+
'default',
|
|
856
|
+
),
|
|
857
|
+
':',
|
|
858
|
+
repeat(choice(
|
|
859
|
+
$._non_case_statement,
|
|
860
|
+
$.declaration,
|
|
861
|
+
$.type_definition,
|
|
862
|
+
)),
|
|
863
|
+
)),
|
|
864
|
+
|
|
865
|
+
while_statement: $ => seq(
|
|
866
|
+
'while',
|
|
867
|
+
field('condition', $.parenthesized_expression),
|
|
868
|
+
field('body', $.statement),
|
|
869
|
+
),
|
|
870
|
+
|
|
871
|
+
do_statement: $ => seq(
|
|
872
|
+
'do',
|
|
873
|
+
field('body', $.statement),
|
|
874
|
+
'while',
|
|
875
|
+
field('condition', $.parenthesized_expression),
|
|
876
|
+
';',
|
|
877
|
+
),
|
|
878
|
+
|
|
879
|
+
for_statement: $ => seq(
|
|
880
|
+
'for',
|
|
881
|
+
'(',
|
|
882
|
+
$._for_statement_body,
|
|
883
|
+
')',
|
|
884
|
+
field('body', $.statement),
|
|
885
|
+
),
|
|
886
|
+
_for_statement_body: $ => seq(
|
|
887
|
+
choice(
|
|
888
|
+
field('initializer', $.declaration),
|
|
889
|
+
seq(field('initializer', optional(choice($.expression, $.comma_expression))), ';'),
|
|
890
|
+
),
|
|
891
|
+
field('condition', optional(choice($.expression, $.comma_expression))),
|
|
892
|
+
';',
|
|
893
|
+
field('update', optional(choice($.expression, $.comma_expression))),
|
|
894
|
+
),
|
|
895
|
+
|
|
896
|
+
return_statement: $ => seq(
|
|
897
|
+
'return',
|
|
898
|
+
optional(choice($.expression, $.comma_expression)),
|
|
899
|
+
';',
|
|
900
|
+
),
|
|
901
|
+
|
|
902
|
+
break_statement: _ => seq(
|
|
903
|
+
'break', ';',
|
|
904
|
+
),
|
|
905
|
+
|
|
906
|
+
continue_statement: _ => seq(
|
|
907
|
+
'continue', ';',
|
|
908
|
+
),
|
|
909
|
+
|
|
910
|
+
goto_statement: $ => seq(
|
|
911
|
+
'goto',
|
|
912
|
+
field('label', $._statement_identifier),
|
|
913
|
+
';',
|
|
914
|
+
),
|
|
915
|
+
|
|
916
|
+
seh_try_statement: $ => seq(
|
|
917
|
+
'__try',
|
|
918
|
+
field('body', $.compound_statement),
|
|
919
|
+
choice($.seh_except_clause, $.seh_finally_clause),
|
|
920
|
+
),
|
|
921
|
+
|
|
922
|
+
seh_except_clause: $ => seq(
|
|
923
|
+
'__except',
|
|
924
|
+
field('filter', $.parenthesized_expression),
|
|
925
|
+
field('body', $.compound_statement),
|
|
926
|
+
),
|
|
927
|
+
|
|
928
|
+
seh_finally_clause: $ => seq(
|
|
929
|
+
'__finally',
|
|
930
|
+
field('body', $.compound_statement),
|
|
931
|
+
),
|
|
932
|
+
|
|
933
|
+
seh_leave_statement: _ => seq(
|
|
934
|
+
'__leave', ';',
|
|
935
|
+
),
|
|
936
|
+
|
|
937
|
+
// Expressions
|
|
938
|
+
|
|
939
|
+
expression: $ => choice(
|
|
940
|
+
$._expression_not_binary,
|
|
941
|
+
$.binary_expression,
|
|
942
|
+
),
|
|
943
|
+
|
|
944
|
+
_expression_not_binary: $ => choice(
|
|
945
|
+
$.conditional_expression,
|
|
946
|
+
$.assignment_expression,
|
|
947
|
+
$.unary_expression,
|
|
948
|
+
$.update_expression,
|
|
949
|
+
$.cast_expression,
|
|
950
|
+
$.pointer_expression,
|
|
951
|
+
$.sizeof_expression,
|
|
952
|
+
$.alignof_expression,
|
|
953
|
+
$.offsetof_expression,
|
|
954
|
+
$.generic_expression,
|
|
955
|
+
$.subscript_expression,
|
|
956
|
+
$.call_expression,
|
|
957
|
+
$.field_expression,
|
|
958
|
+
$.compound_literal_expression,
|
|
959
|
+
$.identifier,
|
|
960
|
+
$.number_literal,
|
|
961
|
+
$._string,
|
|
962
|
+
$.true,
|
|
963
|
+
$.false,
|
|
964
|
+
$.null,
|
|
965
|
+
$.char_literal,
|
|
966
|
+
$.parenthesized_expression,
|
|
967
|
+
$.gnu_asm_expression,
|
|
968
|
+
),
|
|
969
|
+
|
|
970
|
+
_string: $ => prec.left(choice(
|
|
971
|
+
$.string_literal,
|
|
972
|
+
$.concatenated_string,
|
|
973
|
+
)),
|
|
974
|
+
|
|
975
|
+
comma_expression: $ => seq(
|
|
976
|
+
field('left', $.expression),
|
|
977
|
+
',',
|
|
978
|
+
field('right', choice($.expression, $.comma_expression)),
|
|
979
|
+
),
|
|
980
|
+
|
|
981
|
+
conditional_expression: $ => prec.right(PREC.CONDITIONAL, seq(
|
|
982
|
+
field('condition', $.expression),
|
|
983
|
+
'?',
|
|
984
|
+
optional(field('consequence', choice($.expression, $.comma_expression))),
|
|
985
|
+
':',
|
|
986
|
+
field('alternative', $.expression),
|
|
987
|
+
)),
|
|
988
|
+
|
|
989
|
+
_assignment_left_expression: $ => choice(
|
|
990
|
+
$.identifier,
|
|
991
|
+
$.call_expression,
|
|
992
|
+
$.field_expression,
|
|
993
|
+
$.pointer_expression,
|
|
994
|
+
$.subscript_expression,
|
|
995
|
+
$.parenthesized_expression,
|
|
996
|
+
),
|
|
997
|
+
|
|
998
|
+
assignment_expression: $ => prec.right(PREC.ASSIGNMENT, seq(
|
|
999
|
+
field('left', $._assignment_left_expression),
|
|
1000
|
+
field('operator', choice(
|
|
1001
|
+
'=',
|
|
1002
|
+
'*=',
|
|
1003
|
+
'/=',
|
|
1004
|
+
'%=',
|
|
1005
|
+
'+=',
|
|
1006
|
+
'-=',
|
|
1007
|
+
'<<=',
|
|
1008
|
+
'>>=',
|
|
1009
|
+
'&=',
|
|
1010
|
+
'^=',
|
|
1011
|
+
'|=',
|
|
1012
|
+
)),
|
|
1013
|
+
field('right', $.expression),
|
|
1014
|
+
)),
|
|
1015
|
+
|
|
1016
|
+
pointer_expression: $ => prec.left(PREC.CAST, seq(
|
|
1017
|
+
field('operator', choice('*', '&')),
|
|
1018
|
+
field('argument', $.expression),
|
|
1019
|
+
)),
|
|
1020
|
+
|
|
1021
|
+
unary_expression: $ => prec.left(PREC.UNARY, seq(
|
|
1022
|
+
field('operator', choice('!', '~', '-', '+')),
|
|
1023
|
+
field('argument', $.expression),
|
|
1024
|
+
)),
|
|
1025
|
+
|
|
1026
|
+
binary_expression: $ => {
|
|
1027
|
+
const table = [
|
|
1028
|
+
['+', PREC.ADD],
|
|
1029
|
+
['-', PREC.ADD],
|
|
1030
|
+
['*', PREC.MULTIPLY],
|
|
1031
|
+
['/', PREC.MULTIPLY],
|
|
1032
|
+
['%', PREC.MULTIPLY],
|
|
1033
|
+
['||', PREC.LOGICAL_OR],
|
|
1034
|
+
['&&', PREC.LOGICAL_AND],
|
|
1035
|
+
['|', PREC.INCLUSIVE_OR],
|
|
1036
|
+
['^', PREC.EXCLUSIVE_OR],
|
|
1037
|
+
['&', PREC.BITWISE_AND],
|
|
1038
|
+
['==', PREC.EQUAL],
|
|
1039
|
+
['!=', PREC.EQUAL],
|
|
1040
|
+
['>', PREC.RELATIONAL],
|
|
1041
|
+
['>=', PREC.RELATIONAL],
|
|
1042
|
+
['<=', PREC.RELATIONAL],
|
|
1043
|
+
['<', PREC.RELATIONAL],
|
|
1044
|
+
['<<', PREC.SHIFT],
|
|
1045
|
+
['>>', PREC.SHIFT],
|
|
1046
|
+
];
|
|
1047
|
+
|
|
1048
|
+
return choice(...table.map(([operator, precedence]) => {
|
|
1049
|
+
return prec.left(precedence, seq(
|
|
1050
|
+
field('left', $.expression),
|
|
1051
|
+
// @ts-ignore
|
|
1052
|
+
field('operator', operator),
|
|
1053
|
+
field('right', $.expression),
|
|
1054
|
+
));
|
|
1055
|
+
}));
|
|
1056
|
+
},
|
|
1057
|
+
|
|
1058
|
+
update_expression: $ => {
|
|
1059
|
+
const argument = field('argument', $.expression);
|
|
1060
|
+
const operator = field('operator', choice('--', '++'));
|
|
1061
|
+
return prec.right(PREC.UNARY, choice(
|
|
1062
|
+
seq(operator, argument),
|
|
1063
|
+
seq(argument, operator),
|
|
1064
|
+
));
|
|
1065
|
+
},
|
|
1066
|
+
|
|
1067
|
+
cast_expression: $ => prec(PREC.CAST, seq(
|
|
1068
|
+
'(',
|
|
1069
|
+
field('type', $.type_descriptor),
|
|
1070
|
+
')',
|
|
1071
|
+
field('value', $.expression),
|
|
1072
|
+
)),
|
|
1073
|
+
|
|
1074
|
+
type_descriptor: $ => seq(
|
|
1075
|
+
repeat($.type_qualifier),
|
|
1076
|
+
field('type', $.type_specifier),
|
|
1077
|
+
repeat($.type_qualifier),
|
|
1078
|
+
field('declarator', optional($._abstract_declarator)),
|
|
1079
|
+
),
|
|
1080
|
+
|
|
1081
|
+
sizeof_expression: $ => prec(PREC.SIZEOF, seq(
|
|
1082
|
+
'sizeof',
|
|
1083
|
+
choice(
|
|
1084
|
+
field('value', $.expression),
|
|
1085
|
+
seq('(', field('type', $.type_descriptor), ')'),
|
|
1086
|
+
),
|
|
1087
|
+
)),
|
|
1088
|
+
|
|
1089
|
+
alignof_expression: $ => prec(PREC.SIZEOF, seq(
|
|
1090
|
+
choice('__alignof__', '__alignof', '_alignof', 'alignof', '_Alignof'),
|
|
1091
|
+
seq('(', field('type', $.type_descriptor), ')'),
|
|
1092
|
+
)),
|
|
1093
|
+
|
|
1094
|
+
offsetof_expression: $ => prec(PREC.OFFSETOF, seq(
|
|
1095
|
+
'offsetof',
|
|
1096
|
+
seq('(', field('type', $.type_descriptor), ',', field('member', $._field_identifier), ')'),
|
|
1097
|
+
)),
|
|
1098
|
+
|
|
1099
|
+
generic_expression: $ => prec(PREC.CALL, seq(
|
|
1100
|
+
'_Generic',
|
|
1101
|
+
'(',
|
|
1102
|
+
$.expression,
|
|
1103
|
+
',',
|
|
1104
|
+
commaSep1(seq($.type_descriptor, ':', $.expression)),
|
|
1105
|
+
')',
|
|
1106
|
+
)),
|
|
1107
|
+
|
|
1108
|
+
subscript_expression: $ => prec(PREC.SUBSCRIPT, seq(
|
|
1109
|
+
field('argument', $.expression),
|
|
1110
|
+
'[',
|
|
1111
|
+
field('index', $.expression),
|
|
1112
|
+
']',
|
|
1113
|
+
)),
|
|
1114
|
+
|
|
1115
|
+
call_expression: $ => prec(PREC.CALL, seq(
|
|
1116
|
+
field('function', $.expression),
|
|
1117
|
+
field('arguments', $.argument_list),
|
|
1118
|
+
)),
|
|
1119
|
+
|
|
1120
|
+
gnu_asm_expression: $ => prec(PREC.CALL, seq(
|
|
1121
|
+
choice('asm', '__asm__'),
|
|
1122
|
+
repeat($.gnu_asm_qualifier),
|
|
1123
|
+
'(',
|
|
1124
|
+
field('assembly_code', $._string),
|
|
1125
|
+
optional(seq(
|
|
1126
|
+
field('output_operands', $.gnu_asm_output_operand_list),
|
|
1127
|
+
optional(seq(
|
|
1128
|
+
field('input_operands', $.gnu_asm_input_operand_list),
|
|
1129
|
+
optional(seq(
|
|
1130
|
+
field('clobbers', $.gnu_asm_clobber_list),
|
|
1131
|
+
optional(field('goto_labels', $.gnu_asm_goto_list)),
|
|
1132
|
+
)),
|
|
1133
|
+
)),
|
|
1134
|
+
)),
|
|
1135
|
+
')',
|
|
1136
|
+
)),
|
|
1137
|
+
|
|
1138
|
+
gnu_asm_qualifier: _ => choice(
|
|
1139
|
+
'volatile',
|
|
1140
|
+
'inline',
|
|
1141
|
+
'goto',
|
|
1142
|
+
),
|
|
1143
|
+
|
|
1144
|
+
gnu_asm_output_operand_list: $ => seq(
|
|
1145
|
+
':',
|
|
1146
|
+
commaSep(field('operand', $.gnu_asm_output_operand)),
|
|
1147
|
+
),
|
|
1148
|
+
|
|
1149
|
+
gnu_asm_output_operand: $ => seq(
|
|
1150
|
+
optional(seq(
|
|
1151
|
+
'[',
|
|
1152
|
+
field('symbol', $.identifier),
|
|
1153
|
+
']',
|
|
1154
|
+
)),
|
|
1155
|
+
field('constraint', $.string_literal),
|
|
1156
|
+
'(',
|
|
1157
|
+
field('value', $.identifier),
|
|
1158
|
+
')',
|
|
1159
|
+
),
|
|
1160
|
+
|
|
1161
|
+
gnu_asm_input_operand_list: $ => seq(
|
|
1162
|
+
':',
|
|
1163
|
+
commaSep(field('operand', $.gnu_asm_input_operand)),
|
|
1164
|
+
),
|
|
1165
|
+
|
|
1166
|
+
gnu_asm_input_operand: $ => seq(
|
|
1167
|
+
optional(seq(
|
|
1168
|
+
'[',
|
|
1169
|
+
field('symbol', $.identifier),
|
|
1170
|
+
']',
|
|
1171
|
+
)),
|
|
1172
|
+
field('constraint', $.string_literal),
|
|
1173
|
+
'(',
|
|
1174
|
+
field('value', $.expression),
|
|
1175
|
+
')',
|
|
1176
|
+
),
|
|
1177
|
+
|
|
1178
|
+
gnu_asm_clobber_list: $ => seq(
|
|
1179
|
+
':',
|
|
1180
|
+
commaSep(field('register', $._string)),
|
|
1181
|
+
),
|
|
1182
|
+
|
|
1183
|
+
gnu_asm_goto_list: $ => seq(
|
|
1184
|
+
':',
|
|
1185
|
+
commaSep(field('label', $.identifier)),
|
|
1186
|
+
),
|
|
1187
|
+
|
|
1188
|
+
// The compound_statement is added to parse macros taking statements as arguments, e.g. MYFORLOOP(1, 10, i, { foo(i); bar(i); })
|
|
1189
|
+
argument_list: $ => seq('(', commaSep(choice(seq(optional('__extension__'), $.expression), $.compound_statement)), ')'),
|
|
1190
|
+
|
|
1191
|
+
field_expression: $ => seq(
|
|
1192
|
+
prec(PREC.FIELD, seq(
|
|
1193
|
+
field('argument', $.expression),
|
|
1194
|
+
field('operator', choice('.', '->')),
|
|
1195
|
+
)),
|
|
1196
|
+
field('field', $._field_identifier),
|
|
1197
|
+
),
|
|
1198
|
+
|
|
1199
|
+
compound_literal_expression: $ => seq(
|
|
1200
|
+
'(',
|
|
1201
|
+
field('type', $.type_descriptor),
|
|
1202
|
+
')',
|
|
1203
|
+
field('value', $.initializer_list),
|
|
1204
|
+
),
|
|
1205
|
+
|
|
1206
|
+
parenthesized_expression: $ => seq(
|
|
1207
|
+
'(',
|
|
1208
|
+
choice($.expression, $.comma_expression),
|
|
1209
|
+
')',
|
|
1210
|
+
),
|
|
1211
|
+
|
|
1212
|
+
initializer_list: $ => seq(
|
|
1213
|
+
'{',
|
|
1214
|
+
commaSep(choice(
|
|
1215
|
+
$.initializer_pair,
|
|
1216
|
+
$.expression,
|
|
1217
|
+
$.initializer_list,
|
|
1218
|
+
)),
|
|
1219
|
+
optional(','),
|
|
1220
|
+
'}',
|
|
1221
|
+
),
|
|
1222
|
+
|
|
1223
|
+
initializer_pair: $ => choice(
|
|
1224
|
+
seq(
|
|
1225
|
+
field('designator', repeat1(choice(
|
|
1226
|
+
$.subscript_designator,
|
|
1227
|
+
$.field_designator,
|
|
1228
|
+
$.subscript_range_designator,
|
|
1229
|
+
))),
|
|
1230
|
+
'=',
|
|
1231
|
+
field('value', choice($.expression, $.initializer_list)),
|
|
1232
|
+
),
|
|
1233
|
+
seq(
|
|
1234
|
+
field('designator', $._field_identifier),
|
|
1235
|
+
':',
|
|
1236
|
+
field('value', choice($.expression, $.initializer_list)),
|
|
1237
|
+
),
|
|
1238
|
+
),
|
|
1239
|
+
|
|
1240
|
+
subscript_designator: $ => seq('[', $.expression, ']'),
|
|
1241
|
+
|
|
1242
|
+
subscript_range_designator: $ => seq('[', field('start', $.expression), '...', field('end', $.expression), ']'),
|
|
1243
|
+
|
|
1244
|
+
field_designator: $ => seq('.', $._field_identifier),
|
|
1245
|
+
|
|
1246
|
+
number_literal: _ => {
|
|
1247
|
+
const separator = '\'';
|
|
1248
|
+
const hex = /[0-9a-fA-F]/;
|
|
1249
|
+
const decimal = /[0-9]/;
|
|
1250
|
+
const hexDigits = seq(repeat1(hex), repeat(seq(separator, repeat1(hex))));
|
|
1251
|
+
const decimalDigits = seq(repeat1(decimal), repeat(seq(separator, repeat1(decimal))));
|
|
1252
|
+
return token(seq(
|
|
1253
|
+
optional(/[-\+]/),
|
|
1254
|
+
optional(choice(/0[xX]/, /0[bB]/)),
|
|
1255
|
+
choice(
|
|
1256
|
+
seq(
|
|
1257
|
+
choice(
|
|
1258
|
+
decimalDigits,
|
|
1259
|
+
seq(/0[bB]/, decimalDigits),
|
|
1260
|
+
seq(/0[xX]/, hexDigits),
|
|
1261
|
+
),
|
|
1262
|
+
optional(seq('.', optional(hexDigits))),
|
|
1263
|
+
),
|
|
1264
|
+
seq('.', decimalDigits),
|
|
1265
|
+
),
|
|
1266
|
+
optional(seq(
|
|
1267
|
+
/[eEpP]/,
|
|
1268
|
+
optional(seq(
|
|
1269
|
+
optional(/[-\+]/),
|
|
1270
|
+
hexDigits,
|
|
1271
|
+
)),
|
|
1272
|
+
)),
|
|
1273
|
+
/[uUlLwWfFbBdD]*/,
|
|
1274
|
+
));
|
|
1275
|
+
},
|
|
1276
|
+
|
|
1277
|
+
char_literal: $ => seq(
|
|
1278
|
+
choice('L\'', 'u\'', 'U\'', 'u8\'', '\''),
|
|
1279
|
+
repeat1(choice(
|
|
1280
|
+
$.escape_sequence,
|
|
1281
|
+
alias(token.immediate(/[^\n']/), $.character),
|
|
1282
|
+
)),
|
|
1283
|
+
'\'',
|
|
1284
|
+
),
|
|
1285
|
+
|
|
1286
|
+
// Must concatenate at least 2 nodes, one of which must be a string_literal.
|
|
1287
|
+
// Identifier is added to parse macros that are strings, like PRIu64.
|
|
1288
|
+
concatenated_string: $ => prec.right(seq(
|
|
1289
|
+
choice(
|
|
1290
|
+
seq($.identifier, $.string_literal),
|
|
1291
|
+
seq($.string_literal, $.string_literal),
|
|
1292
|
+
seq($.string_literal, $.identifier),
|
|
1293
|
+
),
|
|
1294
|
+
repeat(choice($.string_literal, $.identifier)),
|
|
1295
|
+
)),
|
|
1296
|
+
|
|
1297
|
+
string_literal: $ => seq(
|
|
1298
|
+
choice('L"', 'u"', 'U"', 'u8"', '"'),
|
|
1299
|
+
repeat(choice(
|
|
1300
|
+
alias(token.immediate(prec(1, /[^\\"\n]+/)), $.string_content),
|
|
1301
|
+
$.escape_sequence,
|
|
1302
|
+
)),
|
|
1303
|
+
'"',
|
|
1304
|
+
),
|
|
1305
|
+
|
|
1306
|
+
escape_sequence: _ => token(prec(1, seq(
|
|
1307
|
+
'\\',
|
|
1308
|
+
choice(
|
|
1309
|
+
/[^xuU]/,
|
|
1310
|
+
/\d{2,3}/,
|
|
1311
|
+
/x[0-9a-fA-F]{2,}/,
|
|
1312
|
+
/u[0-9a-fA-F]{4}/,
|
|
1313
|
+
/U[0-9a-fA-F]{8}/,
|
|
1314
|
+
),
|
|
1315
|
+
))),
|
|
1316
|
+
|
|
1317
|
+
system_lib_string: _ => token(seq(
|
|
1318
|
+
'<',
|
|
1319
|
+
repeat(choice(/[^>\n]/, '\\>')),
|
|
1320
|
+
'>',
|
|
1321
|
+
)),
|
|
1322
|
+
|
|
1323
|
+
true: _ => token(choice('TRUE', 'true')),
|
|
1324
|
+
false: _ => token(choice('FALSE', 'false')),
|
|
1325
|
+
null: _ => choice('NULL', 'nullptr'),
|
|
1326
|
+
|
|
1327
|
+
identifier: _ =>
|
|
1328
|
+
// eslint-disable-next-line max-len
|
|
1329
|
+
/(\p{XID_Start}|\$|_|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})(\p{XID_Continue}|\$|\\u[0-9A-Fa-f]{4}|\\U[0-9A-Fa-f]{8})*/,
|
|
1330
|
+
|
|
1331
|
+
_type_identifier: $ => alias(
|
|
1332
|
+
$.identifier,
|
|
1333
|
+
$.type_identifier,
|
|
1334
|
+
),
|
|
1335
|
+
_field_identifier: $ => alias($.identifier, $.field_identifier),
|
|
1336
|
+
_statement_identifier: $ => alias($.identifier, $.statement_identifier),
|
|
1337
|
+
|
|
1338
|
+
_empty_declaration: $ => seq(
|
|
1339
|
+
$.type_specifier,
|
|
1340
|
+
';',
|
|
1341
|
+
),
|
|
1342
|
+
|
|
1343
|
+
macro_type_specifier: $ => prec.dynamic(-1, seq(
|
|
1344
|
+
field('name', $.identifier),
|
|
1345
|
+
'(',
|
|
1346
|
+
field('type', $.type_descriptor),
|
|
1347
|
+
')',
|
|
1348
|
+
)),
|
|
1349
|
+
|
|
1350
|
+
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
|
|
1351
|
+
comment: _ => token(choice(
|
|
1352
|
+
seq('//', /(\\+(.|\r?\n)|[^\\\n])*/),
|
|
1353
|
+
seq(
|
|
1354
|
+
'/*',
|
|
1355
|
+
/[^*]*\*+([^/*][^*]*\*+)*/,
|
|
1356
|
+
'/',
|
|
1357
|
+
),
|
|
1358
|
+
)),
|
|
1359
|
+
},
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
module.exports.PREC = PREC;
|
|
1363
|
+
|
|
1364
|
+
/**
|
|
1365
|
+
*
|
|
1366
|
+
* @param {string} suffix
|
|
1367
|
+
*
|
|
1368
|
+
* @param {RuleBuilder<string>} content
|
|
1369
|
+
*
|
|
1370
|
+
* @param {number} precedence
|
|
1371
|
+
*
|
|
1372
|
+
* @return {RuleBuilders<string, string>}
|
|
1373
|
+
*/
|
|
1374
|
+
function preprocIf(suffix, content, precedence = 0) {
|
|
1375
|
+
/**
|
|
1376
|
+
*
|
|
1377
|
+
* @param {GrammarSymbols<string>} $
|
|
1378
|
+
*
|
|
1379
|
+
* @return {ChoiceRule}
|
|
1380
|
+
*
|
|
1381
|
+
*/
|
|
1382
|
+
function alternativeBlock($) {
|
|
1383
|
+
return choice(
|
|
1384
|
+
suffix ? alias($['preproc_else' + suffix], $.preproc_else) : $.preproc_else,
|
|
1385
|
+
suffix ? alias($['preproc_elif' + suffix], $.preproc_elif) : $.preproc_elif,
|
|
1386
|
+
suffix ? alias($['preproc_elifdef' + suffix], $.preproc_elifdef) : $.preproc_elifdef,
|
|
1387
|
+
);
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
return {
|
|
1391
|
+
['preproc_if' + suffix]: $ => prec(precedence, seq(
|
|
1392
|
+
preprocessor('if'),
|
|
1393
|
+
field('condition', $._preproc_expression),
|
|
1394
|
+
'\n',
|
|
1395
|
+
repeat(content($)),
|
|
1396
|
+
field('alternative', optional(alternativeBlock($))),
|
|
1397
|
+
preprocessor('endif'),
|
|
1398
|
+
)),
|
|
1399
|
+
|
|
1400
|
+
['preproc_ifdef' + suffix]: $ => prec(precedence, seq(
|
|
1401
|
+
choice(preprocessor('ifdef'), preprocessor('ifndef')),
|
|
1402
|
+
field('name', $.identifier),
|
|
1403
|
+
repeat(content($)),
|
|
1404
|
+
field('alternative', optional(alternativeBlock($))),
|
|
1405
|
+
preprocessor('endif'),
|
|
1406
|
+
)),
|
|
1407
|
+
|
|
1408
|
+
['preproc_else' + suffix]: $ => prec(precedence, seq(
|
|
1409
|
+
preprocessor('else'),
|
|
1410
|
+
repeat(content($)),
|
|
1411
|
+
)),
|
|
1412
|
+
|
|
1413
|
+
['preproc_elif' + suffix]: $ => prec(precedence, seq(
|
|
1414
|
+
preprocessor('elif'),
|
|
1415
|
+
field('condition', $._preproc_expression),
|
|
1416
|
+
'\n',
|
|
1417
|
+
repeat(content($)),
|
|
1418
|
+
field('alternative', optional(alternativeBlock($))),
|
|
1419
|
+
)),
|
|
1420
|
+
|
|
1421
|
+
['preproc_elifdef' + suffix]: $ => prec(precedence, seq(
|
|
1422
|
+
choice(preprocessor('elifdef'), preprocessor('elifndef')),
|
|
1423
|
+
field('name', $.identifier),
|
|
1424
|
+
repeat(content($)),
|
|
1425
|
+
field('alternative', optional(alternativeBlock($))),
|
|
1426
|
+
)),
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
/**
|
|
1431
|
+
* Creates a preprocessor regex rule
|
|
1432
|
+
*
|
|
1433
|
+
* @param {RegExp|Rule|String} command
|
|
1434
|
+
*
|
|
1435
|
+
* @return {AliasRule}
|
|
1436
|
+
*/
|
|
1437
|
+
function preprocessor(command) {
|
|
1438
|
+
return alias(new RegExp('#[ \t]*' + command), '#' + command);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* Creates a rule to optionally match one or more of the rules separated by a comma
|
|
1443
|
+
*
|
|
1444
|
+
* @param {Rule} rule
|
|
1445
|
+
*
|
|
1446
|
+
* @return {ChoiceRule}
|
|
1447
|
+
*
|
|
1448
|
+
*/
|
|
1449
|
+
function commaSep(rule) {
|
|
1450
|
+
return optional(commaSep1(rule));
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
/**
|
|
1454
|
+
* Creates a rule to match one or more of the rules separated by a comma
|
|
1455
|
+
*
|
|
1456
|
+
* @param {Rule} rule
|
|
1457
|
+
*
|
|
1458
|
+
* @return {SeqRule}
|
|
1459
|
+
*
|
|
1460
|
+
*/
|
|
1461
|
+
function commaSep1(rule) {
|
|
1462
|
+
return seq(rule, repeat(seq(',', rule)));
|
|
1463
|
+
}
|