From ad139e0a3afc9b99d567004b829e6ec444765110 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Sun, 30 Sep 2018 15:59:56 -0700 Subject: [PATCH] Initial commit --- .appveyor.yml | 22 + .gitignore | 3 + .travis.yml | 23 + binding.gyp | 18 + corpus/declarations.txt | 7 + corpus/selectors.txt | 98 +++ corpus/stylesheets.txt | 15 + grammar.js | 97 +++ index.js | 9 + package-lock.json | 1239 ++++++++++++++++++++++++++++++++++ package.json | 21 + src/binding.cc | 28 + src/grammar.json | 361 ++++++++++ src/parser.c | 1367 ++++++++++++++++++++++++++++++++++++++ src/tree_sitter/parser.h | 195 ++++++ 15 files changed, 3503 insertions(+) create mode 100644 .appveyor.yml create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 binding.gyp create mode 100644 corpus/declarations.txt create mode 100644 corpus/selectors.txt create mode 100644 corpus/stylesheets.txt create mode 100644 grammar.js create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 src/binding.cc create mode 100644 src/grammar.json create mode 100644 src/parser.c create mode 100644 src/tree_sitter/parser.h diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..b21947b --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,22 @@ +image: Visual Studio 2015 + +environment: + nodejs_version: "8" + +platform: + - x64 + +install: + - ps: Install-Product node $env:nodejs_version + - node --version + - npm --version + - npm install + +test_script: + - npm run test-windows + +build: off + +branches: + only: + - master diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01a5e93 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +build +*.log diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1ed42ad --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +language: node_js + +sudo: false + +node_js: + - "node" + +compiler: clang-3.6 + +env: + - CXX=clang-3.6 + +addons: + apt: + sources: + - llvm-toolchain-precise-3.6 + - ubuntu-toolchain-r-test + packages: + - clang-3.6 + +branches: + only: + - master diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 0000000..81ca8f4 --- /dev/null +++ b/binding.gyp @@ -0,0 +1,18 @@ +{ + "targets": [ + { + "target_name": "tree_sitter_css_binding", + "include_dirs": [ + " b {} +c > d > e {} + +--- + +(stylesheet + (rule_set + (selectors (child_selector (type_selector (identifier)) (type_selector (identifier)))) + (block)) + (rule_set + (selectors (child_selector + (child_selector (type_selector (identifier)) (type_selector (identifier))) + (type_selector (identifier)))) + (block))) + +========================= +Descendant selectors +========================= + +a b {} +c d e {} + +--- + +(stylesheet + (rule_set + (selectors (descendant_selector (type_selector (identifier)) (type_selector (identifier)))) + (block)) + (rule_set + (selectors (descendant_selector + (descendant_selector (type_selector (identifier)) (type_selector (identifier))) + (type_selector (identifier)))) + (block))) diff --git a/corpus/stylesheets.txt b/corpus/stylesheets.txt new file mode 100644 index 0000000..dab64fc --- /dev/null +++ b/corpus/stylesheets.txt @@ -0,0 +1,15 @@ +============================ +Rule sets +============================ + +#some-id { + some-property: 5px; +} + +--- + +(stylesheet + (rule_set + (selectors (id_selector (identifier))) + (block + (declaration (property_name (identifier)) (property_value))))) diff --git a/grammar.js b/grammar.js new file mode 100644 index 0000000..01dd67f --- /dev/null +++ b/grammar.js @@ -0,0 +1,97 @@ +module.exports = grammar({ + name: 'css', + + extras: $ => [ + /\s/, + $.comment, + ], + + rules: { + stylesheet: $ => repeat(choice( + $.rule_set, + $.import_statement, + )), + + // Statements + + import_statement: $ => seq( + '@import' + ), + + // Rule sets + + rule_set: $ => seq( + $.selectors, + $.block + ), + + selectors: $ => commaSep1($._selector), + + block: $ => seq('{', repeat($.declaration), '}'), + + // Selectors + + _selector: $ => choice( + $.universal_selector, + $.type_selector, + $.class_selector, + $.id_selector, + $.attribute_selector, + $.child_selector, + $.descendant_selector + ), + + universal_selector: $ => '*', + + type_selector: $ => $.identifier, + + class_selector: $ => seq('.', $.identifier), + + id_selector: $ => seq('#', $.identifier), + + attribute_selector: $ => seq( + choice( + '[', + seq($._selector, token.immediate('[')) + ), + $.property_name, + optional(seq( + choice('=', '~=', '^=', '|=', '*=', '$='), + $.property_value + )), + ']' + ), + + child_selector: $ => prec.left(seq($._selector, '>', $._selector)), + + descendant_selector: $ => prec.left(seq($._selector, $._selector)), + + // Declarations + + declaration: $ => seq( + $.property_name, + ':', + $.property_value, + ';' + ), + + property_name: $ => $.identifier, + + identifier: $ => /[a-zA-Z-_]+/, + + property_value: $ => /[^;()\[\]]+/, + + comment: $ => token(choice( + seq('//', /.*/), + seq( + '/*', + /[^*]*\*+([^/*][^*]*\*+)*/, + '/' + ) + )) + } +}) + +function commaSep1 (rule) { + return seq(rule, repeat(seq(',', rule))) +} diff --git a/index.js b/index.js new file mode 100644 index 0000000..4d04f92 --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +try { + module.exports = require("./build/Release/tree_sitter_css_binding"); +} catch (error) { + try { + module.exports = require("./build/Debug/tree_sitter_css_binding"); + } catch (_) { + throw error + } +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f1d8acf --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1239 @@ +{ + "name": "tree-sitter-css", + "version": "0.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "nan": { + "version": "2.11.1", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.11.1.tgz", + "integrity": "sha512-iji6k87OSXa0CcrLl9z+ZiYSuR2o+c0bGuNmXdrhTQTakxytAFsC56SArGYoiHlJlFoHSnvmhpceZJaXkVuOtA==" + }, + "tree-sitter-cli": { + "version": "0.13.10", + "dev": true, + "requires": { + "@maxbrunsfeld/flame-graph": "^0.1.9", + "ejs": "^2.5.7", + "fs-extra": "^0.30.0", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "nan": "^2.10.0", + "prettier": "^1.12.1", + "temp": "0.8.x", + "tree-sitter": "^0.13.15", + "vows": "0.7.x" + }, + "dependencies": { + "@maxbrunsfeld/flame-graph": { + "version": "0.1.9", + "bundled": true, + "dev": true, + "requires": { + "dedent": "^0.7.0", + "minimist": "^1.2.0", + "temp": "^0.8.3" + } + }, + "ansi-regex": { + "version": "2.1.1", + "bundled": true + }, + "aproba": { + "version": "1.2.0", + "bundled": true + }, + "are-we-there-yet": { + "version": "1.1.5", + "bundled": true, + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "balanced-match": { + "version": "1.0.0", + "bundled": true + }, + "bl": { + "version": "1.2.2", + "bundled": true, + "requires": { + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" + } + }, + "block-stream": { + "version": "", + "bundled": true + }, + "brace-expansion": { + "version": "1.1.11", + "bundled": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "browser-stdout": { + "version": "1.3.1", + "bundled": true + }, + "buffer-alloc": { + "version": "1.2.0", + "bundled": true, + "requires": { + "buffer-alloc-unsafe": "^1.1.0", + "buffer-fill": "^1.0.0" + } + }, + "buffer-alloc-unsafe": { + "version": "1.1.0", + "bundled": true + }, + "buffer-fill": { + "version": "1.0.0", + "bundled": true + }, + "chai": { + "version": "3.5.0", + "bundled": true, + "requires": { + "assertion-error": "^1.0.1", + "deep-eql": "^0.1.3", + "type-detect": "^1.0.0" + }, + "dependencies": { + "assertion-error": { + "version": "1.0.2", + "bundled": true + }, + "deep-eql": { + "version": "0.1.3", + "bundled": true, + "requires": { + "type-detect": "0.1.1" + }, + "dependencies": { + "type-detect": { + "version": "0.1.1", + "bundled": true + } + } + }, + "type-detect": { + "version": "1.0.0", + "bundled": true + } + } + }, + "chownr": { + "version": "1.0.1", + "bundled": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true + }, + "commander": { + "version": "2.15.1", + "bundled": true + }, + "concat-map": { + "version": "0.0.1", + "bundled": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true + }, + "debug": { + "version": "3.1.0", + "bundled": true, + "requires": { + "ms": "2.0.0" + } + }, + "decompress-response": { + "version": "3.3.0", + "bundled": true, + "requires": { + "mimic-response": "^1.0.0" + } + }, + "dedent": { + "version": "0.7.0", + "bundled": true, + "dev": true + }, + "deep-extend": { + "version": "0.6.0", + "bundled": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true + }, + "detect-libc": { + "version": "1.0.3", + "bundled": true + }, + "diff": { + "version": "3.5.0", + "bundled": true + }, + "ejs": { + "version": "2.6.1", + "bundled": true, + "dev": true + }, + "end-of-stream": { + "version": "1.4.1", + "bundled": true, + "requires": { + "once": "^1.4.0" + } + }, + "escape-string-regexp": { + "version": "1.0.5", + "bundled": true + }, + "expand-template": { + "version": "1.1.1", + "bundled": true + }, + "fs-constants": { + "version": "1.0.0", + "bundled": true + }, + "fs-extra": { + "version": "0.30.0", + "bundled": true, + "dev": true, + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^2.1.0", + "klaw": "^1.0.0", + "path-is-absolute": "^1.0.0", + "rimraf": "^2.2.8" + }, + "dependencies": { + "balanced-match": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "brace-expansion": { + "version": "1.1.8", + "bundled": true, + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "concat-map": { + "version": "0.0.1", + "bundled": true, + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "graceful-fs": { + "version": "4.1.11", + "bundled": true, + "dev": true + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true + }, + "jsonfile": { + "version": "2.4.0", + "bundled": true, + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "klaw": { + "version": "1.3.1", + "bundled": true, + "dev": true, + "requires": { + "graceful-fs": "^4.1.9" + } + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "rimraf": { + "version": "2.6.2", + "bundled": true, + "dev": true, + "requires": { + "glob": "^7.0.5" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true + } + } + }, + "fs.realpath": { + "version": "1.0.0", + "bundled": true + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "requires": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "github-from-package": { + "version": "0.0.0", + "bundled": true + }, + "glob": { + "version": "7.1.2", + "bundled": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "growl": { + "version": "1.10.5", + "bundled": true + }, + "has-flag": { + "version": "3.0.0", + "bundled": true + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true + }, + "he": { + "version": "1.1.1", + "bundled": true + }, + "inflight": { + "version": "1.0.6", + "bundled": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "bundled": true + }, + "ini": { + "version": "1.3.5", + "bundled": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "isarray": { + "version": "1.0.0", + "bundled": true + }, + "jsonschema": { + "version": "1.0.3", + "bundled": true + }, + "mimic-response": { + "version": "1.0.1", + "bundled": true + }, + "minimatch": { + "version": "3.0.4", + "bundled": true, + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "1.2.0", + "bundled": true + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "bundled": true + } + } + }, + "mocha": { + "version": "5.2.0", + "bundled": true, + "requires": { + "browser-stdout": "1.3.1", + "commander": "2.15.1", + "debug": "3.1.0", + "diff": "3.5.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.5", + "he": "1.1.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "supports-color": "5.4.0" + } + }, + "ms": { + "version": "2.0.0", + "bundled": true + }, + "nan": { + "version": "2.10.0", + "bundled": true, + "dev": true + }, + "node-abi": { + "version": "2.4.3", + "bundled": true, + "requires": { + "semver": "^5.4.1" + } + }, + "noop-logger": { + "version": "0.1.1", + "bundled": true + }, + "npmlog": { + "version": "4.1.2", + "bundled": true, + "requires": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "requires": { + "wrappy": "1" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true + }, + "path-is-absolute": { + "version": "1.0.1", + "bundled": true + }, + "prebuild-install": { + "version": "5.0.0", + "bundled": true, + "requires": { + "detect-libc": "^1.0.3", + "expand-template": "^1.0.2", + "github-from-package": "0.0.0", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "node-abi": "^2.2.0", + "noop-logger": "^0.1.1", + "npmlog": "^4.0.1", + "os-homedir": "^1.0.1", + "pump": "^2.0.1", + "rc": "^1.2.7", + "simple-get": "^2.7.0", + "tar-fs": "^1.13.0", + "tunnel-agent": "^0.6.0", + "which-pm-runs": "^1.0.0" + } + }, + "prettier": { + "version": "1.12.1", + "bundled": true, + "dev": true + }, + "process-nextick-args": { + "version": "2.0.0", + "bundled": true + }, + "pump": { + "version": "2.0.1", + "bundled": true, + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "rc": { + "version": "1.2.8", + "bundled": true, + "requires": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + } + }, + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "safe-buffer": { + "version": "5.1.2", + "bundled": true + }, + "semver": { + "version": "5.5.0", + "bundled": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true + }, + "simple-concat": { + "version": "1.0.0", + "bundled": true + }, + "simple-get": { + "version": "2.8.1", + "bundled": true, + "requires": { + "decompress-response": "^3.3.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, + "stackvis": { + "version": "0.3.0", + "bundled": true, + "requires": { + "manta": "1.5.1" + }, + "dependencies": { + "manta": { + "version": "1.5.1", + "bundled": true, + "requires": { + "tar": "0.1.18" + } + }, + "tar": { + "version": "0.1.18", + "bundled": true, + "requires": { + "block-stream": "*", + "inherits": "2" + } + } + } + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true + }, + "superstring": { + "version": "2.3.1", + "bundled": true, + "requires": { + "nan": "^2.10.0" + }, + "dependencies": { + "nan": { + "version": "2.10.0", + "bundled": true + } + } + }, + "supports-color": { + "version": "5.4.0", + "bundled": true, + "requires": { + "has-flag": "^3.0.0" + } + }, + "tar-fs": { + "version": "1.16.3", + "bundled": true, + "requires": { + "chownr": "^1.0.1", + "mkdirp": "^0.5.1", + "pump": "^1.0.0", + "tar-stream": "^1.1.2" + }, + "dependencies": { + "pump": { + "version": "1.0.3", + "bundled": true, + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + } + } + }, + "tar-stream": { + "version": "1.6.1", + "bundled": true, + "requires": { + "bl": "^1.0.0", + "buffer-alloc": "^1.1.0", + "end-of-stream": "^1.0.0", + "fs-constants": "^1.0.0", + "readable-stream": "^2.3.0", + "to-buffer": "^1.1.0", + "xtend": "^4.0.0" + } + }, + "temp": { + "version": "0.8.3", + "bundled": true, + "dev": true, + "requires": { + "os-tmpdir": "^1.0.0", + "rimraf": "~2.2.6" + }, + "dependencies": { + "os-tmpdir": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "rimraf": { + "version": "2.2.8", + "bundled": true, + "dev": true + } + } + }, + "to-buffer": { + "version": "1.1.1", + "bundled": true + }, + "tree-sitter": { + "version": "0.13.15", + "bundled": true, + "dev": true, + "requires": { + "nan": "^2.10.0", + "prebuild-install": "^5.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "2.1.1", + "bundled": true, + "dev": true + }, + "aproba": { + "version": "1.2.0", + "bundled": true, + "dev": true + }, + "are-we-there-yet": { + "version": "1.1.5", + "bundled": true, + "dev": true, + "requires": { + "delegates": "^1.0.0", + "readable-stream": "^2.0.6" + } + }, + "bl": { + "version": "1.2.2", + "bundled": true, + "dev": true, + "requires": { + "readable-stream": "^2.3.5", + "safe-buffer": "^5.1.1" + } + }, + "buffer-alloc": { + "version": "1.2.0", + "bundled": true, + "dev": true, + "requires": { + "buffer-alloc-unsafe": "^1.1.0", + "buffer-fill": "^1.0.0" + } + }, + "buffer-alloc-unsafe": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "buffer-fill": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "chownr": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "code-point-at": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "console-control-strings": { + "version": "1.1.0", + "bundled": true, + "dev": true + }, + "core-util-is": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "decompress-response": { + "version": "3.3.0", + "bundled": true, + "dev": true, + "requires": { + "mimic-response": "^1.0.0" + } + }, + "deep-extend": { + "version": "0.6.0", + "bundled": true, + "dev": true + }, + "delegates": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "detect-libc": { + "version": "1.0.3", + "bundled": true, + "dev": true + }, + "end-of-stream": { + "version": "1.4.1", + "bundled": true, + "dev": true, + "requires": { + "once": "^1.4.0" + } + }, + "expand-template": { + "version": "1.1.1", + "bundled": true, + "dev": true + }, + "fs-constants": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "gauge": { + "version": "2.7.4", + "bundled": true, + "dev": true, + "requires": { + "aproba": "^1.0.3", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.0", + "object-assign": "^4.1.0", + "signal-exit": "^3.0.0", + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wide-align": "^1.1.0" + } + }, + "github-from-package": { + "version": "0.0.0", + "bundled": true, + "dev": true + }, + "has-unicode": { + "version": "2.0.1", + "bundled": true, + "dev": true + }, + "inherits": { + "version": "2.0.3", + "bundled": true, + "dev": true + }, + "ini": { + "version": "1.3.5", + "bundled": true, + "dev": true + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "bundled": true, + "dev": true, + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "isarray": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "mimic-response": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "minimist": { + "version": "1.2.0", + "bundled": true, + "dev": true + }, + "mkdirp": { + "version": "0.5.1", + "bundled": true, + "dev": true, + "requires": { + "minimist": "0.0.8" + }, + "dependencies": { + "minimist": { + "version": "0.0.8", + "bundled": true, + "dev": true + } + } + }, + "nan": { + "version": "2.10.0", + "bundled": true, + "dev": true + }, + "napi-build-utils": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "node-abi": { + "version": "2.4.3", + "bundled": true, + "dev": true, + "requires": { + "semver": "^5.4.1" + } + }, + "noop-logger": { + "version": "0.1.1", + "bundled": true, + "dev": true + }, + "npmlog": { + "version": "4.1.2", + "bundled": true, + "dev": true, + "requires": { + "are-we-there-yet": "~1.1.2", + "console-control-strings": "~1.1.0", + "gauge": "~2.7.3", + "set-blocking": "~2.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "bundled": true, + "dev": true + }, + "object-assign": { + "version": "4.1.1", + "bundled": true, + "dev": true + }, + "once": { + "version": "1.4.0", + "bundled": true, + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "os-homedir": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "prebuild-install": { + "version": "5.2.0", + "bundled": true, + "dev": true, + "requires": { + "detect-libc": "^1.0.3", + "expand-template": "^1.0.2", + "github-from-package": "0.0.0", + "minimist": "^1.2.0", + "mkdirp": "^0.5.1", + "napi-build-utils": "^1.0.1", + "node-abi": "^2.2.0", + "noop-logger": "^0.1.1", + "npmlog": "^4.0.1", + "os-homedir": "^1.0.1", + "pump": "^2.0.1", + "rc": "^1.2.7", + "simple-get": "^2.7.0", + "tar-fs": "^1.13.0", + "tunnel-agent": "^0.6.0", + "which-pm-runs": "^1.0.0" + } + }, + "process-nextick-args": { + "version": "2.0.0", + "bundled": true, + "dev": true + }, + "pump": { + "version": "2.0.1", + "bundled": true, + "dev": true, + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "rc": { + "version": "1.2.8", + "bundled": true, + "dev": true, + "requires": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + } + }, + "readable-stream": { + "version": "2.3.6", + "bundled": true, + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "safe-buffer": { + "version": "5.1.2", + "bundled": true, + "dev": true + }, + "semver": { + "version": "5.5.0", + "bundled": true, + "dev": true + }, + "set-blocking": { + "version": "2.0.0", + "bundled": true, + "dev": true + }, + "signal-exit": { + "version": "3.0.2", + "bundled": true, + "dev": true + }, + "simple-concat": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "simple-get": { + "version": "2.8.1", + "bundled": true, + "dev": true, + "requires": { + "decompress-response": "^3.3.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, + "string-width": { + "version": "1.0.2", + "bundled": true, + "dev": true, + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "string_decoder": { + "version": "1.1.1", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "bundled": true, + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-json-comments": { + "version": "2.0.1", + "bundled": true, + "dev": true + }, + "tar-fs": { + "version": "1.16.3", + "bundled": true, + "dev": true, + "requires": { + "chownr": "^1.0.1", + "mkdirp": "^0.5.1", + "pump": "^1.0.0", + "tar-stream": "^1.1.2" + }, + "dependencies": { + "pump": { + "version": "1.0.3", + "bundled": true, + "dev": true, + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + } + } + }, + "tar-stream": { + "version": "1.6.1", + "bundled": true, + "dev": true, + "requires": { + "bl": "^1.0.0", + "buffer-alloc": "^1.1.0", + "end-of-stream": "^1.0.0", + "fs-constants": "^1.0.0", + "readable-stream": "^2.3.0", + "to-buffer": "^1.1.0", + "xtend": "^4.0.0" + } + }, + "to-buffer": { + "version": "1.1.1", + "bundled": true, + "dev": true + }, + "tunnel-agent": { + "version": "0.6.0", + "bundled": true, + "dev": true, + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "which-pm-runs": { + "version": "1.0.0", + "bundled": true, + "dev": true + }, + "wide-align": { + "version": "1.1.3", + "bundled": true, + "dev": true, + "requires": { + "string-width": "^1.0.2 || 2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true, + "dev": true + }, + "xtend": { + "version": "4.0.1", + "bundled": true, + "dev": true + } + } + }, + "tunnel-agent": { + "version": "0.6.0", + "bundled": true, + "requires": { + "safe-buffer": "^5.0.1" + } + }, + "util-deprecate": { + "version": "1.0.2", + "bundled": true + }, + "vows": { + "version": "0.7.0", + "bundled": true, + "dev": true, + "requires": { + "diff": "~1.0.3", + "eyes": ">=0.1.6" + }, + "dependencies": { + "diff": { + "version": "1.0.8", + "bundled": true, + "dev": true + }, + "eyes": { + "version": "0.1.8", + "bundled": true, + "dev": true + } + } + }, + "which-pm-runs": { + "version": "1.0.0", + "bundled": true + }, + "wide-align": { + "version": "1.1.3", + "bundled": true, + "requires": { + "string-width": "^1.0.2 || 2" + } + }, + "wrappy": { + "version": "1.0.2", + "bundled": true + }, + "xtend": { + "version": "4.0.1", + "bundled": true + } + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..13531d2 --- /dev/null +++ b/package.json @@ -0,0 +1,21 @@ +{ + "name": "tree-sitter-css", + "version": "0.0.1", + "description": "CSS grammar for tree-sitter", + "main": "index.js", + "keywords": [ + "parser", + "lexer" + ], + "author": "Max Brunsfeld", + "license": "MIT", + "dependencies": { + "nan": "^2.11.1" + }, + "devDependencies": { + "tree-sitter-cli": "^0.13.5" + }, + "scripts": { + "test": "tree-sitter test" + } +} diff --git a/src/binding.cc b/src/binding.cc new file mode 100644 index 0000000..0d6f618 --- /dev/null +++ b/src/binding.cc @@ -0,0 +1,28 @@ +#include "tree_sitter/parser.h" +#include +#include "nan.h" + +using namespace v8; + +extern "C" TSLanguage * tree_sitter_css(); + +namespace { + +NAN_METHOD(New) {} + +void Init(Handle exports, Handle module) { + Local tpl = Nan::New(New); + tpl->SetClassName(Nan::New("Language").ToLocalChecked()); + tpl->InstanceTemplate()->SetInternalFieldCount(1); + + Local constructor = tpl->GetFunction(); + Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); + Nan::SetInternalFieldPointer(instance, 0, tree_sitter_css()); + + instance->Set(Nan::New("name").ToLocalChecked(), Nan::New("css").ToLocalChecked()); + module->Set(Nan::New("exports").ToLocalChecked(), instance); +} + +NODE_MODULE(tree_sitter_css_binding, Init) + +} // namespace diff --git a/src/grammar.json b/src/grammar.json new file mode 100644 index 0000000..a290f10 --- /dev/null +++ b/src/grammar.json @@ -0,0 +1,361 @@ +{ + "name": "css", + "rules": { + "stylesheet": { + "type": "REPEAT", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "rule_set" + }, + { + "type": "SYMBOL", + "name": "import_statement" + } + ] + } + }, + "import_statement": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "@import" + } + ] + }, + "rule_set": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "selectors" + }, + { + "type": "SYMBOL", + "name": "block" + } + ] + }, + "selectors": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "_selector" + }, + { + "type": "REPEAT", + "content": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "," + }, + { + "type": "SYMBOL", + "name": "_selector" + } + ] + } + } + ] + }, + "block": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "{" + }, + { + "type": "REPEAT", + "content": { + "type": "SYMBOL", + "name": "declaration" + } + }, + { + "type": "STRING", + "value": "}" + } + ] + }, + "_selector": { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "universal_selector" + }, + { + "type": "SYMBOL", + "name": "type_selector" + }, + { + "type": "SYMBOL", + "name": "class_selector" + }, + { + "type": "SYMBOL", + "name": "id_selector" + }, + { + "type": "SYMBOL", + "name": "attribute_selector" + }, + { + "type": "SYMBOL", + "name": "child_selector" + }, + { + "type": "SYMBOL", + "name": "descendant_selector" + } + ] + }, + "universal_selector": { + "type": "STRING", + "value": "*" + }, + "type_selector": { + "type": "SYMBOL", + "name": "identifier" + }, + "class_selector": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "." + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + }, + "id_selector": { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "#" + }, + { + "type": "SYMBOL", + "name": "identifier" + } + ] + }, + "attribute_selector": { + "type": "SEQ", + "members": [ + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "[" + }, + { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "_selector" + }, + { + "type": "IMMEDIATE_TOKEN", + "content": { + "type": "STRING", + "value": "[" + } + } + ] + } + ] + }, + { + "type": "SYMBOL", + "name": "property_name" + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "=" + }, + { + "type": "STRING", + "value": "~=" + }, + { + "type": "STRING", + "value": "^=" + }, + { + "type": "STRING", + "value": "|=" + }, + { + "type": "STRING", + "value": "*=" + }, + { + "type": "STRING", + "value": "$=" + } + ] + }, + { + "type": "SYMBOL", + "name": "property_value" + } + ] + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "STRING", + "value": "]" + } + ] + }, + "child_selector": { + "type": "PREC_LEFT", + "value": 0, + "content": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "_selector" + }, + { + "type": "STRING", + "value": ">" + }, + { + "type": "SYMBOL", + "name": "_selector" + } + ] + } + }, + "descendant_selector": { + "type": "PREC_LEFT", + "value": 0, + "content": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "_selector" + }, + { + "type": "SYMBOL", + "name": "_selector" + } + ] + } + }, + "declaration": { + "type": "SEQ", + "members": [ + { + "type": "SYMBOL", + "name": "property_name" + }, + { + "type": "STRING", + "value": ":" + }, + { + "type": "SYMBOL", + "name": "property_value" + }, + { + "type": "STRING", + "value": ";" + } + ] + }, + "property_name": { + "type": "SYMBOL", + "name": "identifier" + }, + "identifier": { + "type": "PATTERN", + "value": "[a-zA-Z-_]+" + }, + "property_value": { + "type": "PATTERN", + "value": "[^;()\\[\\]]+" + }, + "comment": { + "type": "TOKEN", + "content": { + "type": "CHOICE", + "members": [ + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "//" + }, + { + "type": "PATTERN", + "value": ".*" + } + ] + }, + { + "type": "SEQ", + "members": [ + { + "type": "STRING", + "value": "/*" + }, + { + "type": "PATTERN", + "value": "[^*]*\\*+([^\\/*][^*]*\\*+)*" + }, + { + "type": "STRING", + "value": "/" + } + ] + } + ] + } + } + }, + "extras": [ + { + "type": "PATTERN", + "value": "\\s" + }, + { + "type": "SYMBOL", + "name": "comment" + } + ], + "conflicts": [], + "externals": [], + "inline": [] +} \ No newline at end of file diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..78d6e96 --- /dev/null +++ b/src/parser.c @@ -0,0 +1,1367 @@ +#include + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif + +#define LANGUAGE_VERSION 9 +#define STATE_COUNT 42 +#define SYMBOL_COUNT 39 +#define ALIAS_COUNT 0 +#define TOKEN_COUNT 23 +#define EXTERNAL_TOKEN_COUNT 0 +#define MAX_ALIAS_SEQUENCE_LENGTH 0 + +enum { + sym_import_statement = 1, + anon_sym_COMMA = 2, + anon_sym_LBRACE = 3, + anon_sym_RBRACE = 4, + sym_universal_selector = 5, + anon_sym_DOT = 6, + anon_sym_POUND = 7, + anon_sym_LBRACK = 8, + anon_sym_LBRACK2 = 9, + anon_sym_EQ = 10, + anon_sym_TILDE_EQ = 11, + anon_sym_CARET_EQ = 12, + anon_sym_PIPE_EQ = 13, + anon_sym_STAR_EQ = 14, + anon_sym_DOLLAR_EQ = 15, + anon_sym_RBRACK = 16, + anon_sym_GT = 17, + anon_sym_COLON = 18, + anon_sym_SEMI = 19, + sym_identifier = 20, + sym_property_value = 21, + sym_comment = 22, + sym_stylesheet = 23, + sym_rule_set = 24, + sym_selectors = 25, + sym_block = 26, + sym__selector = 27, + sym_type_selector = 28, + sym_class_selector = 29, + sym_id_selector = 30, + sym_attribute_selector = 31, + sym_child_selector = 32, + sym_descendant_selector = 33, + sym_declaration = 34, + sym_property_name = 35, + aux_sym_stylesheet_repeat1 = 36, + aux_sym_selectors_repeat1 = 37, + aux_sym_block_repeat1 = 38, +}; + +static const char *ts_symbol_names[] = { + [ts_builtin_sym_end] = "END", + [sym_import_statement] = "import_statement", + [anon_sym_COMMA] = ",", + [anon_sym_LBRACE] = "{", + [anon_sym_RBRACE] = "}", + [sym_universal_selector] = "universal_selector", + [anon_sym_DOT] = ".", + [anon_sym_POUND] = "#", + [anon_sym_LBRACK] = "[", + [anon_sym_LBRACK2] = "[", + [anon_sym_EQ] = "=", + [anon_sym_TILDE_EQ] = "~=", + [anon_sym_CARET_EQ] = "^=", + [anon_sym_PIPE_EQ] = "|=", + [anon_sym_STAR_EQ] = "*=", + [anon_sym_DOLLAR_EQ] = "$=", + [anon_sym_RBRACK] = "]", + [anon_sym_GT] = ">", + [anon_sym_COLON] = ":", + [anon_sym_SEMI] = ";", + [sym_identifier] = "identifier", + [sym_property_value] = "property_value", + [sym_comment] = "comment", + [sym_stylesheet] = "stylesheet", + [sym_rule_set] = "rule_set", + [sym_selectors] = "selectors", + [sym_block] = "block", + [sym__selector] = "_selector", + [sym_type_selector] = "type_selector", + [sym_class_selector] = "class_selector", + [sym_id_selector] = "id_selector", + [sym_attribute_selector] = "attribute_selector", + [sym_child_selector] = "child_selector", + [sym_descendant_selector] = "descendant_selector", + [sym_declaration] = "declaration", + [sym_property_name] = "property_name", + [aux_sym_stylesheet_repeat1] = "stylesheet_repeat1", + [aux_sym_selectors_repeat1] = "selectors_repeat1", + [aux_sym_block_repeat1] = "block_repeat1", +}; + +static const TSSymbolMetadata ts_symbol_metadata[] = { + [ts_builtin_sym_end] = { + .visible = false, + .named = true, + }, + [sym_import_statement] = { + .visible = true, + .named = true, + }, + [anon_sym_COMMA] = { + .visible = true, + .named = false, + }, + [anon_sym_LBRACE] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACE] = { + .visible = true, + .named = false, + }, + [sym_universal_selector] = { + .visible = true, + .named = true, + }, + [anon_sym_DOT] = { + .visible = true, + .named = false, + }, + [anon_sym_POUND] = { + .visible = true, + .named = false, + }, + [anon_sym_LBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_LBRACK2] = { + .visible = true, + .named = false, + }, + [anon_sym_EQ] = { + .visible = true, + .named = false, + }, + [anon_sym_TILDE_EQ] = { + .visible = true, + .named = false, + }, + [anon_sym_CARET_EQ] = { + .visible = true, + .named = false, + }, + [anon_sym_PIPE_EQ] = { + .visible = true, + .named = false, + }, + [anon_sym_STAR_EQ] = { + .visible = true, + .named = false, + }, + [anon_sym_DOLLAR_EQ] = { + .visible = true, + .named = false, + }, + [anon_sym_RBRACK] = { + .visible = true, + .named = false, + }, + [anon_sym_GT] = { + .visible = true, + .named = false, + }, + [anon_sym_COLON] = { + .visible = true, + .named = false, + }, + [anon_sym_SEMI] = { + .visible = true, + .named = false, + }, + [sym_identifier] = { + .visible = true, + .named = true, + }, + [sym_property_value] = { + .visible = true, + .named = true, + }, + [sym_comment] = { + .visible = true, + .named = true, + }, + [sym_stylesheet] = { + .visible = true, + .named = true, + }, + [sym_rule_set] = { + .visible = true, + .named = true, + }, + [sym_selectors] = { + .visible = true, + .named = true, + }, + [sym_block] = { + .visible = true, + .named = true, + }, + [sym__selector] = { + .visible = false, + .named = true, + }, + [sym_type_selector] = { + .visible = true, + .named = true, + }, + [sym_class_selector] = { + .visible = true, + .named = true, + }, + [sym_id_selector] = { + .visible = true, + .named = true, + }, + [sym_attribute_selector] = { + .visible = true, + .named = true, + }, + [sym_child_selector] = { + .visible = true, + .named = true, + }, + [sym_descendant_selector] = { + .visible = true, + .named = true, + }, + [sym_declaration] = { + .visible = true, + .named = true, + }, + [sym_property_name] = { + .visible = true, + .named = true, + }, + [aux_sym_stylesheet_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_selectors_repeat1] = { + .visible = false, + .named = false, + }, + [aux_sym_block_repeat1] = { + .visible = false, + .named = false, + }, +}; + +static bool ts_lex(TSLexer *lexer, TSStateId state) { + START_LEXER(); + switch (state) { + case 0: + if (lookahead == 0) + ADVANCE(1); + if (lookahead == '#') + ADVANCE(2); + if (lookahead == '$') + ADVANCE(3); + if (lookahead == '*') + ADVANCE(5); + if (lookahead == ',') + ADVANCE(7); + if (lookahead == '.') + ADVANCE(8); + if (lookahead == '/') + ADVANCE(9); + if (lookahead == ':') + ADVANCE(14); + if (lookahead == ';') + ADVANCE(15); + if (lookahead == '=') + ADVANCE(16); + if (lookahead == '>') + ADVANCE(17); + if (lookahead == '@') + ADVANCE(18); + if (lookahead == '[') + ADVANCE(25); + if (lookahead == ']') + ADVANCE(26); + if (lookahead == '^') + ADVANCE(27); + if (lookahead == '{') + ADVANCE(29); + if (lookahead == '|') + ADVANCE(30); + if (lookahead == '}') + ADVANCE(32); + if (lookahead == '~') + ADVANCE(33); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(35); + if (lookahead == '-' || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) + ADVANCE(37); + END_STATE(); + case 1: + ACCEPT_TOKEN(ts_builtin_sym_end); + END_STATE(); + case 2: + ACCEPT_TOKEN(anon_sym_POUND); + END_STATE(); + case 3: + if (lookahead == '=') + ADVANCE(4); + END_STATE(); + case 4: + ACCEPT_TOKEN(anon_sym_DOLLAR_EQ); + END_STATE(); + case 5: + ACCEPT_TOKEN(sym_universal_selector); + if (lookahead == '=') + ADVANCE(6); + END_STATE(); + case 6: + ACCEPT_TOKEN(anon_sym_STAR_EQ); + END_STATE(); + case 7: + ACCEPT_TOKEN(anon_sym_COMMA); + END_STATE(); + case 8: + ACCEPT_TOKEN(anon_sym_DOT); + END_STATE(); + case 9: + if (lookahead == '*') + ADVANCE(10); + if (lookahead == '/') + ADVANCE(13); + END_STATE(); + case 10: + if (lookahead == '*') + ADVANCE(11); + if (lookahead != 0) + ADVANCE(10); + END_STATE(); + case 11: + if (lookahead == '*') + ADVANCE(11); + if (lookahead == '/') + ADVANCE(12); + if (lookahead != 0) + ADVANCE(10); + END_STATE(); + case 12: + ACCEPT_TOKEN(sym_comment); + END_STATE(); + case 13: + ACCEPT_TOKEN(sym_comment); + if (lookahead != 0 && + lookahead != '\n') + ADVANCE(13); + END_STATE(); + case 14: + ACCEPT_TOKEN(anon_sym_COLON); + END_STATE(); + case 15: + ACCEPT_TOKEN(anon_sym_SEMI); + END_STATE(); + case 16: + ACCEPT_TOKEN(anon_sym_EQ); + END_STATE(); + case 17: + ACCEPT_TOKEN(anon_sym_GT); + END_STATE(); + case 18: + if (lookahead == 'i') + ADVANCE(19); + END_STATE(); + case 19: + if (lookahead == 'm') + ADVANCE(20); + END_STATE(); + case 20: + if (lookahead == 'p') + ADVANCE(21); + END_STATE(); + case 21: + if (lookahead == 'o') + ADVANCE(22); + END_STATE(); + case 22: + if (lookahead == 'r') + ADVANCE(23); + END_STATE(); + case 23: + if (lookahead == 't') + ADVANCE(24); + END_STATE(); + case 24: + ACCEPT_TOKEN(sym_import_statement); + END_STATE(); + case 25: + ACCEPT_TOKEN(anon_sym_LBRACK2); + END_STATE(); + case 26: + ACCEPT_TOKEN(anon_sym_RBRACK); + END_STATE(); + case 27: + if (lookahead == '=') + ADVANCE(28); + END_STATE(); + case 28: + ACCEPT_TOKEN(anon_sym_CARET_EQ); + END_STATE(); + case 29: + ACCEPT_TOKEN(anon_sym_LBRACE); + END_STATE(); + case 30: + if (lookahead == '=') + ADVANCE(31); + END_STATE(); + case 31: + ACCEPT_TOKEN(anon_sym_PIPE_EQ); + END_STATE(); + case 32: + ACCEPT_TOKEN(anon_sym_RBRACE); + END_STATE(); + case 33: + if (lookahead == '=') + ADVANCE(34); + END_STATE(); + case 34: + ACCEPT_TOKEN(anon_sym_TILDE_EQ); + END_STATE(); + case 35: + if (lookahead == 0) + ADVANCE(1); + if (lookahead == '#') + ADVANCE(2); + if (lookahead == '$') + ADVANCE(3); + if (lookahead == '*') + ADVANCE(5); + if (lookahead == ',') + ADVANCE(7); + if (lookahead == '.') + ADVANCE(8); + if (lookahead == '/') + ADVANCE(9); + if (lookahead == ':') + ADVANCE(14); + if (lookahead == ';') + ADVANCE(15); + if (lookahead == '=') + ADVANCE(16); + if (lookahead == '>') + ADVANCE(17); + if (lookahead == '@') + ADVANCE(18); + if (lookahead == '[') + ADVANCE(36); + if (lookahead == ']') + ADVANCE(26); + if (lookahead == '^') + ADVANCE(27); + if (lookahead == '{') + ADVANCE(29); + if (lookahead == '|') + ADVANCE(30); + if (lookahead == '}') + ADVANCE(32); + if (lookahead == '~') + ADVANCE(33); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(35); + if (lookahead == '-' || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) + ADVANCE(37); + END_STATE(); + case 36: + ACCEPT_TOKEN(anon_sym_LBRACK); + END_STATE(); + case 37: + ACCEPT_TOKEN(sym_identifier); + if (lookahead == '-' || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) + ADVANCE(37); + END_STATE(); + case 38: + if (lookahead == 0) + ADVANCE(1); + if (lookahead == '#') + ADVANCE(2); + if (lookahead == '*') + ADVANCE(39); + if (lookahead == '.') + ADVANCE(8); + if (lookahead == '/') + ADVANCE(9); + if (lookahead == '@') + ADVANCE(18); + if (lookahead == '[') + ADVANCE(36); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(38); + if (lookahead == '-' || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) + ADVANCE(37); + END_STATE(); + case 39: + ACCEPT_TOKEN(sym_universal_selector); + END_STATE(); + case 40: + if (lookahead == '#') + ADVANCE(2); + if (lookahead == '*') + ADVANCE(39); + if (lookahead == ',') + ADVANCE(7); + if (lookahead == '.') + ADVANCE(8); + if (lookahead == '/') + ADVANCE(9); + if (lookahead == '>') + ADVANCE(17); + if (lookahead == '[') + ADVANCE(25); + if (lookahead == '{') + ADVANCE(29); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(41); + if (lookahead == '-' || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) + ADVANCE(37); + END_STATE(); + case 41: + if (lookahead == '#') + ADVANCE(2); + if (lookahead == '*') + ADVANCE(39); + if (lookahead == ',') + ADVANCE(7); + if (lookahead == '.') + ADVANCE(8); + if (lookahead == '/') + ADVANCE(9); + if (lookahead == '>') + ADVANCE(17); + if (lookahead == '[') + ADVANCE(36); + if (lookahead == '{') + ADVANCE(29); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(41); + if (lookahead == '-' || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) + ADVANCE(37); + END_STATE(); + case 42: + if (lookahead == 0) + ADVANCE(1); + if (lookahead == '/') + ADVANCE(9); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(42); + END_STATE(); + case 43: + if (lookahead == '$') + ADVANCE(3); + if (lookahead == '*') + ADVANCE(44); + if (lookahead == '/') + ADVANCE(9); + if (lookahead == ':') + ADVANCE(14); + if (lookahead == '=') + ADVANCE(16); + if (lookahead == ']') + ADVANCE(26); + if (lookahead == '^') + ADVANCE(27); + if (lookahead == '|') + ADVANCE(30); + if (lookahead == '~') + ADVANCE(33); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(43); + END_STATE(); + case 44: + if (lookahead == '=') + ADVANCE(6); + END_STATE(); + case 45: + if (lookahead == '$') + ADVANCE(3); + if (lookahead == '*') + ADVANCE(44); + if (lookahead == '/') + ADVANCE(9); + if (lookahead == '=') + ADVANCE(16); + if (lookahead == ']') + ADVANCE(26); + if (lookahead == '^') + ADVANCE(27); + if (lookahead == '|') + ADVANCE(30); + if (lookahead == '~') + ADVANCE(33); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(45); + END_STATE(); + case 46: + if (lookahead == '/') + ADVANCE(9); + if (lookahead == '}') + ADVANCE(32); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(46); + if (lookahead == '-' || + ('A' <= lookahead && lookahead <= 'Z') || + lookahead == '_' || + ('a' <= lookahead && lookahead <= 'z')) + ADVANCE(37); + END_STATE(); + case 47: + if (lookahead == '/') + ADVANCE(48); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + ADVANCE(53); + if (lookahead != 0 && + lookahead != '(' && + lookahead != ')' && + lookahead != ';' && + lookahead != '[' && + lookahead != ']') + ADVANCE(51); + END_STATE(); + case 48: + ACCEPT_TOKEN(sym_property_value); + if (lookahead == '*') + ADVANCE(49); + if (lookahead == '/') + ADVANCE(52); + if (lookahead != 0 && + (lookahead < '(' || lookahead > '*') && + lookahead != ';' && + lookahead != '[' && + lookahead != ']') + ADVANCE(51); + END_STATE(); + case 49: + ACCEPT_TOKEN(sym_property_value); + if (lookahead == '*') + ADVANCE(50); + if (lookahead == '(' || + lookahead == ')' || + lookahead == ';' || + lookahead == '[' || + lookahead == ']') + ADVANCE(10); + if (lookahead != 0) + ADVANCE(49); + END_STATE(); + case 50: + ACCEPT_TOKEN(sym_property_value); + if (lookahead == '*') + ADVANCE(50); + if (lookahead == '/') + ADVANCE(51); + if (lookahead == '(' || + lookahead == ')' || + lookahead == ';' || + lookahead == '[' || + lookahead == ']') + ADVANCE(10); + if (lookahead != 0) + ADVANCE(49); + END_STATE(); + case 51: + ACCEPT_TOKEN(sym_property_value); + if (lookahead != 0 && + lookahead != '(' && + lookahead != ')' && + lookahead != ';' && + lookahead != '[' && + lookahead != ']') + ADVANCE(51); + END_STATE(); + case 52: + ACCEPT_TOKEN(sym_property_value); + if (lookahead == '\n') + ADVANCE(51); + if (lookahead == '(' || + lookahead == ')' || + lookahead == ';' || + lookahead == '[' || + lookahead == ']') + ADVANCE(13); + if (lookahead != 0) + ADVANCE(52); + END_STATE(); + case 53: + ACCEPT_TOKEN(sym_property_value); + if (lookahead == '/') + ADVANCE(48); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + ADVANCE(53); + if (lookahead != 0 && + lookahead != '(' && + lookahead != ')' && + lookahead != ';' && + lookahead != '[' && + lookahead != ']') + ADVANCE(51); + END_STATE(); + case 54: + if (lookahead == '/') + ADVANCE(9); + if (lookahead == ':') + ADVANCE(14); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(54); + END_STATE(); + case 55: + if (lookahead == '/') + ADVANCE(9); + if (lookahead == ';') + ADVANCE(15); + if (lookahead == '\t' || + lookahead == '\n' || + lookahead == '\r' || + lookahead == ' ') + SKIP(55); + END_STATE(); + default: + return false; + } +} + +static TSLexMode ts_lex_modes[STATE_COUNT] = { + [0] = {.lex_state = 0}, + [1] = {.lex_state = 38}, + [2] = {.lex_state = 38}, + [3] = {.lex_state = 38}, + [4] = {.lex_state = 38}, + [5] = {.lex_state = 40}, + [6] = {.lex_state = 42}, + [7] = {.lex_state = 40}, + [8] = {.lex_state = 40}, + [9] = {.lex_state = 38}, + [10] = {.lex_state = 40}, + [11] = {.lex_state = 40}, + [12] = {.lex_state = 43}, + [13] = {.lex_state = 45}, + [14] = {.lex_state = 46}, + [15] = {.lex_state = 38}, + [16] = {.lex_state = 38}, + [17] = {.lex_state = 38}, + [18] = {.lex_state = 38}, + [19] = {.lex_state = 40}, + [20] = {.lex_state = 40}, + [21] = {.lex_state = 38}, + [22] = {.lex_state = 47}, + [23] = {.lex_state = 40}, + [24] = {.lex_state = 38}, + [25] = {.lex_state = 54}, + [26] = {.lex_state = 46}, + [27] = {.lex_state = 40}, + [28] = {.lex_state = 45}, + [29] = {.lex_state = 40}, + [30] = {.lex_state = 40}, + [31] = {.lex_state = 45}, + [32] = {.lex_state = 47}, + [33] = {.lex_state = 38}, + [34] = {.lex_state = 46}, + [35] = {.lex_state = 47}, + [36] = {.lex_state = 40}, + [37] = {.lex_state = 40}, + [38] = {.lex_state = 55}, + [39] = {.lex_state = 45}, + [40] = {.lex_state = 46}, + [41] = {.lex_state = 40}, +}; + +static uint16_t ts_parse_table[STATE_COUNT][SYMBOL_COUNT] = { + [0] = { + [ts_builtin_sym_end] = ACTIONS(1), + [sym_import_statement] = ACTIONS(1), + [anon_sym_COMMA] = ACTIONS(1), + [anon_sym_LBRACE] = ACTIONS(1), + [anon_sym_RBRACE] = ACTIONS(1), + [sym_universal_selector] = ACTIONS(3), + [anon_sym_DOT] = ACTIONS(1), + [anon_sym_POUND] = ACTIONS(1), + [anon_sym_LBRACK] = ACTIONS(3), + [anon_sym_LBRACK2] = ACTIONS(1), + [anon_sym_EQ] = ACTIONS(1), + [anon_sym_TILDE_EQ] = ACTIONS(1), + [anon_sym_CARET_EQ] = ACTIONS(1), + [anon_sym_PIPE_EQ] = ACTIONS(1), + [anon_sym_STAR_EQ] = ACTIONS(1), + [anon_sym_DOLLAR_EQ] = ACTIONS(1), + [anon_sym_RBRACK] = ACTIONS(1), + [anon_sym_GT] = ACTIONS(1), + [anon_sym_COLON] = ACTIONS(1), + [anon_sym_SEMI] = ACTIONS(1), + [sym_identifier] = ACTIONS(1), + [sym_comment] = ACTIONS(1), + }, + [1] = { + [sym_stylesheet] = STATE(6), + [sym_rule_set] = STATE(9), + [sym_selectors] = STATE(7), + [sym__selector] = STATE(8), + [sym_type_selector] = STATE(8), + [sym_class_selector] = STATE(8), + [sym_id_selector] = STATE(8), + [sym_attribute_selector] = STATE(8), + [sym_child_selector] = STATE(8), + [sym_descendant_selector] = STATE(8), + [aux_sym_stylesheet_repeat1] = STATE(9), + [ts_builtin_sym_end] = ACTIONS(5), + [sym_import_statement] = ACTIONS(7), + [sym_universal_selector] = ACTIONS(9), + [anon_sym_DOT] = ACTIONS(11), + [anon_sym_POUND] = ACTIONS(13), + [anon_sym_LBRACK] = ACTIONS(15), + [sym_identifier] = ACTIONS(17), + [sym_comment] = ACTIONS(19), + }, + [2] = { + [sym_identifier] = ACTIONS(21), + [sym_comment] = ACTIONS(19), + }, + [3] = { + [sym_identifier] = ACTIONS(23), + [sym_comment] = ACTIONS(19), + }, + [4] = { + [sym_property_name] = STATE(13), + [sym_identifier] = ACTIONS(25), + [sym_comment] = ACTIONS(19), + }, + [5] = { + [anon_sym_COMMA] = ACTIONS(27), + [anon_sym_LBRACE] = ACTIONS(27), + [sym_universal_selector] = ACTIONS(27), + [anon_sym_DOT] = ACTIONS(27), + [anon_sym_POUND] = ACTIONS(27), + [anon_sym_LBRACK] = ACTIONS(29), + [anon_sym_LBRACK2] = ACTIONS(27), + [anon_sym_GT] = ACTIONS(27), + [sym_identifier] = ACTIONS(27), + [sym_comment] = ACTIONS(19), + }, + [6] = { + [ts_builtin_sym_end] = ACTIONS(31), + [sym_comment] = ACTIONS(19), + }, + [7] = { + [sym_block] = STATE(15), + [anon_sym_LBRACE] = ACTIONS(33), + [sym_comment] = ACTIONS(19), + }, + [8] = { + [sym__selector] = STATE(19), + [sym_type_selector] = STATE(19), + [sym_class_selector] = STATE(19), + [sym_id_selector] = STATE(19), + [sym_attribute_selector] = STATE(19), + [sym_child_selector] = STATE(19), + [sym_descendant_selector] = STATE(19), + [aux_sym_selectors_repeat1] = STATE(20), + [anon_sym_COMMA] = ACTIONS(35), + [anon_sym_LBRACE] = ACTIONS(37), + [sym_universal_selector] = ACTIONS(39), + [anon_sym_DOT] = ACTIONS(11), + [anon_sym_POUND] = ACTIONS(13), + [anon_sym_LBRACK] = ACTIONS(41), + [anon_sym_LBRACK2] = ACTIONS(43), + [anon_sym_GT] = ACTIONS(45), + [sym_identifier] = ACTIONS(17), + [sym_comment] = ACTIONS(19), + }, + [9] = { + [sym_rule_set] = STATE(21), + [sym_selectors] = STATE(7), + [sym__selector] = STATE(8), + [sym_type_selector] = STATE(8), + [sym_class_selector] = STATE(8), + [sym_id_selector] = STATE(8), + [sym_attribute_selector] = STATE(8), + [sym_child_selector] = STATE(8), + [sym_descendant_selector] = STATE(8), + [aux_sym_stylesheet_repeat1] = STATE(21), + [ts_builtin_sym_end] = ACTIONS(47), + [sym_import_statement] = ACTIONS(49), + [sym_universal_selector] = ACTIONS(9), + [anon_sym_DOT] = ACTIONS(11), + [anon_sym_POUND] = ACTIONS(13), + [anon_sym_LBRACK] = ACTIONS(15), + [sym_identifier] = ACTIONS(17), + [sym_comment] = ACTIONS(19), + }, + [10] = { + [anon_sym_COMMA] = ACTIONS(51), + [anon_sym_LBRACE] = ACTIONS(51), + [sym_universal_selector] = ACTIONS(51), + [anon_sym_DOT] = ACTIONS(51), + [anon_sym_POUND] = ACTIONS(51), + [anon_sym_LBRACK] = ACTIONS(53), + [anon_sym_LBRACK2] = ACTIONS(51), + [anon_sym_GT] = ACTIONS(51), + [sym_identifier] = ACTIONS(51), + [sym_comment] = ACTIONS(19), + }, + [11] = { + [anon_sym_COMMA] = ACTIONS(55), + [anon_sym_LBRACE] = ACTIONS(55), + [sym_universal_selector] = ACTIONS(55), + [anon_sym_DOT] = ACTIONS(55), + [anon_sym_POUND] = ACTIONS(55), + [anon_sym_LBRACK] = ACTIONS(57), + [anon_sym_LBRACK2] = ACTIONS(55), + [anon_sym_GT] = ACTIONS(55), + [sym_identifier] = ACTIONS(55), + [sym_comment] = ACTIONS(19), + }, + [12] = { + [anon_sym_EQ] = ACTIONS(59), + [anon_sym_TILDE_EQ] = ACTIONS(59), + [anon_sym_CARET_EQ] = ACTIONS(59), + [anon_sym_PIPE_EQ] = ACTIONS(59), + [anon_sym_STAR_EQ] = ACTIONS(59), + [anon_sym_DOLLAR_EQ] = ACTIONS(59), + [anon_sym_RBRACK] = ACTIONS(59), + [anon_sym_COLON] = ACTIONS(59), + [sym_comment] = ACTIONS(19), + }, + [13] = { + [anon_sym_EQ] = ACTIONS(61), + [anon_sym_TILDE_EQ] = ACTIONS(61), + [anon_sym_CARET_EQ] = ACTIONS(61), + [anon_sym_PIPE_EQ] = ACTIONS(61), + [anon_sym_STAR_EQ] = ACTIONS(61), + [anon_sym_DOLLAR_EQ] = ACTIONS(61), + [anon_sym_RBRACK] = ACTIONS(63), + [sym_comment] = ACTIONS(19), + }, + [14] = { + [sym_declaration] = STATE(26), + [sym_property_name] = STATE(25), + [aux_sym_block_repeat1] = STATE(26), + [anon_sym_RBRACE] = ACTIONS(65), + [sym_identifier] = ACTIONS(25), + [sym_comment] = ACTIONS(19), + }, + [15] = { + [ts_builtin_sym_end] = ACTIONS(67), + [sym_import_statement] = ACTIONS(67), + [sym_universal_selector] = ACTIONS(67), + [anon_sym_DOT] = ACTIONS(67), + [anon_sym_POUND] = ACTIONS(67), + [anon_sym_LBRACK] = ACTIONS(67), + [sym_identifier] = ACTIONS(67), + [sym_comment] = ACTIONS(19), + }, + [16] = { + [sym__selector] = STATE(27), + [sym_type_selector] = STATE(27), + [sym_class_selector] = STATE(27), + [sym_id_selector] = STATE(27), + [sym_attribute_selector] = STATE(27), + [sym_child_selector] = STATE(27), + [sym_descendant_selector] = STATE(27), + [sym_universal_selector] = ACTIONS(69), + [anon_sym_DOT] = ACTIONS(11), + [anon_sym_POUND] = ACTIONS(13), + [anon_sym_LBRACK] = ACTIONS(15), + [sym_identifier] = ACTIONS(17), + [sym_comment] = ACTIONS(19), + }, + [17] = { + [sym_property_name] = STATE(28), + [sym_identifier] = ACTIONS(25), + [sym_comment] = ACTIONS(19), + }, + [18] = { + [sym__selector] = STATE(29), + [sym_type_selector] = STATE(29), + [sym_class_selector] = STATE(29), + [sym_id_selector] = STATE(29), + [sym_attribute_selector] = STATE(29), + [sym_child_selector] = STATE(29), + [sym_descendant_selector] = STATE(29), + [sym_universal_selector] = ACTIONS(71), + [anon_sym_DOT] = ACTIONS(11), + [anon_sym_POUND] = ACTIONS(13), + [anon_sym_LBRACK] = ACTIONS(15), + [sym_identifier] = ACTIONS(17), + [sym_comment] = ACTIONS(19), + }, + [19] = { + [sym__selector] = STATE(19), + [sym_type_selector] = STATE(19), + [sym_class_selector] = STATE(19), + [sym_id_selector] = STATE(19), + [sym_attribute_selector] = STATE(19), + [sym_child_selector] = STATE(19), + [sym_descendant_selector] = STATE(19), + [anon_sym_COMMA] = ACTIONS(73), + [anon_sym_LBRACE] = ACTIONS(73), + [sym_universal_selector] = ACTIONS(73), + [anon_sym_DOT] = ACTIONS(73), + [anon_sym_POUND] = ACTIONS(73), + [anon_sym_LBRACK] = ACTIONS(75), + [anon_sym_LBRACK2] = ACTIONS(73), + [anon_sym_GT] = ACTIONS(73), + [sym_identifier] = ACTIONS(73), + [sym_comment] = ACTIONS(19), + }, + [20] = { + [aux_sym_selectors_repeat1] = STATE(30), + [anon_sym_COMMA] = ACTIONS(35), + [anon_sym_LBRACE] = ACTIONS(77), + [sym_comment] = ACTIONS(19), + }, + [21] = { + [sym_rule_set] = STATE(21), + [sym_selectors] = STATE(7), + [sym__selector] = STATE(8), + [sym_type_selector] = STATE(8), + [sym_class_selector] = STATE(8), + [sym_id_selector] = STATE(8), + [sym_attribute_selector] = STATE(8), + [sym_child_selector] = STATE(8), + [sym_descendant_selector] = STATE(8), + [aux_sym_stylesheet_repeat1] = STATE(21), + [ts_builtin_sym_end] = ACTIONS(79), + [sym_import_statement] = ACTIONS(81), + [sym_universal_selector] = ACTIONS(84), + [anon_sym_DOT] = ACTIONS(87), + [anon_sym_POUND] = ACTIONS(90), + [anon_sym_LBRACK] = ACTIONS(93), + [sym_identifier] = ACTIONS(96), + [sym_comment] = ACTIONS(19), + }, + [22] = { + [sym_property_value] = ACTIONS(99), + [sym_comment] = ACTIONS(101), + }, + [23] = { + [anon_sym_COMMA] = ACTIONS(103), + [anon_sym_LBRACE] = ACTIONS(103), + [sym_universal_selector] = ACTIONS(103), + [anon_sym_DOT] = ACTIONS(103), + [anon_sym_POUND] = ACTIONS(103), + [anon_sym_LBRACK] = ACTIONS(105), + [anon_sym_LBRACK2] = ACTIONS(103), + [anon_sym_GT] = ACTIONS(103), + [sym_identifier] = ACTIONS(103), + [sym_comment] = ACTIONS(19), + }, + [24] = { + [ts_builtin_sym_end] = ACTIONS(107), + [sym_import_statement] = ACTIONS(107), + [sym_universal_selector] = ACTIONS(107), + [anon_sym_DOT] = ACTIONS(107), + [anon_sym_POUND] = ACTIONS(107), + [anon_sym_LBRACK] = ACTIONS(107), + [sym_identifier] = ACTIONS(107), + [sym_comment] = ACTIONS(19), + }, + [25] = { + [anon_sym_COLON] = ACTIONS(109), + [sym_comment] = ACTIONS(19), + }, + [26] = { + [sym_declaration] = STATE(34), + [sym_property_name] = STATE(25), + [aux_sym_block_repeat1] = STATE(34), + [anon_sym_RBRACE] = ACTIONS(111), + [sym_identifier] = ACTIONS(25), + [sym_comment] = ACTIONS(19), + }, + [27] = { + [sym__selector] = STATE(19), + [sym_type_selector] = STATE(19), + [sym_class_selector] = STATE(19), + [sym_id_selector] = STATE(19), + [sym_attribute_selector] = STATE(19), + [sym_child_selector] = STATE(19), + [sym_descendant_selector] = STATE(19), + [anon_sym_COMMA] = ACTIONS(113), + [anon_sym_LBRACE] = ACTIONS(113), + [sym_universal_selector] = ACTIONS(39), + [anon_sym_DOT] = ACTIONS(11), + [anon_sym_POUND] = ACTIONS(13), + [anon_sym_LBRACK] = ACTIONS(41), + [anon_sym_LBRACK2] = ACTIONS(43), + [anon_sym_GT] = ACTIONS(45), + [sym_identifier] = ACTIONS(17), + [sym_comment] = ACTIONS(19), + }, + [28] = { + [anon_sym_EQ] = ACTIONS(115), + [anon_sym_TILDE_EQ] = ACTIONS(115), + [anon_sym_CARET_EQ] = ACTIONS(115), + [anon_sym_PIPE_EQ] = ACTIONS(115), + [anon_sym_STAR_EQ] = ACTIONS(115), + [anon_sym_DOLLAR_EQ] = ACTIONS(115), + [anon_sym_RBRACK] = ACTIONS(117), + [sym_comment] = ACTIONS(19), + }, + [29] = { + [sym__selector] = STATE(19), + [sym_type_selector] = STATE(19), + [sym_class_selector] = STATE(19), + [sym_id_selector] = STATE(19), + [sym_attribute_selector] = STATE(19), + [sym_child_selector] = STATE(19), + [sym_descendant_selector] = STATE(19), + [anon_sym_COMMA] = ACTIONS(119), + [anon_sym_LBRACE] = ACTIONS(119), + [sym_universal_selector] = ACTIONS(119), + [anon_sym_DOT] = ACTIONS(119), + [anon_sym_POUND] = ACTIONS(119), + [anon_sym_LBRACK] = ACTIONS(121), + [anon_sym_LBRACK2] = ACTIONS(119), + [anon_sym_GT] = ACTIONS(119), + [sym_identifier] = ACTIONS(119), + [sym_comment] = ACTIONS(19), + }, + [30] = { + [aux_sym_selectors_repeat1] = STATE(30), + [anon_sym_COMMA] = ACTIONS(123), + [anon_sym_LBRACE] = ACTIONS(113), + [sym_comment] = ACTIONS(19), + }, + [31] = { + [anon_sym_RBRACK] = ACTIONS(126), + [sym_comment] = ACTIONS(19), + }, + [32] = { + [sym_property_value] = ACTIONS(128), + [sym_comment] = ACTIONS(101), + }, + [33] = { + [ts_builtin_sym_end] = ACTIONS(130), + [sym_import_statement] = ACTIONS(130), + [sym_universal_selector] = ACTIONS(130), + [anon_sym_DOT] = ACTIONS(130), + [anon_sym_POUND] = ACTIONS(130), + [anon_sym_LBRACK] = ACTIONS(130), + [sym_identifier] = ACTIONS(130), + [sym_comment] = ACTIONS(19), + }, + [34] = { + [sym_declaration] = STATE(34), + [sym_property_name] = STATE(25), + [aux_sym_block_repeat1] = STATE(34), + [anon_sym_RBRACE] = ACTIONS(132), + [sym_identifier] = ACTIONS(134), + [sym_comment] = ACTIONS(19), + }, + [35] = { + [sym_property_value] = ACTIONS(137), + [sym_comment] = ACTIONS(101), + }, + [36] = { + [anon_sym_COMMA] = ACTIONS(139), + [anon_sym_LBRACE] = ACTIONS(139), + [sym_universal_selector] = ACTIONS(139), + [anon_sym_DOT] = ACTIONS(139), + [anon_sym_POUND] = ACTIONS(139), + [anon_sym_LBRACK] = ACTIONS(141), + [anon_sym_LBRACK2] = ACTIONS(139), + [anon_sym_GT] = ACTIONS(139), + [sym_identifier] = ACTIONS(139), + [sym_comment] = ACTIONS(19), + }, + [37] = { + [anon_sym_COMMA] = ACTIONS(143), + [anon_sym_LBRACE] = ACTIONS(143), + [sym_universal_selector] = ACTIONS(143), + [anon_sym_DOT] = ACTIONS(143), + [anon_sym_POUND] = ACTIONS(143), + [anon_sym_LBRACK] = ACTIONS(145), + [anon_sym_LBRACK2] = ACTIONS(143), + [anon_sym_GT] = ACTIONS(143), + [sym_identifier] = ACTIONS(143), + [sym_comment] = ACTIONS(19), + }, + [38] = { + [anon_sym_SEMI] = ACTIONS(147), + [sym_comment] = ACTIONS(19), + }, + [39] = { + [anon_sym_RBRACK] = ACTIONS(149), + [sym_comment] = ACTIONS(19), + }, + [40] = { + [anon_sym_RBRACE] = ACTIONS(151), + [sym_identifier] = ACTIONS(151), + [sym_comment] = ACTIONS(19), + }, + [41] = { + [anon_sym_COMMA] = ACTIONS(153), + [anon_sym_LBRACE] = ACTIONS(153), + [sym_universal_selector] = ACTIONS(153), + [anon_sym_DOT] = ACTIONS(153), + [anon_sym_POUND] = ACTIONS(153), + [anon_sym_LBRACK] = ACTIONS(155), + [anon_sym_LBRACK2] = ACTIONS(153), + [anon_sym_GT] = ACTIONS(153), + [sym_identifier] = ACTIONS(153), + [sym_comment] = ACTIONS(19), + }, +}; + +static TSParseActionEntry ts_parse_actions[] = { + [0] = {.count = 0, .reusable = false}, + [1] = {.count = 1, .reusable = true}, RECOVER(), + [3] = {.count = 1, .reusable = false}, RECOVER(), + [5] = {.count = 1, .reusable = true}, REDUCE(sym_stylesheet, 0), + [7] = {.count = 1, .reusable = true}, SHIFT(9), + [9] = {.count = 1, .reusable = true}, SHIFT(8), + [11] = {.count = 1, .reusable = true}, SHIFT(2), + [13] = {.count = 1, .reusable = true}, SHIFT(3), + [15] = {.count = 1, .reusable = true}, SHIFT(4), + [17] = {.count = 1, .reusable = true}, SHIFT(5), + [19] = {.count = 1, .reusable = true}, SHIFT_EXTRA(), + [21] = {.count = 1, .reusable = true}, SHIFT(10), + [23] = {.count = 1, .reusable = true}, SHIFT(11), + [25] = {.count = 1, .reusable = true}, SHIFT(12), + [27] = {.count = 1, .reusable = true}, REDUCE(sym_type_selector, 1), + [29] = {.count = 1, .reusable = false}, REDUCE(sym_type_selector, 1), + [31] = {.count = 1, .reusable = true}, ACCEPT_INPUT(), + [33] = {.count = 1, .reusable = true}, SHIFT(14), + [35] = {.count = 1, .reusable = true}, SHIFT(16), + [37] = {.count = 1, .reusable = true}, REDUCE(sym_selectors, 1), + [39] = {.count = 1, .reusable = true}, SHIFT(19), + [41] = {.count = 1, .reusable = false}, SHIFT(4), + [43] = {.count = 1, .reusable = true}, SHIFT(17), + [45] = {.count = 1, .reusable = true}, SHIFT(18), + [47] = {.count = 1, .reusable = true}, REDUCE(sym_stylesheet, 1), + [49] = {.count = 1, .reusable = true}, SHIFT(21), + [51] = {.count = 1, .reusable = true}, REDUCE(sym_class_selector, 2), + [53] = {.count = 1, .reusable = false}, REDUCE(sym_class_selector, 2), + [55] = {.count = 1, .reusable = true}, REDUCE(sym_id_selector, 2), + [57] = {.count = 1, .reusable = false}, REDUCE(sym_id_selector, 2), + [59] = {.count = 1, .reusable = true}, REDUCE(sym_property_name, 1), + [61] = {.count = 1, .reusable = true}, SHIFT(22), + [63] = {.count = 1, .reusable = true}, SHIFT(23), + [65] = {.count = 1, .reusable = true}, SHIFT(24), + [67] = {.count = 1, .reusable = true}, REDUCE(sym_rule_set, 2), + [69] = {.count = 1, .reusable = true}, SHIFT(27), + [71] = {.count = 1, .reusable = true}, SHIFT(29), + [73] = {.count = 1, .reusable = true}, REDUCE(sym_descendant_selector, 2), + [75] = {.count = 1, .reusable = false}, REDUCE(sym_descendant_selector, 2), + [77] = {.count = 1, .reusable = true}, REDUCE(sym_selectors, 2), + [79] = {.count = 1, .reusable = true}, REDUCE(aux_sym_stylesheet_repeat1, 2), + [81] = {.count = 2, .reusable = true}, REDUCE(aux_sym_stylesheet_repeat1, 2), SHIFT_REPEAT(21), + [84] = {.count = 2, .reusable = true}, REDUCE(aux_sym_stylesheet_repeat1, 2), SHIFT_REPEAT(8), + [87] = {.count = 2, .reusable = true}, REDUCE(aux_sym_stylesheet_repeat1, 2), SHIFT_REPEAT(2), + [90] = {.count = 2, .reusable = true}, REDUCE(aux_sym_stylesheet_repeat1, 2), SHIFT_REPEAT(3), + [93] = {.count = 2, .reusable = true}, REDUCE(aux_sym_stylesheet_repeat1, 2), SHIFT_REPEAT(4), + [96] = {.count = 2, .reusable = true}, REDUCE(aux_sym_stylesheet_repeat1, 2), SHIFT_REPEAT(5), + [99] = {.count = 1, .reusable = false}, SHIFT(31), + [101] = {.count = 1, .reusable = false}, SHIFT_EXTRA(), + [103] = {.count = 1, .reusable = true}, REDUCE(sym_attribute_selector, 3), + [105] = {.count = 1, .reusable = false}, REDUCE(sym_attribute_selector, 3), + [107] = {.count = 1, .reusable = true}, REDUCE(sym_block, 2), + [109] = {.count = 1, .reusable = true}, SHIFT(32), + [111] = {.count = 1, .reusable = true}, SHIFT(33), + [113] = {.count = 1, .reusable = true}, REDUCE(aux_sym_selectors_repeat1, 2), + [115] = {.count = 1, .reusable = true}, SHIFT(35), + [117] = {.count = 1, .reusable = true}, SHIFT(36), + [119] = {.count = 1, .reusable = true}, REDUCE(sym_child_selector, 3), + [121] = {.count = 1, .reusable = false}, REDUCE(sym_child_selector, 3), + [123] = {.count = 2, .reusable = true}, REDUCE(aux_sym_selectors_repeat1, 2), SHIFT_REPEAT(16), + [126] = {.count = 1, .reusable = true}, SHIFT(37), + [128] = {.count = 1, .reusable = false}, SHIFT(38), + [130] = {.count = 1, .reusable = true}, REDUCE(sym_block, 3), + [132] = {.count = 1, .reusable = true}, REDUCE(aux_sym_block_repeat1, 2), + [134] = {.count = 2, .reusable = true}, REDUCE(aux_sym_block_repeat1, 2), SHIFT_REPEAT(12), + [137] = {.count = 1, .reusable = false}, SHIFT(39), + [139] = {.count = 1, .reusable = true}, REDUCE(sym_attribute_selector, 4), + [141] = {.count = 1, .reusable = false}, REDUCE(sym_attribute_selector, 4), + [143] = {.count = 1, .reusable = true}, REDUCE(sym_attribute_selector, 5), + [145] = {.count = 1, .reusable = false}, REDUCE(sym_attribute_selector, 5), + [147] = {.count = 1, .reusable = true}, SHIFT(40), + [149] = {.count = 1, .reusable = true}, SHIFT(41), + [151] = {.count = 1, .reusable = true}, REDUCE(sym_declaration, 4), + [153] = {.count = 1, .reusable = true}, REDUCE(sym_attribute_selector, 6), + [155] = {.count = 1, .reusable = false}, REDUCE(sym_attribute_selector, 6), +}; + +#ifdef _WIN32 +#define extern __declspec(dllexport) +#endif + +extern const TSLanguage *tree_sitter_css() { + static TSLanguage language = { + .version = LANGUAGE_VERSION, + .symbol_count = SYMBOL_COUNT, + .alias_count = ALIAS_COUNT, + .token_count = TOKEN_COUNT, + .symbol_metadata = ts_symbol_metadata, + .parse_table = (const unsigned short *)ts_parse_table, + .parse_actions = ts_parse_actions, + .lex_modes = ts_lex_modes, + .symbol_names = ts_symbol_names, + .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, + .lex_fn = ts_lex, + .external_token_count = EXTERNAL_TOKEN_COUNT, + }; + return &language; +} diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h new file mode 100644 index 0000000..a757eac --- /dev/null +++ b/src/tree_sitter/parser.h @@ -0,0 +1,195 @@ +#ifndef TREE_SITTER_PARSER_H_ +#define TREE_SITTER_PARSER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define ts_builtin_sym_error ((TSSymbol)-1) +#define ts_builtin_sym_end 0 +#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 + +#ifndef TREE_SITTER_RUNTIME_H_ +typedef uint16_t TSSymbol; +typedef struct TSLanguage TSLanguage; +#endif + +typedef uint16_t TSStateId; + +typedef struct { + bool visible : 1; + bool named : 1; +} TSSymbolMetadata; + +typedef struct TSLexer TSLexer; + +struct TSLexer { + int32_t lookahead; + TSSymbol result_symbol; + void (*advance)(TSLexer *, bool); + void (*mark_end)(TSLexer *); + uint32_t (*get_column)(TSLexer *); + bool (*is_at_included_range_start)(TSLexer *); +}; + +typedef enum { + TSParseActionTypeShift, + TSParseActionTypeReduce, + TSParseActionTypeAccept, + TSParseActionTypeRecover, +} TSParseActionType; + +typedef struct { + union { + struct { + TSStateId state; + bool extra : 1; + bool repetition : 1; + }; + struct { + TSSymbol symbol; + int16_t dynamic_precedence; + uint8_t child_count; + uint8_t alias_sequence_id; + }; + } params; + TSParseActionType type : 4; +} TSParseAction; + +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; +} TSLexMode; + +typedef union { + TSParseAction action; + struct { + uint8_t count; + bool reusable : 1; + }; +} TSParseActionEntry; + +struct TSLanguage { + uint32_t version; + uint32_t symbol_count; + uint32_t alias_count; + uint32_t token_count; + uint32_t external_token_count; + const char **symbol_names; + const TSSymbolMetadata *symbol_metadata; + const uint16_t *parse_table; + const TSParseActionEntry *parse_actions; + const TSLexMode *lex_modes; + const TSSymbol *alias_sequences; + uint16_t max_alias_sequence_length; + bool (*lex_fn)(TSLexer *, TSStateId); + bool (*keyword_lex_fn)(TSLexer *, TSStateId); + TSSymbol keyword_capture_token; + struct { + const bool *states; + const TSSymbol *symbol_map; + void *(*create)(); + void (*destroy)(void *); + bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); + unsigned (*serialize)(void *, char *); + void (*deserialize)(void *, const char *, unsigned); + } external_scanner; +}; + +/* + * Lexer Macros + */ + +#define START_LEXER() \ + bool result = false; \ + int32_t lookahead; \ + next_state: \ + lookahead = lexer->lookahead; + +#define ADVANCE(state_value) \ + { \ + lexer->advance(lexer, false); \ + state = state_value; \ + goto next_state; \ + } + +#define SKIP(state_value) \ + { \ + lexer->advance(lexer, true); \ + state = state_value; \ + goto next_state; \ + } + +#define ACCEPT_TOKEN(symbol_value) \ + result = true; \ + lexer->result_symbol = symbol_value; \ + lexer->mark_end(lexer); + +#define END_STATE() return result; + +/* + * Parse Table Macros + */ + +#define STATE(id) id + +#define ACTIONS(id) id + +#define SHIFT(state_value) \ + { \ + { \ + .type = TSParseActionTypeShift, \ + .params = {.state = state_value}, \ + } \ + } + +#define SHIFT_REPEAT(state_value) \ + { \ + { \ + .type = TSParseActionTypeShift, \ + .params = { \ + .state = state_value, \ + .repetition = true \ + }, \ + } \ + } + +#define RECOVER() \ + { \ + { .type = TSParseActionTypeRecover } \ + } + +#define SHIFT_EXTRA() \ + { \ + { \ + .type = TSParseActionTypeShift, \ + .params = {.extra = true} \ + } \ + } + +#define REDUCE(symbol_val, child_count_val, ...) \ + { \ + { \ + .type = TSParseActionTypeReduce, \ + .params = { \ + .symbol = symbol_val, \ + .child_count = child_count_val, \ + __VA_ARGS__ \ + } \ + } \ + } + +#define ACCEPT_INPUT() \ + { \ + { .type = TSParseActionTypeAccept } \ + } + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_PARSER_H_