mirror of https://github.com/Wilfred/difftastic/
Use tree-sitter-css from crates.io
parent
97dbc9b018
commit
c73b18be77
@ -1 +0,0 @@
|
|||||||
../tree-sitter-css/queries/highlights.scm
|
|
||||||
@ -1 +0,0 @@
|
|||||||
tree-sitter-css/src
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
image: Visual Studio 2015
|
|
||||||
|
|
||||||
environment:
|
|
||||||
nodejs_version: "10"
|
|
||||||
|
|
||||||
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
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
'env': {
|
|
||||||
'commonjs': true,
|
|
||||||
'es2021': true,
|
|
||||||
},
|
|
||||||
'extends': 'google',
|
|
||||||
'overrides': [
|
|
||||||
],
|
|
||||||
'parserOptions': {
|
|
||||||
'ecmaVersion': 'latest',
|
|
||||||
'sourceType': 'module',
|
|
||||||
},
|
|
||||||
'rules': {
|
|
||||||
'indent': ['error', 2, {'SwitchCase': 1}],
|
|
||||||
'max-len': [
|
|
||||||
'error',
|
|
||||||
{'code': 120, 'ignoreComments': true, 'ignoreUrls': true, 'ignoreStrings': true},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
/src/** linguist-vendored
|
|
||||||
/examples/* linguist-vendored
|
|
||||||
|
|
||||||
src/grammar.json linguist-generated
|
|
||||||
src/node-types.json linguist-generated
|
|
||||||
src/parser.c linguist-generated
|
|
||||||
|
|
||||||
src/grammar.json -diff
|
|
||||||
src/node-types.json -diff
|
|
||||||
src/parser.c -diff
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
name: Bug Report
|
|
||||||
description: File a bug or issue
|
|
||||||
title: "bug: "
|
|
||||||
labels: [bug]
|
|
||||||
body:
|
|
||||||
- type: markdown
|
|
||||||
attributes:
|
|
||||||
value: |
|
|
||||||
**Before** reporting an issue, make sure to search [existing issues](https://github.com/tree-sitter/tree-sitter-css/issues). Usage questions such as ***"How do I...?"*** either belong in [Discussions](https://github.com/tree-sitter/tree-sitter/discussions) upstream or in our [Discord server](https://discord.gg/w7nTvsVJhm) and will be closed.
|
|
||||||
If your issue is related to a bug in your editor-experience because your editor *leverages* tree-sitter and this parser, then it is likely your issue does *NOT* belong here and belongs in the relevant editor's repository.
|
|
||||||
- type: checkboxes
|
|
||||||
attributes:
|
|
||||||
label: Did you check existing issues?
|
|
||||||
description: Make sure you've checked all of the below before submitting an issue
|
|
||||||
options:
|
|
||||||
- label: I have read all the [tree-sitter docs](https://tree-sitter.github.io/tree-sitter/using-parsers) if it relates to using the parser
|
|
||||||
required: false
|
|
||||||
- label: I have searched the existing issues of tree-sitter-css
|
|
||||||
required: true
|
|
||||||
- type: input
|
|
||||||
attributes:
|
|
||||||
label: "Tree-Sitter CLI Version, if relevant (output of `tree-sitter --version`)"
|
|
||||||
placeholder: "tree-sitter 0.20.8 (6bbb50bef8249e6460e7d69e42cc8146622fa4fd)"
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Describe the bug
|
|
||||||
description: A clear and concise description of what the bug is. Please include any related errors you see such as parsing errors or tree-sitter cli errors.
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Steps To Reproduce/Bad Parse Tree
|
|
||||||
description: Steps to reproduce the behavior. If you have a bad parse tree, please include it here. You can get this by running `tree-sitter parse <path-to-file>` and copying the output.
|
|
||||||
placeholder: |
|
|
||||||
1.
|
|
||||||
2.
|
|
||||||
3.
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Expected Behavior/Parse Tree
|
|
||||||
description: A concise description of what you expected to happen, or in the case of a bad parse tree, the expected parse tree.
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
- type: textarea
|
|
||||||
attributes:
|
|
||||||
label: Repro
|
|
||||||
description: Minimal code to reproduce this issue. Ideally this should be reproducible with the C library or the tree-sitter cli, do not suggest an editor or external tool.
|
|
||||||
value: |
|
|
||||||
/* Example code that fails to parse */
|
|
||||||
.foo {
|
|
||||||
color: red;
|
|
||||||
/* Code that fails to parse, or causes an error */
|
|
||||||
}
|
|
||||||
render: CSS
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
@ -1 +0,0 @@
|
|||||||
blank_issues_enabled: false
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
name: Feature Request
|
|
||||||
description: Suggest a new feature
|
|
||||||
title: "feature: "
|
|
||||||
labels: [enhancement]
|
|
||||||
body:
|
|
||||||
- type: checkboxes
|
|
||||||
attributes:
|
|
||||||
label: Did you check the tree-sitter docs?
|
|
||||||
description: Make sure you read all the docs before submitting a feature request
|
|
||||||
options:
|
|
||||||
- label: I have read all the [tree-sitter docs](https://tree-sitter.github.io/tree-sitter/using-parsers) if it relates to using the parser
|
|
||||||
required: false
|
|
||||||
- type: textarea
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
attributes:
|
|
||||||
label: Is your feature request related to a problem? Please describe.
|
|
||||||
description: A clear and concise description of what the problem is. Ex. I think the grammar models this rule incorrectly and can be improved, or the scanner can be improved by doing [...], or CSS has officially added a new feature that should be added to the grammar.
|
|
||||||
- type: textarea
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
attributes:
|
|
||||||
label: Describe the solution you'd like
|
|
||||||
description: A clear and concise description of what you want to happen.
|
|
||||||
- type: textarea
|
|
||||||
validations:
|
|
||||||
required: true
|
|
||||||
attributes:
|
|
||||||
label: Describe alternatives you've considered
|
|
||||||
description: A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
- type: textarea
|
|
||||||
validations:
|
|
||||||
required: false
|
|
||||||
attributes:
|
|
||||||
label: Additional context
|
|
||||||
description: Add any other context or screenshots about the feature request here. If your feature request is related to a new CSS feature, please include a link to the relevant **official** CSS documentation.
|
|
||||||
@ -1,32 +0,0 @@
|
|||||||
name: CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "**"
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: true
|
|
||||||
matrix:
|
|
||||||
os: [macos-latest, ubuntu-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
- run: npm install
|
|
||||||
- run: npm test
|
|
||||||
test_windows:
|
|
||||||
runs-on: windows-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
- run: npm install
|
|
||||||
- run: npm run-script test-windows
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
name: Fuzz Parser
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
paths:
|
|
||||||
- src/scanner.c
|
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- src/scanner.c
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Parser fuzzing
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: vigoux/tree-sitter-fuzz-action@v1
|
|
||||||
with:
|
|
||||||
language: css
|
|
||||||
external-scanner: src/scanner.c
|
|
||||||
time: 60
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
name: Lint
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "**"
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Install modules
|
|
||||||
run: npm install
|
|
||||||
- name: Run ESLint
|
|
||||||
run: npm run lint
|
|
||||||
@ -1,103 +0,0 @@
|
|||||||
name: Release
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_run:
|
|
||||||
workflows: ["CI"]
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Get previous commit SHA
|
|
||||||
id: get_previous_commit
|
|
||||||
run: |
|
|
||||||
LATEST_TAG=$(git describe --tags --abbrev=0)
|
|
||||||
if [[ -z "$LATEST_TAG" ]]; then
|
|
||||||
echo "No tag found. Failing..."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "latest_tag=${LATEST_TAG#v}" >> "$GITHUB_ENV" # Remove 'v' prefix from the tag
|
|
||||||
|
|
||||||
- name: Check if version changed and is greater than the previous
|
|
||||||
id: version_check
|
|
||||||
run: |
|
|
||||||
# Compare the current version with the version from the previous commit
|
|
||||||
PREVIOUS_NPM_VERSION=${{ env.latest_tag }}
|
|
||||||
CURRENT_NPM_VERSION=$(jq -r '.version' package.json)
|
|
||||||
CURRENT_CARGO_VERSION=$(awk -F '"' '/^version/ {print $2}' Cargo.toml)
|
|
||||||
if [[ "$CURRENT_NPM_VERSION" != "$CURRENT_CARGO_VERSION" ]]; then # Cargo.toml and package.json versions must match
|
|
||||||
echo "Mismatch: NPM version ($CURRENT_NPM_VERSION) and Cargo.toml version ($CURRENT_CARGO_VERSION)"
|
|
||||||
echo "version_changed=false" >> "$GITHUB_ENV"
|
|
||||||
else
|
|
||||||
if [[ "$PREVIOUS_NPM_VERSION" == "$CURRENT_NPM_VERSION" ]]; then
|
|
||||||
echo "version_changed=" >> "$GITHUB_ENV"
|
|
||||||
else
|
|
||||||
IFS='.' read -ra PREVIOUS_VERSION_PARTS <<< "$PREVIOUS_NPM_VERSION"
|
|
||||||
IFS='.' read -ra CURRENT_VERSION_PARTS <<< "$CURRENT_NPM_VERSION"
|
|
||||||
VERSION_CHANGED=false
|
|
||||||
for i in "${!PREVIOUS_VERSION_PARTS[@]}"; do
|
|
||||||
if [[ ${CURRENT_VERSION_PARTS[i]} -gt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
|
|
||||||
VERSION_CHANGED=true
|
|
||||||
break
|
|
||||||
elif [[ ${CURRENT_VERSION_PARTS[i]} -lt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "version_changed=$VERSION_CHANGED" >> "$GITHUB_ENV"
|
|
||||||
echo "current_version=${CURRENT_NPM_VERSION}" >> "$GITHUB_ENV"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Display result
|
|
||||||
run: |
|
|
||||||
echo "Version bump detected: ${{ env.version_changed }}"
|
|
||||||
|
|
||||||
- name: Fail if version is lower
|
|
||||||
if: env.version_changed == 'false'
|
|
||||||
run: exit 1
|
|
||||||
|
|
||||||
- name: Setup Node
|
|
||||||
if: env.version_changed == 'true'
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 18
|
|
||||||
registry-url: "https://registry.npmjs.org"
|
|
||||||
- name: Publish to NPM
|
|
||||||
if: env.version_changed == 'true'
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
|
||||||
run: npm publish
|
|
||||||
|
|
||||||
- name: Setup Rust
|
|
||||||
if: env.version_changed == 'true'
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
profile: minimal
|
|
||||||
toolchain: stable
|
|
||||||
override: true
|
|
||||||
- name: Publish to Crates.io
|
|
||||||
if: env.version_changed == 'true'
|
|
||||||
uses: katyo/publish-crates@v2
|
|
||||||
with:
|
|
||||||
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
|
||||||
|
|
||||||
- name: Tag versions
|
|
||||||
if: env.version_changed == 'true'
|
|
||||||
run: |
|
|
||||||
git checkout master
|
|
||||||
git config user.name github-actions[bot]
|
|
||||||
git config user.email github-actions[bot]@users.noreply.github.com
|
|
||||||
git tag -d "v${{ env.current_version }}" || true
|
|
||||||
git push origin --delete "v${{ env.current_version }}" || true
|
|
||||||
git tag -a "v${{ env.current_version }}" -m "Version ${{ env.current_version }}"
|
|
||||||
git push origin "v${{ env.current_version }}"
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
Cargo.lock
|
|
||||||
node_modules
|
|
||||||
build
|
|
||||||
package-lock.json
|
|
||||||
/target/
|
|
||||||
.build/
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
/test
|
|
||||||
/examples
|
|
||||||
/build
|
|
||||||
/script
|
|
||||||
/target
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
|
|
||||||
node_js: 10
|
|
||||||
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "tree-sitter-css"
|
|
||||||
description = "CSS grammar for tree-sitter"
|
|
||||||
version = "0.20.0"
|
|
||||||
authors = [
|
|
||||||
"Max Brunsfeld <maxbrunsfeld@gmail.com>",
|
|
||||||
"Amaan Qureshi <amaanq12@gmail.com>",
|
|
||||||
]
|
|
||||||
license = "MIT"
|
|
||||||
readme = "bindings/rust/README.md"
|
|
||||||
keywords = ["incremental", "parsing", "css"]
|
|
||||||
categories = ["parsing", "text-editors"]
|
|
||||||
repository = "https://github.com/tree-sitter/tree-sitter-css"
|
|
||||||
edition = "2021"
|
|
||||||
autoexamples = false
|
|
||||||
|
|
||||||
build = "bindings/rust/build.rs"
|
|
||||||
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
path = "bindings/rust/lib.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
tree-sitter = "~0.20.10"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
cc = "~1.0"
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2018 Max Brunsfeld
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
// swift-tools-version:5.3
|
|
||||||
import PackageDescription
|
|
||||||
|
|
||||||
let package = Package(
|
|
||||||
name: "TreeSitterCSS",
|
|
||||||
products: [
|
|
||||||
.library(name: "TreeSitterCSS", targets: ["TreeSitterCSS"]),
|
|
||||||
],
|
|
||||||
dependencies: [],
|
|
||||||
targets: [
|
|
||||||
.target(name: "TreeSitterCSS",
|
|
||||||
path: ".",
|
|
||||||
exclude: [
|
|
||||||
"binding.gyp",
|
|
||||||
"bindings",
|
|
||||||
"Cargo.toml",
|
|
||||||
"corpus",
|
|
||||||
"grammar.js",
|
|
||||||
"LICENSE",
|
|
||||||
"package.json",
|
|
||||||
"README.md",
|
|
||||||
],
|
|
||||||
sources: [
|
|
||||||
"src/parser.c",
|
|
||||||
"src/scanner.c",
|
|
||||||
],
|
|
||||||
resources: [
|
|
||||||
.copy("queries")
|
|
||||||
],
|
|
||||||
publicHeadersPath: "bindings/swift",
|
|
||||||
cSettings: [.headerSearchPath("src")])
|
|
||||||
]
|
|
||||||
)
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
# tree-sitter-css
|
|
||||||
|
|
||||||
[![CI][ci]](https://github.com/tree-sitter/tree-sitter-css/actions/workflows/ci.yml)
|
|
||||||
[![discord][discord]](https://discord.gg/w7nTvsVJhm)
|
|
||||||
[![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org)
|
|
||||||
[![crates][crates]](https://crates.io/crates/tree-sitter-css)
|
|
||||||
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-css)
|
|
||||||
|
|
||||||
CSS grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
|
||||||
|
|
||||||
References
|
|
||||||
|
|
||||||
- [CSS Syntax Guide](https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax)
|
|
||||||
|
|
||||||
[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/tree-sitter-css/ci.yml?logo=github&label=CI
|
|
||||||
[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord
|
|
||||||
[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix
|
|
||||||
[npm]: https://img.shields.io/npm/v/tree-sitter-css?logo=npm
|
|
||||||
[crates]: https://img.shields.io/crates/v/tree-sitter-css?logo=rust
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"targets": [
|
|
||||||
{
|
|
||||||
"target_name": "tree_sitter_css_binding",
|
|
||||||
"include_dirs": [
|
|
||||||
"<!(node -e \"require('nan')\")",
|
|
||||||
"src"
|
|
||||||
],
|
|
||||||
"sources": [
|
|
||||||
"src/parser.c",
|
|
||||||
"src/scanner.c",
|
|
||||||
"bindings/node/binding.cc"
|
|
||||||
],
|
|
||||||
"cflags_c": [
|
|
||||||
"-std=c99",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
#include "tree_sitter/parser.h"
|
|
||||||
#include <node.h>
|
|
||||||
#include "nan.h"
|
|
||||||
|
|
||||||
using namespace v8;
|
|
||||||
|
|
||||||
extern "C" TSLanguage * tree_sitter_css();
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
NAN_METHOD(New) {}
|
|
||||||
|
|
||||||
void Init(Local<Object> exports, Local<Object> module) {
|
|
||||||
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
|
||||||
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
|
|
||||||
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
|
||||||
|
|
||||||
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
|
|
||||||
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
|
||||||
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_css());
|
|
||||||
|
|
||||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("css").ToLocalChecked());
|
|
||||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
NODE_MODULE(tree_sitter_css_binding, Init)
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
try {
|
|
||||||
module.exports = require("../../build/Release/tree_sitter_css_binding");
|
|
||||||
} catch (error1) {
|
|
||||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
|
||||||
throw error1;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
module.exports = require("../../build/Debug/tree_sitter_css_binding");
|
|
||||||
} catch (error2) {
|
|
||||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
|
||||||
throw error2;
|
|
||||||
}
|
|
||||||
throw error1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
|
||||||
} catch (_) {}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
# tree-sitter-css
|
|
||||||
|
|
||||||
This crate provides a CSS grammar for the [tree-sitter][] parsing library.
|
|
||||||
To use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
|
|
||||||
file. (Note that you will probably also need to depend on the
|
|
||||||
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
|
|
||||||
way.)
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[dependencies]
|
|
||||||
tree-sitter = "~0.20.10"
|
|
||||||
tree-sitter-css = "0.20.0"
|
|
||||||
```
|
|
||||||
|
|
||||||
Typically, you will use the [language][language func] function to add this
|
|
||||||
grammar to a tree-sitter [Parser][], and then use the parser to parse some code:
|
|
||||||
|
|
||||||
```rust
|
|
||||||
let code = r#"
|
|
||||||
.foo {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
let mut parser = Parser::new();
|
|
||||||
parser.set_language(tree_sitter_css::language()).expect("Error loading CSS grammar");
|
|
||||||
let parsed = parser.parse(code, None);
|
|
||||||
```
|
|
||||||
|
|
||||||
If you have any questions, please reach out to us in the [tree-sitter
|
|
||||||
discussions] page.
|
|
||||||
|
|
||||||
[language func]: https://docs.rs/tree-sitter-css/*/tree_sitter_css/fn.language.html
|
|
||||||
[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
|
||||||
[tree-sitter]: https://tree-sitter.github.io/
|
|
||||||
[tree-sitter crate]: https://crates.io/crates/tree-sitter
|
|
||||||
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
let src_dir = std::path::Path::new("src");
|
|
||||||
|
|
||||||
let mut c_config = cc::Build::new();
|
|
||||||
c_config.include(src_dir);
|
|
||||||
c_config
|
|
||||||
.flag_if_supported("-Wno-unused-parameter")
|
|
||||||
.flag_if_supported("-Wno-unused-but-set-variable")
|
|
||||||
.flag_if_supported("-Wno-trigraphs");
|
|
||||||
let parser_path = src_dir.join("parser.c");
|
|
||||||
c_config.file(&parser_path);
|
|
||||||
|
|
||||||
let scanner_path = src_dir.join("scanner.c");
|
|
||||||
c_config.file(&scanner_path);
|
|
||||||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
|
||||||
|
|
||||||
c_config.compile("parser");
|
|
||||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
|
||||||
}
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
//! This crate provides css language support for the [tree-sitter][] parsing library.
|
|
||||||
//!
|
|
||||||
//! Typically, you will use the [language][language func] function to add this language to a
|
|
||||||
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
|
||||||
//!
|
|
||||||
//! ```
|
|
||||||
//! let code = "";
|
|
||||||
//! let mut parser = tree_sitter::Parser::new();
|
|
||||||
//! parser.set_language(tree_sitter_css::language()).expect("Error loading CSS grammar");
|
|
||||||
//! let tree = parser.parse(code, None).unwrap();
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
||||||
//! [language func]: fn.language.html
|
|
||||||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
|
||||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
|
||||||
|
|
||||||
use tree_sitter::Language;
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
fn tree_sitter_css() -> Language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the tree-sitter [Language][] for this grammar.
|
|
||||||
///
|
|
||||||
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
||||||
pub fn language() -> Language {
|
|
||||||
unsafe { tree_sitter_css() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The content of the [`node-types.json`][] file for this grammar.
|
|
||||||
///
|
|
||||||
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
|
||||||
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
|
||||||
|
|
||||||
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn test_can_load_grammar() {
|
|
||||||
let mut parser = tree_sitter::Parser::new();
|
|
||||||
parser
|
|
||||||
.set_language(super::language())
|
|
||||||
.expect("Error loading CSS grammar");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
#ifndef TREE_SITTER_CSS_H_
|
|
||||||
#define TREE_SITTER_CSS_H_
|
|
||||||
|
|
||||||
typedef struct TSLanguage TSLanguage;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern TSLanguage *tree_sitter_css();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // TREE_SITTER_CSS_H_
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,426 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file CSS grammar for tree-sitter
|
|
||||||
* @author Max Brunsfeld <maxbrunsfeld@gmail.com>
|
|
||||||
* @author Amaan Qureshi <amaanq12@gmail.com>
|
|
||||||
* @license MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* eslint-disable arrow-parens */
|
|
||||||
/* eslint-disable camelcase */
|
|
||||||
/* eslint-disable-next-line spaced-comment */
|
|
||||||
/// <reference types="tree-sitter-cli/dsl" />
|
|
||||||
// @ts-check
|
|
||||||
|
|
||||||
module.exports = grammar({
|
|
||||||
name: 'css',
|
|
||||||
|
|
||||||
extras: $ => [
|
|
||||||
/\s/,
|
|
||||||
$.comment,
|
|
||||||
$.js_comment,
|
|
||||||
],
|
|
||||||
|
|
||||||
externals: $ => [
|
|
||||||
$._descendant_operator,
|
|
||||||
$._pseudo_class_selector_colon,
|
|
||||||
$.__error_recovery,
|
|
||||||
],
|
|
||||||
|
|
||||||
inline: $ => [
|
|
||||||
$._top_level_item,
|
|
||||||
$._block_item,
|
|
||||||
],
|
|
||||||
|
|
||||||
rules: {
|
|
||||||
stylesheet: $ => repeat($._top_level_item),
|
|
||||||
|
|
||||||
_top_level_item: $ => choice(
|
|
||||||
$.declaration,
|
|
||||||
$.rule_set,
|
|
||||||
$.import_statement,
|
|
||||||
$.media_statement,
|
|
||||||
$.charset_statement,
|
|
||||||
$.namespace_statement,
|
|
||||||
$.keyframes_statement,
|
|
||||||
$.supports_statement,
|
|
||||||
$.at_rule,
|
|
||||||
),
|
|
||||||
|
|
||||||
// Statements
|
|
||||||
|
|
||||||
import_statement: $ => seq(
|
|
||||||
'@import',
|
|
||||||
$._value,
|
|
||||||
sep(',', $._query),
|
|
||||||
';',
|
|
||||||
),
|
|
||||||
|
|
||||||
media_statement: $ => seq(
|
|
||||||
'@media',
|
|
||||||
sep1(',', $._query),
|
|
||||||
$.block,
|
|
||||||
),
|
|
||||||
|
|
||||||
charset_statement: $ => seq(
|
|
||||||
'@charset',
|
|
||||||
$._value,
|
|
||||||
';',
|
|
||||||
),
|
|
||||||
|
|
||||||
namespace_statement: $ => seq(
|
|
||||||
'@namespace',
|
|
||||||
optional(alias($.identifier, $.namespace_name)),
|
|
||||||
choice($.string_value, $.call_expression),
|
|
||||||
';',
|
|
||||||
),
|
|
||||||
|
|
||||||
keyframes_statement: $ => seq(
|
|
||||||
choice(
|
|
||||||
'@keyframes',
|
|
||||||
alias(/@[-a-z]+keyframes/, $.at_keyword),
|
|
||||||
),
|
|
||||||
alias($.identifier, $.keyframes_name),
|
|
||||||
$.keyframe_block_list,
|
|
||||||
),
|
|
||||||
|
|
||||||
keyframe_block_list: $ => seq(
|
|
||||||
'{',
|
|
||||||
repeat($.keyframe_block),
|
|
||||||
'}',
|
|
||||||
),
|
|
||||||
|
|
||||||
keyframe_block: $ => seq(
|
|
||||||
choice($.from, $.to, $.integer_value),
|
|
||||||
$.block,
|
|
||||||
),
|
|
||||||
|
|
||||||
from: _ => 'from',
|
|
||||||
to: _ => 'to',
|
|
||||||
|
|
||||||
supports_statement: $ => seq(
|
|
||||||
'@supports',
|
|
||||||
$._query,
|
|
||||||
$.block,
|
|
||||||
),
|
|
||||||
|
|
||||||
postcss_statement: $ => prec(-1, seq(
|
|
||||||
$.at_keyword,
|
|
||||||
repeat($._value),
|
|
||||||
';',
|
|
||||||
)),
|
|
||||||
|
|
||||||
at_rule: $ => seq(
|
|
||||||
$.at_keyword,
|
|
||||||
sep(',', $._query),
|
|
||||||
choice(';', $.block),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Rule sets
|
|
||||||
|
|
||||||
rule_set: $ => seq(
|
|
||||||
$.selectors,
|
|
||||||
$.block,
|
|
||||||
),
|
|
||||||
|
|
||||||
selectors: $ => sep1(',', $._selector),
|
|
||||||
|
|
||||||
block: $ => seq(
|
|
||||||
'{',
|
|
||||||
repeat($._block_item),
|
|
||||||
optional(alias($.last_declaration, $.declaration)),
|
|
||||||
'}',
|
|
||||||
),
|
|
||||||
|
|
||||||
_block_item: $ => choice(
|
|
||||||
$.declaration,
|
|
||||||
$.rule_set,
|
|
||||||
$.import_statement,
|
|
||||||
$.media_statement,
|
|
||||||
$.charset_statement,
|
|
||||||
$.namespace_statement,
|
|
||||||
$.keyframes_statement,
|
|
||||||
$.supports_statement,
|
|
||||||
$.postcss_statement,
|
|
||||||
$.at_rule,
|
|
||||||
),
|
|
||||||
|
|
||||||
// Selectors
|
|
||||||
|
|
||||||
_selector: $ => choice(
|
|
||||||
$.universal_selector,
|
|
||||||
alias($.identifier, $.tag_name),
|
|
||||||
$.class_selector,
|
|
||||||
$.nesting_selector,
|
|
||||||
$.pseudo_class_selector,
|
|
||||||
$.pseudo_element_selector,
|
|
||||||
$.id_selector,
|
|
||||||
$.attribute_selector,
|
|
||||||
$.string_value,
|
|
||||||
$.child_selector,
|
|
||||||
$.descendant_selector,
|
|
||||||
$.sibling_selector,
|
|
||||||
$.adjacent_sibling_selector,
|
|
||||||
$.namespace_selector,
|
|
||||||
),
|
|
||||||
|
|
||||||
nesting_selector: _ => '&',
|
|
||||||
|
|
||||||
universal_selector: _ => '*',
|
|
||||||
|
|
||||||
class_selector: $ => prec(1, seq(
|
|
||||||
optional($._selector),
|
|
||||||
'.',
|
|
||||||
alias($.identifier, $.class_name),
|
|
||||||
)),
|
|
||||||
|
|
||||||
pseudo_class_selector: $ => seq(
|
|
||||||
optional($._selector),
|
|
||||||
alias($._pseudo_class_selector_colon, ':'),
|
|
||||||
alias($.identifier, $.class_name),
|
|
||||||
optional(alias($.pseudo_class_arguments, $.arguments)),
|
|
||||||
),
|
|
||||||
|
|
||||||
pseudo_element_selector: $ => seq(
|
|
||||||
optional($._selector),
|
|
||||||
'::',
|
|
||||||
alias($.identifier, $.tag_name),
|
|
||||||
optional(alias($.pseudo_element_arguments, $.arguments)),
|
|
||||||
),
|
|
||||||
|
|
||||||
id_selector: $ => seq(
|
|
||||||
optional($._selector),
|
|
||||||
'#',
|
|
||||||
alias($.identifier, $.id_name),
|
|
||||||
),
|
|
||||||
|
|
||||||
attribute_selector: $ => seq(
|
|
||||||
optional($._selector),
|
|
||||||
'[',
|
|
||||||
alias(choice($.identifier, $.namespace_selector), $.attribute_name),
|
|
||||||
optional(seq(
|
|
||||||
choice('=', '~=', '^=', '|=', '*=', '$='),
|
|
||||||
$._value,
|
|
||||||
)),
|
|
||||||
']',
|
|
||||||
),
|
|
||||||
|
|
||||||
child_selector: $ => prec.left(seq($._selector, '>', $._selector)),
|
|
||||||
|
|
||||||
descendant_selector: $ => prec.left(seq($._selector, $._descendant_operator, $._selector)),
|
|
||||||
|
|
||||||
sibling_selector: $ => prec.left(seq($._selector, '~', $._selector)),
|
|
||||||
|
|
||||||
adjacent_sibling_selector: $ => prec.left(seq($._selector, '+', $._selector)),
|
|
||||||
|
|
||||||
namespace_selector: $ => prec.left(seq($._selector, '|', $._selector)),
|
|
||||||
|
|
||||||
pseudo_class_arguments: $ => seq(
|
|
||||||
token.immediate('('),
|
|
||||||
sep(',', choice($._selector, repeat1($._value))),
|
|
||||||
')',
|
|
||||||
),
|
|
||||||
|
|
||||||
pseudo_element_arguments: $ => seq(
|
|
||||||
token.immediate('('),
|
|
||||||
sep(',', choice($._selector, repeat1($._value))),
|
|
||||||
')',
|
|
||||||
),
|
|
||||||
|
|
||||||
// Declarations
|
|
||||||
|
|
||||||
declaration: $ => seq(
|
|
||||||
alias($.identifier, $.property_name),
|
|
||||||
':',
|
|
||||||
$._value,
|
|
||||||
repeat(seq(
|
|
||||||
optional(','),
|
|
||||||
$._value,
|
|
||||||
)),
|
|
||||||
optional($.important),
|
|
||||||
';',
|
|
||||||
),
|
|
||||||
|
|
||||||
last_declaration: $ => prec(1, seq(
|
|
||||||
alias($.identifier, $.property_name),
|
|
||||||
':',
|
|
||||||
$._value,
|
|
||||||
repeat(seq(
|
|
||||||
optional(','),
|
|
||||||
$._value,
|
|
||||||
)),
|
|
||||||
optional($.important),
|
|
||||||
)),
|
|
||||||
|
|
||||||
important: _ => '!important',
|
|
||||||
|
|
||||||
// Media queries
|
|
||||||
|
|
||||||
_query: $ => choice(
|
|
||||||
alias($.identifier, $.keyword_query),
|
|
||||||
$.feature_query,
|
|
||||||
$.binary_query,
|
|
||||||
$.unary_query,
|
|
||||||
$.selector_query,
|
|
||||||
$.parenthesized_query,
|
|
||||||
),
|
|
||||||
|
|
||||||
feature_query: $ => seq(
|
|
||||||
'(',
|
|
||||||
alias($.identifier, $.feature_name),
|
|
||||||
':',
|
|
||||||
repeat1($._value),
|
|
||||||
')',
|
|
||||||
),
|
|
||||||
|
|
||||||
parenthesized_query: $ => seq(
|
|
||||||
'(',
|
|
||||||
$._query,
|
|
||||||
')',
|
|
||||||
),
|
|
||||||
|
|
||||||
binary_query: $ => prec.left(seq(
|
|
||||||
$._query,
|
|
||||||
choice('and', 'or'),
|
|
||||||
$._query,
|
|
||||||
)),
|
|
||||||
|
|
||||||
unary_query: $ => prec(1, seq(
|
|
||||||
choice('not', 'only'),
|
|
||||||
$._query,
|
|
||||||
)),
|
|
||||||
|
|
||||||
selector_query: $ => seq(
|
|
||||||
'selector',
|
|
||||||
'(',
|
|
||||||
$._selector,
|
|
||||||
')',
|
|
||||||
),
|
|
||||||
|
|
||||||
// Property Values
|
|
||||||
|
|
||||||
_value: $ => prec(-1, choice(
|
|
||||||
alias($.identifier, $.plain_value),
|
|
||||||
$.plain_value,
|
|
||||||
$.color_value,
|
|
||||||
$.integer_value,
|
|
||||||
$.float_value,
|
|
||||||
$.string_value,
|
|
||||||
$.grid_value,
|
|
||||||
$.binary_expression,
|
|
||||||
$.parenthesized_value,
|
|
||||||
$.call_expression,
|
|
||||||
$.important,
|
|
||||||
)),
|
|
||||||
|
|
||||||
parenthesized_value: $ => seq(
|
|
||||||
'(',
|
|
||||||
$._value,
|
|
||||||
')',
|
|
||||||
),
|
|
||||||
|
|
||||||
color_value: _ => seq('#', token.immediate(/[0-9a-fA-F]{3,8}/)),
|
|
||||||
|
|
||||||
string_value: _ => choice(
|
|
||||||
seq('\'', /([^'\n]|\\(.|\n))*/, '\''),
|
|
||||||
seq('"', /([^"\n]|\\(.|\n))*/, '"'),
|
|
||||||
),
|
|
||||||
|
|
||||||
integer_value: $ => seq(
|
|
||||||
token(seq(
|
|
||||||
optional(choice('+', '-')),
|
|
||||||
/\d+/,
|
|
||||||
)),
|
|
||||||
optional($.unit),
|
|
||||||
),
|
|
||||||
|
|
||||||
float_value: $ => seq(
|
|
||||||
token(seq(
|
|
||||||
optional(choice('+', '-')),
|
|
||||||
/\d*/,
|
|
||||||
choice(
|
|
||||||
seq('.', /\d+/),
|
|
||||||
seq(/[eE]/, optional('-'), /\d+/),
|
|
||||||
seq('.', /\d+/, /[eE]/, optional('-'), /\d+/),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
optional($.unit),
|
|
||||||
),
|
|
||||||
|
|
||||||
unit: _ => token.immediate(/[a-zA-Z%]+/),
|
|
||||||
|
|
||||||
grid_value: $ => seq(
|
|
||||||
'[',
|
|
||||||
sep1(',', $._value),
|
|
||||||
']',
|
|
||||||
),
|
|
||||||
|
|
||||||
call_expression: $ => seq(
|
|
||||||
alias($.identifier, $.function_name),
|
|
||||||
$.arguments,
|
|
||||||
),
|
|
||||||
|
|
||||||
binary_expression: $ => prec.left(seq(
|
|
||||||
$._value,
|
|
||||||
choice('+', '-', '*', '/'),
|
|
||||||
$._value,
|
|
||||||
)),
|
|
||||||
|
|
||||||
arguments: $ => seq(
|
|
||||||
token.immediate('('),
|
|
||||||
sep(choice(',', ';'), repeat1($._value)),
|
|
||||||
')',
|
|
||||||
),
|
|
||||||
|
|
||||||
identifier: _ => /(--|-?[a-zA-Z_])[a-zA-Z0-9-_]*/,
|
|
||||||
|
|
||||||
at_keyword: _ => /@[a-zA-Z-_]+/,
|
|
||||||
|
|
||||||
js_comment: _ => token(prec(-1, seq('//', /.*/))),
|
|
||||||
|
|
||||||
comment: _ => token(seq(
|
|
||||||
'/*',
|
|
||||||
/[^*]*\*+([^/*][^*]*\*+)*/,
|
|
||||||
'/',
|
|
||||||
)),
|
|
||||||
|
|
||||||
plain_value: _ => token(seq(
|
|
||||||
repeat(choice(
|
|
||||||
/[-_]/,
|
|
||||||
/\/[^\*\s,;!{}()\[\]]/, // Slash not followed by a '*' (which would be a comment)
|
|
||||||
)),
|
|
||||||
/[a-zA-Z]/,
|
|
||||||
repeat(choice(
|
|
||||||
/[^/\s,;!{}()\[\]]/, // Not a slash, not a delimiter character
|
|
||||||
/\/[^\*\s,;!{}()\[\]]/, // Slash not followed by a '*' (which would be a comment)
|
|
||||||
)),
|
|
||||||
)),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a rule to optionally match one or more of the rules separated by `separator`
|
|
||||||
*
|
|
||||||
* @param {RuleOrLiteral} separator
|
|
||||||
*
|
|
||||||
* @param {RuleOrLiteral} rule
|
|
||||||
*
|
|
||||||
* @return {ChoiceRule}
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function sep(separator, rule) {
|
|
||||||
return optional(sep1(separator, rule));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a rule to match one or more of the rules separated by `separator`
|
|
||||||
*
|
|
||||||
* @param {RuleOrLiteral} separator
|
|
||||||
*
|
|
||||||
* @param {RuleOrLiteral} rule
|
|
||||||
*
|
|
||||||
* @return {SeqRule}
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function sep1(separator, rule) {
|
|
||||||
return seq(rule, repeat(seq(separator, rule)));
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "tree-sitter-css",
|
|
||||||
"version": "0.20.0",
|
|
||||||
"description": "CSS grammar for tree-sitter",
|
|
||||||
"main": "bindings/node",
|
|
||||||
"keywords": [
|
|
||||||
"parser",
|
|
||||||
"lexer",
|
|
||||||
"css"
|
|
||||||
],
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/tree-sitter/tree-sitter-css.git"
|
|
||||||
},
|
|
||||||
"author": "Max Brunsfeld",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"nan": "^2.18.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"eslint": ">=5.16.0",
|
|
||||||
"eslint-config-google": "^0.14.0",
|
|
||||||
"tree-sitter-cli": "^0.20.8"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "tree-sitter generate && node-gyp build",
|
|
||||||
"lint": "eslint grammar.js",
|
|
||||||
"parse": "tree-sitter parse",
|
|
||||||
"test": "tree-sitter test && tree-sitter parse examples/*.css --quiet --time",
|
|
||||||
"test-windows": "tree-sitter test"
|
|
||||||
},
|
|
||||||
"tree-sitter": [
|
|
||||||
{
|
|
||||||
"scope": "source.css",
|
|
||||||
"file-types": [
|
|
||||||
"css"
|
|
||||||
],
|
|
||||||
"injection-regex": "^css$",
|
|
||||||
"highlights": [
|
|
||||||
"queries/highlights.scm"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
(comment) @comment
|
|
||||||
|
|
||||||
(tag_name) @tag
|
|
||||||
(nesting_selector) @tag
|
|
||||||
(universal_selector) @tag
|
|
||||||
|
|
||||||
"~" @operator
|
|
||||||
">" @operator
|
|
||||||
"+" @operator
|
|
||||||
"-" @operator
|
|
||||||
"*" @operator
|
|
||||||
"/" @operator
|
|
||||||
"=" @operator
|
|
||||||
"^=" @operator
|
|
||||||
"|=" @operator
|
|
||||||
"~=" @operator
|
|
||||||
"$=" @operator
|
|
||||||
"*=" @operator
|
|
||||||
|
|
||||||
"and" @operator
|
|
||||||
"or" @operator
|
|
||||||
"not" @operator
|
|
||||||
"only" @operator
|
|
||||||
|
|
||||||
(attribute_selector (plain_value) @string)
|
|
||||||
(pseudo_element_selector (tag_name) @attribute)
|
|
||||||
(pseudo_class_selector (class_name) @attribute)
|
|
||||||
|
|
||||||
(class_name) @property
|
|
||||||
(id_name) @property
|
|
||||||
(namespace_name) @property
|
|
||||||
(property_name) @property
|
|
||||||
(feature_name) @property
|
|
||||||
|
|
||||||
(attribute_name) @attribute
|
|
||||||
|
|
||||||
(function_name) @function
|
|
||||||
|
|
||||||
((property_name) @variable
|
|
||||||
(#match? @variable "^--"))
|
|
||||||
((plain_value) @variable
|
|
||||||
(#match? @variable "^--"))
|
|
||||||
|
|
||||||
"@media" @keyword
|
|
||||||
"@import" @keyword
|
|
||||||
"@charset" @keyword
|
|
||||||
"@namespace" @keyword
|
|
||||||
"@supports" @keyword
|
|
||||||
"@keyframes" @keyword
|
|
||||||
(at_keyword) @keyword
|
|
||||||
(to) @keyword
|
|
||||||
(from) @keyword
|
|
||||||
(important) @keyword
|
|
||||||
|
|
||||||
(string_value) @string
|
|
||||||
(color_value) @string.special
|
|
||||||
|
|
||||||
(integer_value) @number
|
|
||||||
(float_value) @number
|
|
||||||
(unit) @type
|
|
||||||
|
|
||||||
"#" @punctuation.delimiter
|
|
||||||
"," @punctuation.delimiter
|
|
||||||
":" @punctuation.delimiter
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,84 +0,0 @@
|
|||||||
#include "tree_sitter/parser.h"
|
|
||||||
|
|
||||||
#include <wctype.h>
|
|
||||||
|
|
||||||
enum TokenType {
|
|
||||||
DESCENDANT_OP,
|
|
||||||
PSEUDO_CLASS_SELECTOR_COLON,
|
|
||||||
ERROR_RECOVERY,
|
|
||||||
};
|
|
||||||
|
|
||||||
static inline void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
|
|
||||||
|
|
||||||
static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
|
|
||||||
|
|
||||||
void *tree_sitter_css_external_scanner_create() { return NULL; }
|
|
||||||
|
|
||||||
void tree_sitter_css_external_scanner_destroy(void *payload) {}
|
|
||||||
|
|
||||||
void tree_sitter_css_external_scanner_reset(void *payload) {}
|
|
||||||
|
|
||||||
unsigned tree_sitter_css_external_scanner_serialize(void *payload, char *buffer) { return 0; }
|
|
||||||
|
|
||||||
void tree_sitter_css_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {}
|
|
||||||
|
|
||||||
bool tree_sitter_css_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
|
|
||||||
if (valid_symbols[ERROR_RECOVERY]) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iswspace(lexer->lookahead) && valid_symbols[DESCENDANT_OP]) {
|
|
||||||
lexer->result_symbol = DESCENDANT_OP;
|
|
||||||
|
|
||||||
lexer->advance(lexer, true);
|
|
||||||
while (iswspace(lexer->lookahead)) {
|
|
||||||
lexer->advance(lexer, true);
|
|
||||||
}
|
|
||||||
lexer->mark_end(lexer);
|
|
||||||
|
|
||||||
if (lexer->lookahead == '#' || lexer->lookahead == '.' || lexer->lookahead == '[' || lexer->lookahead == '-' ||
|
|
||||||
lexer->lookahead == '*' || iswalnum(lexer->lookahead)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lexer->lookahead == ':') {
|
|
||||||
lexer->advance(lexer, false);
|
|
||||||
if (iswspace(lexer->lookahead)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (;;) {
|
|
||||||
if (lexer->lookahead == ';' || lexer->lookahead == '}' || lexer->eof(lexer)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (lexer->lookahead == '{') {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
lexer->advance(lexer, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valid_symbols[PSEUDO_CLASS_SELECTOR_COLON]) {
|
|
||||||
while (iswspace(lexer->lookahead)) {
|
|
||||||
lexer->advance(lexer, true);
|
|
||||||
}
|
|
||||||
if (lexer->lookahead == ':') {
|
|
||||||
advance(lexer);
|
|
||||||
if (lexer->lookahead == ':') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
lexer->mark_end(lexer);
|
|
||||||
// We need a { to be a pseudo class selector, a ; indicates a property
|
|
||||||
while (lexer->lookahead != ';' && lexer->lookahead != '}' && !lexer->eof(lexer)) {
|
|
||||||
advance(lexer);
|
|
||||||
if (lexer->lookahead == '{') {
|
|
||||||
lexer->result_symbol = PSEUDO_CLASS_SELECTOR_COLON;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@ -1,224 +0,0 @@
|
|||||||
#ifndef TREE_SITTER_PARSER_H_
|
|
||||||
#define TREE_SITTER_PARSER_H_
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
|
||||||
#define ts_builtin_sym_end 0
|
|
||||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
|
||||||
|
|
||||||
#ifndef TREE_SITTER_API_H_
|
|
||||||
typedef uint16_t TSStateId;
|
|
||||||
typedef uint16_t TSSymbol;
|
|
||||||
typedef uint16_t TSFieldId;
|
|
||||||
typedef struct TSLanguage TSLanguage;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
TSFieldId field_id;
|
|
||||||
uint8_t child_index;
|
|
||||||
bool inherited;
|
|
||||||
} TSFieldMapEntry;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t index;
|
|
||||||
uint16_t length;
|
|
||||||
} TSFieldMapSlice;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
bool visible;
|
|
||||||
bool named;
|
|
||||||
bool supertype;
|
|
||||||
} 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)(const TSLexer *);
|
|
||||||
bool (*eof)(const TSLexer *);
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
TSParseActionTypeShift,
|
|
||||||
TSParseActionTypeReduce,
|
|
||||||
TSParseActionTypeAccept,
|
|
||||||
TSParseActionTypeRecover,
|
|
||||||
} TSParseActionType;
|
|
||||||
|
|
||||||
typedef union {
|
|
||||||
struct {
|
|
||||||
uint8_t type;
|
|
||||||
TSStateId state;
|
|
||||||
bool extra;
|
|
||||||
bool repetition;
|
|
||||||
} shift;
|
|
||||||
struct {
|
|
||||||
uint8_t type;
|
|
||||||
uint8_t child_count;
|
|
||||||
TSSymbol symbol;
|
|
||||||
int16_t dynamic_precedence;
|
|
||||||
uint16_t production_id;
|
|
||||||
} reduce;
|
|
||||||
uint8_t type;
|
|
||||||
} TSParseAction;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t lex_state;
|
|
||||||
uint16_t external_lex_state;
|
|
||||||
} TSLexMode;
|
|
||||||
|
|
||||||
typedef union {
|
|
||||||
TSParseAction action;
|
|
||||||
struct {
|
|
||||||
uint8_t count;
|
|
||||||
bool reusable;
|
|
||||||
} entry;
|
|
||||||
} TSParseActionEntry;
|
|
||||||
|
|
||||||
struct TSLanguage {
|
|
||||||
uint32_t version;
|
|
||||||
uint32_t symbol_count;
|
|
||||||
uint32_t alias_count;
|
|
||||||
uint32_t token_count;
|
|
||||||
uint32_t external_token_count;
|
|
||||||
uint32_t state_count;
|
|
||||||
uint32_t large_state_count;
|
|
||||||
uint32_t production_id_count;
|
|
||||||
uint32_t field_count;
|
|
||||||
uint16_t max_alias_sequence_length;
|
|
||||||
const uint16_t *parse_table;
|
|
||||||
const uint16_t *small_parse_table;
|
|
||||||
const uint32_t *small_parse_table_map;
|
|
||||||
const TSParseActionEntry *parse_actions;
|
|
||||||
const char * const *symbol_names;
|
|
||||||
const char * const *field_names;
|
|
||||||
const TSFieldMapSlice *field_map_slices;
|
|
||||||
const TSFieldMapEntry *field_map_entries;
|
|
||||||
const TSSymbolMetadata *symbol_metadata;
|
|
||||||
const TSSymbol *public_symbol_map;
|
|
||||||
const uint16_t *alias_map;
|
|
||||||
const TSSymbol *alias_sequences;
|
|
||||||
const TSLexMode *lex_modes;
|
|
||||||
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);
|
|
||||||
void (*destroy)(void *);
|
|
||||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
|
||||||
unsigned (*serialize)(void *, char *);
|
|
||||||
void (*deserialize)(void *, const char *, unsigned);
|
|
||||||
} external_scanner;
|
|
||||||
const TSStateId *primary_state_ids;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Lexer Macros
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define START_LEXER() \
|
|
||||||
bool result = false; \
|
|
||||||
bool skip = false; \
|
|
||||||
bool eof = false; \
|
|
||||||
int32_t lookahead; \
|
|
||||||
goto start; \
|
|
||||||
next_state: \
|
|
||||||
lexer->advance(lexer, skip); \
|
|
||||||
start: \
|
|
||||||
skip = false; \
|
|
||||||
lookahead = lexer->lookahead; \
|
|
||||||
eof = lexer->eof(lexer);
|
|
||||||
|
|
||||||
#define ADVANCE(state_value) \
|
|
||||||
{ \
|
|
||||||
state = state_value; \
|
|
||||||
goto next_state; \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SKIP(state_value) \
|
|
||||||
{ \
|
|
||||||
skip = 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 SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
|
|
||||||
|
|
||||||
#define STATE(id) id
|
|
||||||
|
|
||||||
#define ACTIONS(id) id
|
|
||||||
|
|
||||||
#define SHIFT(state_value) \
|
|
||||||
{{ \
|
|
||||||
.shift = { \
|
|
||||||
.type = TSParseActionTypeShift, \
|
|
||||||
.state = (state_value) \
|
|
||||||
} \
|
|
||||||
}}
|
|
||||||
|
|
||||||
#define SHIFT_REPEAT(state_value) \
|
|
||||||
{{ \
|
|
||||||
.shift = { \
|
|
||||||
.type = TSParseActionTypeShift, \
|
|
||||||
.state = (state_value), \
|
|
||||||
.repetition = true \
|
|
||||||
} \
|
|
||||||
}}
|
|
||||||
|
|
||||||
#define SHIFT_EXTRA() \
|
|
||||||
{{ \
|
|
||||||
.shift = { \
|
|
||||||
.type = TSParseActionTypeShift, \
|
|
||||||
.extra = true \
|
|
||||||
} \
|
|
||||||
}}
|
|
||||||
|
|
||||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
|
||||||
{{ \
|
|
||||||
.reduce = { \
|
|
||||||
.type = TSParseActionTypeReduce, \
|
|
||||||
.symbol = symbol_val, \
|
|
||||||
.child_count = child_count_val, \
|
|
||||||
__VA_ARGS__ \
|
|
||||||
}, \
|
|
||||||
}}
|
|
||||||
|
|
||||||
#define RECOVER() \
|
|
||||||
{{ \
|
|
||||||
.type = TSParseActionTypeRecover \
|
|
||||||
}}
|
|
||||||
|
|
||||||
#define ACCEPT_INPUT() \
|
|
||||||
{{ \
|
|
||||||
.type = TSParseActionTypeAccept \
|
|
||||||
}}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // TREE_SITTER_PARSER_H_
|
|
||||||
@ -1,333 +0,0 @@
|
|||||||
==========================
|
|
||||||
Function calls
|
|
||||||
==========================
|
|
||||||
|
|
||||||
a {
|
|
||||||
color: rgba(0, 255, 0, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration
|
|
||||||
(property_name)
|
|
||||||
(call_expression (function_name) (arguments
|
|
||||||
(integer_value)
|
|
||||||
(integer_value)
|
|
||||||
(integer_value)
|
|
||||||
(float_value)))))))
|
|
||||||
|
|
||||||
=============================================
|
|
||||||
Calls where each argument has multiple values
|
|
||||||
=============================================
|
|
||||||
|
|
||||||
div {
|
|
||||||
background: repeating-linear-gradient(red, orange 50px);
|
|
||||||
clip-path: polygon(50% 0%, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0% 50%, 40% 40%);
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set (selectors (tag_name)) (block
|
|
||||||
(declaration
|
|
||||||
(property_name)
|
|
||||||
(call_expression (function_name) (arguments
|
|
||||||
(plain_value)
|
|
||||||
(plain_value)
|
|
||||||
(integer_value (unit)))))
|
|
||||||
(declaration
|
|
||||||
(property_name)
|
|
||||||
(call_expression (function_name) (arguments
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))))))))
|
|
||||||
|
|
||||||
============================
|
|
||||||
Color literals
|
|
||||||
============================
|
|
||||||
|
|
||||||
a {
|
|
||||||
b: #fafd04;
|
|
||||||
c: #fafd0401;
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (color_value))
|
|
||||||
(declaration (property_name) (color_value)))))
|
|
||||||
|
|
||||||
============================
|
|
||||||
Numbers
|
|
||||||
============================
|
|
||||||
|
|
||||||
a {
|
|
||||||
b: 0.5%;
|
|
||||||
c: 5em;
|
|
||||||
margin: 10E3px;
|
|
||||||
margin: -456.8px;
|
|
||||||
margin: -5px;
|
|
||||||
margin: -0.0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set (selectors (tag_name)) (block
|
|
||||||
(declaration (property_name) (float_value (unit)))
|
|
||||||
(declaration (property_name) (integer_value (unit)))
|
|
||||||
(declaration (property_name) (float_value (unit)))
|
|
||||||
(declaration (property_name) (float_value (unit)))
|
|
||||||
(declaration (property_name) (integer_value (unit)))
|
|
||||||
(declaration (property_name) (float_value (unit))))))
|
|
||||||
|
|
||||||
============================
|
|
||||||
Binary arithmetic operators
|
|
||||||
============================
|
|
||||||
|
|
||||||
a {
|
|
||||||
width: calc(100% - 80px);
|
|
||||||
aspect-ratio: 1/2;
|
|
||||||
font-size: calc(10px + (56 - 10) * ((100vw - 320px) / (1920 - 320)));
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration
|
|
||||||
(property_name)
|
|
||||||
(call_expression (function_name) (arguments (binary_expression (integer_value (unit)) (integer_value (unit))))))
|
|
||||||
(declaration
|
|
||||||
(property_name)
|
|
||||||
(binary_expression (integer_value) (integer_value)))
|
|
||||||
(declaration
|
|
||||||
(property_name)
|
|
||||||
(call_expression
|
|
||||||
(function_name)
|
|
||||||
(arguments
|
|
||||||
(binary_expression
|
|
||||||
(binary_expression
|
|
||||||
(integer_value (unit))
|
|
||||||
(parenthesized_value (binary_expression (integer_value) (integer_value))))
|
|
||||||
(parenthesized_value
|
|
||||||
(binary_expression
|
|
||||||
(parenthesized_value (binary_expression (integer_value (unit)) (integer_value (unit))))
|
|
||||||
(parenthesized_value (binary_expression (integer_value) (integer_value))))))))))))
|
|
||||||
|
|
||||||
============================
|
|
||||||
Strings
|
|
||||||
============================
|
|
||||||
|
|
||||||
a {
|
|
||||||
b: '';
|
|
||||||
c: '\'hi\'';
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (string_value))
|
|
||||||
(declaration (property_name) (string_value)))))
|
|
||||||
|
|
||||||
============================
|
|
||||||
URLs
|
|
||||||
============================
|
|
||||||
|
|
||||||
a {
|
|
||||||
b: http://something-else?foo=bar;
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (plain_value)))))
|
|
||||||
|
|
||||||
============================
|
|
||||||
Important declarations
|
|
||||||
============================
|
|
||||||
|
|
||||||
a {
|
|
||||||
b: c !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (plain_value) (important)))))
|
|
||||||
|
|
||||||
============================
|
|
||||||
Declarations without trailing semicolons
|
|
||||||
============================
|
|
||||||
|
|
||||||
a {
|
|
||||||
b: c;
|
|
||||||
d: e
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (plain_value))
|
|
||||||
(declaration (property_name) (plain_value)))))
|
|
||||||
|
|
||||||
=======================================
|
|
||||||
Comments right after numbers
|
|
||||||
=======================================
|
|
||||||
|
|
||||||
// A comment
|
|
||||||
a {
|
|
||||||
shape-outside: circle(20em/*=*/at 50% 50%);
|
|
||||||
shape-outside: inset(1em, 1em, 1em, 1em);
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(js_comment)
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (call_expression (function_name) (arguments
|
|
||||||
(integer_value (unit))
|
|
||||||
(comment)
|
|
||||||
(plain_value)
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit)))))
|
|
||||||
(declaration (property_name) (call_expression (function_name) (arguments
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))
|
|
||||||
(integer_value (unit))))))))
|
|
||||||
|
|
||||||
=================================
|
|
||||||
Declarations at the top level
|
|
||||||
=================================
|
|
||||||
|
|
||||||
--a-variable: -5px;
|
|
||||||
a-property: calc(5px + var(--a-variable));
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(declaration (property_name) (integer_value (unit)))
|
|
||||||
(declaration (property_name) (call_expression (function_name) (arguments (binary_expression (integer_value (unit)) (call_expression (function_name) (arguments (plain_value))))))))
|
|
||||||
|
|
||||||
=============================================
|
|
||||||
Spaces after colons in property declarations
|
|
||||||
=============================================
|
|
||||||
|
|
||||||
div {
|
|
||||||
margin : 0;
|
|
||||||
padding : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors
|
|
||||||
(tag_name))
|
|
||||||
(block
|
|
||||||
(declaration
|
|
||||||
(property_name)
|
|
||||||
(integer_value))
|
|
||||||
(declaration
|
|
||||||
(property_name)
|
|
||||||
(integer_value)))))
|
|
||||||
|
|
||||||
=============================================
|
|
||||||
No spaces after colons
|
|
||||||
=============================================
|
|
||||||
|
|
||||||
div {
|
|
||||||
all:unset;
|
|
||||||
display:flex;
|
|
||||||
justify-content:center;
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (plain_value))
|
|
||||||
(declaration (property_name) (plain_value))
|
|
||||||
(declaration (property_name) (plain_value)))))
|
|
||||||
|
|
||||||
=============================================
|
|
||||||
PostCSS
|
|
||||||
=============================================
|
|
||||||
|
|
||||||
.selector {
|
|
||||||
@apply variable-a meta-variable-b lots-of-combined-properties-c !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
@layer components {
|
|
||||||
.btn-blue {
|
|
||||||
@apply --mixin sm:space-x-0 left-[11%] border-foreground/20 !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (class_selector (class_name)))
|
|
||||||
(block
|
|
||||||
(postcss_statement
|
|
||||||
(at_keyword)
|
|
||||||
(plain_value)
|
|
||||||
(plain_value)
|
|
||||||
(plain_value)
|
|
||||||
(important))))
|
|
||||||
(at_rule
|
|
||||||
(at_keyword)
|
|
||||||
(keyword_query)
|
|
||||||
(block
|
|
||||||
(rule_set
|
|
||||||
(selectors (class_selector (class_name)))
|
|
||||||
(block
|
|
||||||
(postcss_statement
|
|
||||||
(at_keyword)
|
|
||||||
(plain_value)
|
|
||||||
(plain_value)
|
|
||||||
(plain_value)
|
|
||||||
(grid_value (integer_value (unit)))
|
|
||||||
(plain_value)
|
|
||||||
(important)))))))
|
|
||||||
@ -1,226 +0,0 @@
|
|||||||
=========================
|
|
||||||
Universal selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
* {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set (selectors (universal_selector)) (block)))
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Type selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
div, span {}
|
|
||||||
h1, h2, h3, h4 {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set (selectors (tag_name) (tag_name)) (block))
|
|
||||||
(rule_set (selectors (tag_name) (tag_name) (tag_name) (tag_name)) (block)))
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Class selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
.class-a {}
|
|
||||||
div.class-b, .class-c.class-d {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (class_selector (class_name)))
|
|
||||||
(block))
|
|
||||||
(rule_set
|
|
||||||
(selectors
|
|
||||||
(class_selector (tag_name) (class_name))
|
|
||||||
(class_selector (class_selector (class_name)) (class_name)))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Id selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
#some-id, a#another-id {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (id_selector (id_name)) (id_selector (tag_name) (id_name)))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Attribute selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
[a] {}
|
|
||||||
[b=c] {}
|
|
||||||
[d~=e] {}
|
|
||||||
a[b] {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set (selectors (attribute_selector (attribute_name))) (block))
|
|
||||||
(rule_set (selectors (attribute_selector (attribute_name) (plain_value))) (block))
|
|
||||||
(rule_set (selectors (attribute_selector (attribute_name) (plain_value))) (block))
|
|
||||||
(rule_set (selectors (attribute_selector (tag_name) (attribute_name))) (block)))
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Pseudo-class selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
a:hover {}
|
|
||||||
:nth-child(2) {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (pseudo_class_selector (tag_name) (class_name)))
|
|
||||||
(block))
|
|
||||||
(rule_set
|
|
||||||
(selectors (pseudo_class_selector (class_name) (arguments (integer_value))))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Pseudo-element selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
a::first-line {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (pseudo_element_selector (tag_name) (tag_name)))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
=========================
|
|
||||||
::slotted pseudo element
|
|
||||||
=========================
|
|
||||||
|
|
||||||
::slotted(button) {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (pseudo_element_selector (tag_name)
|
|
||||||
(arguments (tag_name))))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Child selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
a > b {}
|
|
||||||
c > d > e {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (child_selector (tag_name) (tag_name)))
|
|
||||||
(block))
|
|
||||||
(rule_set
|
|
||||||
(selectors (child_selector
|
|
||||||
(child_selector (tag_name) (tag_name))
|
|
||||||
(tag_name)))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
=========================
|
|
||||||
Descendant selectors
|
|
||||||
=========================
|
|
||||||
|
|
||||||
a b {}
|
|
||||||
c d e {}
|
|
||||||
f * {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (descendant_selector (tag_name) (tag_name)))
|
|
||||||
(block))
|
|
||||||
(rule_set
|
|
||||||
(selectors (descendant_selector
|
|
||||||
(descendant_selector (tag_name) (tag_name))
|
|
||||||
(tag_name)))
|
|
||||||
(block))
|
|
||||||
(rule_set
|
|
||||||
(selectors
|
|
||||||
(descendant_selector
|
|
||||||
(tag_name)
|
|
||||||
(universal_selector)))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
===========================
|
|
||||||
Nesting selectors
|
|
||||||
===========================
|
|
||||||
|
|
||||||
a {
|
|
||||||
&.b {}
|
|
||||||
& c {}
|
|
||||||
& > d {}
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (tag_name))
|
|
||||||
(block
|
|
||||||
(rule_set (selectors (class_selector (nesting_selector) (class_name))) (block))
|
|
||||||
(rule_set (selectors (descendant_selector (nesting_selector) (tag_name))) (block))
|
|
||||||
(rule_set (selectors (child_selector (nesting_selector) (tag_name))) (block)))))
|
|
||||||
|
|
||||||
===========================
|
|
||||||
Sibling selectors
|
|
||||||
===========================
|
|
||||||
|
|
||||||
a.b ~ c.d {}
|
|
||||||
.e.f + .g.h {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (sibling_selector
|
|
||||||
(class_selector (tag_name) (class_name))
|
|
||||||
(class_selector (tag_name) (class_name))))
|
|
||||||
(block))
|
|
||||||
(rule_set
|
|
||||||
(selectors (adjacent_sibling_selector
|
|
||||||
(class_selector (class_selector (class_name)) (class_name))
|
|
||||||
(class_selector (class_selector (class_name)) (class_name))))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
===========================
|
|
||||||
The :not selector
|
|
||||||
===========================
|
|
||||||
|
|
||||||
a:not(:hover) {}
|
|
||||||
.b:not(c > .d) {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (pseudo_class_selector
|
|
||||||
(tag_name)
|
|
||||||
(class_name)
|
|
||||||
(arguments (pseudo_class_selector (class_name)))))
|
|
||||||
(block))
|
|
||||||
(rule_set
|
|
||||||
(selectors (pseudo_class_selector
|
|
||||||
(class_selector (class_name))
|
|
||||||
(class_name)
|
|
||||||
(arguments (child_selector (tag_name) (class_selector (class_name))))))
|
|
||||||
(block)))
|
|
||||||
@ -1,170 +0,0 @@
|
|||||||
==============================
|
|
||||||
Import statements
|
|
||||||
==============================
|
|
||||||
|
|
||||||
@import url("fineprint.css") print;
|
|
||||||
@import url("bluish.css") speech;
|
|
||||||
@import 'custom.css';
|
|
||||||
@import url("chrome://communicator/skin/");
|
|
||||||
@import "common.css" screen;
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(import_statement (call_expression (function_name) (arguments (string_value))) (keyword_query))
|
|
||||||
(import_statement (call_expression (function_name) (arguments (string_value))) (keyword_query))
|
|
||||||
(import_statement (string_value))
|
|
||||||
(import_statement (call_expression (function_name) (arguments (string_value))))
|
|
||||||
(import_statement (string_value) (keyword_query)))
|
|
||||||
|
|
||||||
==============================
|
|
||||||
Namespace statements
|
|
||||||
==============================
|
|
||||||
|
|
||||||
/* Default namespace */
|
|
||||||
@namespace url(XML-namespace-URL);
|
|
||||||
@namespace "XML-namespace-URL";
|
|
||||||
@namespace url(http://www.w3.org/1999/xhtml);
|
|
||||||
@namespace svg url(http://www.w3.org/2000/svg);
|
|
||||||
|
|
||||||
/* Prefixed namespace */
|
|
||||||
@namespace prefix url(XML-namespace-URL);
|
|
||||||
@namespace prefix "XML-namespace-URL";
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(comment)
|
|
||||||
(namespace_statement (call_expression (function_name) (arguments (plain_value))))
|
|
||||||
(namespace_statement (string_value))
|
|
||||||
(namespace_statement (call_expression (function_name) (arguments (plain_value))))
|
|
||||||
(namespace_statement (namespace_name) (call_expression (function_name) (arguments (plain_value))))
|
|
||||||
(comment)
|
|
||||||
(namespace_statement (namespace_name) (call_expression (function_name) (arguments (plain_value))))
|
|
||||||
(namespace_statement (namespace_name) (string_value)))
|
|
||||||
|
|
||||||
==============================
|
|
||||||
Keyframes statements
|
|
||||||
==============================
|
|
||||||
|
|
||||||
@keyframes important1 {
|
|
||||||
from { margin-top: 50px; }
|
|
||||||
50% { margin-top: 150px !important; } /* ignored */
|
|
||||||
to { margin-top: 100px; }
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(keyframes_statement (keyframes_name) (keyframe_block_list
|
|
||||||
(keyframe_block (from) (block (declaration (property_name) (integer_value (unit)))))
|
|
||||||
(keyframe_block (integer_value (unit)) (block (declaration (property_name) (integer_value (unit)) (important))))
|
|
||||||
(comment)
|
|
||||||
(keyframe_block (to) (block (declaration (property_name) (integer_value (unit))))))))
|
|
||||||
|
|
||||||
==============================
|
|
||||||
Media statements
|
|
||||||
==============================
|
|
||||||
|
|
||||||
@media screen and (min-width: 30em) and (orientation: landscape) {}
|
|
||||||
@media (min-height: 680px), screen and (orientation: portrait) {}
|
|
||||||
@media not all and (monochrome) {}
|
|
||||||
@media only screen {}
|
|
||||||
@media screen and (min-width: 0 0) {
|
|
||||||
.tooltipped-multiline: after {}
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(media_statement
|
|
||||||
(binary_query
|
|
||||||
(binary_query
|
|
||||||
(keyword_query)
|
|
||||||
(feature_query (feature_name) (integer_value (unit))))
|
|
||||||
(feature_query (feature_name) (plain_value)))
|
|
||||||
(block))
|
|
||||||
(media_statement
|
|
||||||
(feature_query (feature_name) (integer_value (unit)))
|
|
||||||
(binary_query (keyword_query) (feature_query (feature_name) (plain_value)))
|
|
||||||
(block))
|
|
||||||
(media_statement
|
|
||||||
(binary_query (unary_query (keyword_query)) (parenthesized_query (keyword_query)))
|
|
||||||
(block))
|
|
||||||
(media_statement (unary_query (keyword_query)) (block))
|
|
||||||
(media_statement
|
|
||||||
(binary_query
|
|
||||||
(keyword_query)
|
|
||||||
(feature_query (feature_name) (integer_value) (integer_value)))
|
|
||||||
(block
|
|
||||||
(rule_set
|
|
||||||
(selectors (pseudo_class_selector (class_selector (class_name)) (class_name)))
|
|
||||||
(block)))))
|
|
||||||
|
|
||||||
==============================
|
|
||||||
Supports statements
|
|
||||||
==============================
|
|
||||||
|
|
||||||
@supports (animation-name: test) {
|
|
||||||
div { animation-name: test; }
|
|
||||||
}
|
|
||||||
@supports (transform-style: preserve) or (-moz-transform-style: preserve) {}
|
|
||||||
@supports not ((text-align-last: justify) or (-moz-text-align-last: justify)) {}
|
|
||||||
@supports not selector(:matches(a, b)) {}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(supports_statement
|
|
||||||
(feature_query (feature_name) (plain_value))
|
|
||||||
(block
|
|
||||||
(rule_set (selectors (tag_name)) (block
|
|
||||||
(declaration (property_name) (plain_value))))))
|
|
||||||
(supports_statement
|
|
||||||
(binary_query
|
|
||||||
(feature_query (feature_name) (plain_value))
|
|
||||||
(feature_query (feature_name) (plain_value)))
|
|
||||||
(block))
|
|
||||||
(supports_statement
|
|
||||||
(unary_query (parenthesized_query (binary_query
|
|
||||||
(feature_query (feature_name) (plain_value))
|
|
||||||
(feature_query (feature_name) (plain_value)))))
|
|
||||||
(block))
|
|
||||||
(supports_statement
|
|
||||||
(unary_query (selector_query (pseudo_class_selector
|
|
||||||
(class_name)
|
|
||||||
(arguments (tag_name) (tag_name)))))
|
|
||||||
(block)))
|
|
||||||
|
|
||||||
==============================
|
|
||||||
Charset statements
|
|
||||||
==============================
|
|
||||||
|
|
||||||
@charset "utf-8";
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(charset_statement (string_value)))
|
|
||||||
|
|
||||||
==============================
|
|
||||||
Other at-statements
|
|
||||||
==============================
|
|
||||||
|
|
||||||
@font-face {
|
|
||||||
font-family: "Open Sans";
|
|
||||||
src: url("/a") format("woff2"), url("/b/c") format("woff");
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(at_rule
|
|
||||||
(at_keyword)
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (string_value))
|
|
||||||
(declaration (property_name)
|
|
||||||
(call_expression (function_name) (arguments (string_value)))
|
|
||||||
(call_expression (function_name) (arguments (string_value)))
|
|
||||||
(call_expression (function_name) (arguments (string_value)))
|
|
||||||
(call_expression (function_name) (arguments (string_value)))))))
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
============================
|
|
||||||
Rule sets
|
|
||||||
============================
|
|
||||||
|
|
||||||
#some-id {
|
|
||||||
some-property: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
(stylesheet
|
|
||||||
(rule_set
|
|
||||||
(selectors (id_selector (id_name)))
|
|
||||||
(block
|
|
||||||
(declaration (property_name) (integer_value (unit))))))
|
|
||||||
Loading…
Reference in New Issue