Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Enhanced the syntax support (WIP) #1

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
5cdbbac
Fix: upgrade tree-sitter generate output
zealot128 Jul 10, 2021
c068c0b
Feat: Enhance parser rules
zealot128 Jul 10, 2021
7679f9a
CI: Add Github Action, Readme, missing source files
zealot128 Jul 13, 2021
5875f9a
Feat: Doctype + Multiline content with dot
zealot128 Jul 13, 2021
4e1f7c9
fix: try to avoid segfaults in scanner.cc
theHamsta Apr 30, 2022
23eba6f
Merge pull request #1 from theHamsta/avoid-segfault
zealot128 May 5, 2022
63e2149
Fix: Fix most of tests by setting associativity
zealot128 May 5, 2022
f028424
Feat: angular square bracket attributes
mclaughlinconnor Aug 7, 2022
c2614e0
Feat: angular outputs with javascript
mclaughlinconnor Aug 7, 2022
ea362b8
Feat: angular directives
mclaughlinconnor Aug 7, 2022
e280d15
Feat: unbuffered javascript code support
mclaughlinconnor Aug 8, 2022
b49b341
Fix: injections not working with new javascript
mclaughlinconnor Aug 8, 2022
19180c9
Fix: remove unused $ variables
mclaughlinconnor Aug 8, 2022
98b5088
Feat: add conditionals
mclaughlinconnor Aug 8, 2022
57c6984
Fix: actually include injections
mclaughlinconnor Aug 8, 2022
8ba0699
Fix: make all javascript nodes look like $.javascript
mclaughlinconnor Aug 10, 2022
c4d9f6a
Feat: add non-angular javascript attributes for non-functions only
mclaughlinconnor Aug 11, 2022
88e0d01
Fix: fix not handling tags inside of unbuffered code properly
mclaughlinconnor Aug 18, 2022
113e0d0
Feat: add buffered code
mclaughlinconnor Aug 19, 2022
e764a07
Feat: unescaped buffered code
mclaughlinconnor Aug 19, 2022
070733e
Feat: case statements
mclaughlinconnor Aug 19, 2022
2f61832
Fix: fix pipes not being treated as root nodes, also gave better name
mclaughlinconnor Aug 19, 2022
697c464
Feat: add code attributes for non-Angular attributes
mclaughlinconnor Aug 20, 2022
01ef1d1
Fix: add missing javascript alias for angular interpolations
mclaughlinconnor Aug 21, 2022
a2a292d
Fix: fix first character of attribute not being included in $.javascript
mclaughlinconnor Aug 21, 2022
a6155ca
Feat: allow one level of function calls in pug javascript attributes
mclaughlinconnor Aug 21, 2022
83b0de9
Feat: add pug javascript interpolation
mclaughlinconnor Aug 21, 2022
14afe9d
Fix: allow hash tags and brackets in tag content
mclaughlinconnor Aug 21, 2022
5ecff5d
Fix: allow dot being on newline for content
mclaughlinconnor Aug 22, 2022
034c32b
Feat: add javascript inside of script dot blocks
mclaughlinconnor Aug 22, 2022
0cad251
Fix: fix dedent not being handled on end of unbuffered code breaking …
mclaughlinconnor Aug 22, 2022
d69283f
Fix: strip trailing whitespace from source
mclaughlinconnor Dec 15, 2022
1c99974
Fix: fix conditionals in tags sometimes being booted to the root
mclaughlinconnor Dec 15, 2022
7c72d1f
Fix: fix comments following unbuffered js breaking
mclaughlinconnor Dec 15, 2022
6c30f3d
Fix: fix conditionals being merged together with errors
mclaughlinconnor Dec 16, 2022
5c80bb9
Docs: add todos for angular templates and standalone class components
mclaughlinconnor Dec 16, 2022
f25c05a
Feat: support angular template attributes
mclaughlinconnor Dec 16, 2022
5c7d7b6
Fix: remove useless precedence on tag
mclaughlinconnor Dec 16, 2022
f130e69
Fix: fix conditional statements being a bit enthusiastic about how mu…
mclaughlinconnor Dec 16, 2022
282438a
Fix: fix case statements not finishing their captures in the right place
mclaughlinconnor Dec 17, 2022
a175593
Fix: fix comments starting after the first line being limited to one …
mclaughlinconnor Dec 17, 2022
8ddc893
Docs: add many more todos
mclaughlinconnor Dec 17, 2022
d9d378b
Fix: fix consecutive dedents being merged together
mclaughlinconnor Dec 18, 2022
d3d4fef
Fix: remove commented code from scanner
mclaughlinconnor Dec 18, 2022
2a6abd4
Lint: reformat $.children across multiple lines
mclaughlinconnor Dec 18, 2022
a298ab0
Docs: the $._dedent is absolutely needed here
mclaughlinconnor Dec 18, 2022
8761d26
Feat: parse Angular attributes with dots in them properly
mclaughlinconnor Dec 18, 2022
04e0b9e
Build: add log.html to gitignore
mclaughlinconnor Dec 18, 2022
82248cb
Fix: fix broken pipe test with expected failure
mclaughlinconnor Dec 18, 2022
2163d2e
Fix: remove useless injection queries
mclaughlinconnor Dec 18, 2022
ba017b7
Feat: add self-closing tags
mclaughlinconnor Dec 18, 2022
538de8f
Feat: add filters
mclaughlinconnor Dec 18, 2022
589d132
Docs: update readme with current state
mclaughlinconnor Dec 18, 2022
2d9f925
Docs: remove todos fixed by repairing dedents
mclaughlinconnor Dec 18, 2022
739462a
Feat: add template inheritance
mclaughlinconnor Dec 18, 2022
9161427
Lint: remove a few extra unused $'s
mclaughlinconnor Dec 18, 2022
535e59e
Feat: add mixins
mclaughlinconnor Dec 19, 2022
ea3d9d0
Feat: add iterators
mclaughlinconnor Dec 20, 2022
6be1371
Fix: remove colons from tag name supported characters
mclaughlinconnor Dec 20, 2022
d97918b
Fix: allow slashes and other non-alphanumerics in extend filenames
mclaughlinconnor Dec 20, 2022
f455fbc
Feat: add includes
mclaughlinconnor Dec 20, 2022
f1774d0
Fix: fix comments not ending after dedents
mclaughlinconnor Dec 21, 2022
66f77e8
Fix: fix newlines inside dot continues causing the next dedent to be …
mclaughlinconnor Dec 21, 2022
500831d
Chore: add keyword alias to all keywords to prepare for highlighting
mclaughlinconnor Dec 20, 2022
8a1e143
Chore: bump tree-sitter-cli to 0.20.7
mclaughlinconnor Dec 21, 2022
81f89bf
Feat: add syntax highlighting queries
mclaughlinconnor Dec 21, 2022
90b13ba
Docs: reword readme to be more inclusive of non-angular developers
mclaughlinconnor Jan 14, 2023
95bdfdb
Merge pull request #6 from mclaughlinconnor/readme_reword
mclaughlinconnor Jan 14, 2023
148608f
Merge pull request #4 from Pug-Angular-Editor-Tools/master
zealot128 Jan 15, 2023
26a8250
Fix: add angular two way binding support
mclaughlinconnor Jan 5, 2023
0baa245
Docs: add todo for angular template directive bindings
mclaughlinconnor Jan 5, 2023
550afac
Docs: add some thoughts about nested function calls in pug js attributes
mclaughlinconnor Jan 5, 2023
0ae4867
Docs: add todo to rework regexes
mclaughlinconnor Jan 5, 2023
26f6ac8
Merge pull request #5 from Pug-Angular-Editor-Tools/bananabox
zealot128 Jan 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

name: build

on:
push:
pull_request:
branches:
- "**" # Don't trust forks because miners

jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm install
- run: npm test

4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
node_modules/
bindings/
build/
pug.so
src/parser.c
src/grammar.json
log.html
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 14.15.1
59 changes: 59 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# tree-sitter-pug
# Tree-sitter-pug

**WARNING** This parser is incomplete and in it's very early stages. Will most likely break if you attempt to use it on any real code.
This is a general tree-sitter parser grammar for the [pug](https://github.com/pugjs/pug) language with some extra features built in for Angular and Vue development.

## Current state

Everything currently included is relatively bug-free, but the structure/name of some rules may change before we declare this parser "complete".

There is list of todos at the top of `grammar.js`, but the summary is: all of the basics are supported.
There are tests for every scenario supported, so you can just have a look through `./test/corpus/*.txt` to see exactly which scenarios are supported and have been tested.

Feel free to open an issue/pull request if there's something missing/broken.

## Developing

How to run & test:

```
npm install -g tree-sitter-cli
tree-sitter generate && tree-sitter test
```

This is a tree-sitter parser for the [pug](https://github.com/pugjs/pug) language.
For now this is intended to be used for a vue+pug setup, as the control flow operations aren't recognized by the parser (since they are not used in conjunction with vue).
28 changes: 28 additions & 0 deletions bindings/node/binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"

using namespace v8;

extern "C" TSLanguage * tree_sitter_pug();

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_pug());

Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("pug").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}

NODE_MODULE(tree_sitter_pug_binding, Init)

} // namespace
19 changes: 19 additions & 0 deletions bindings/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
try {
module.exports = require("../../build/Release/tree_sitter_pug_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_pug_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}

try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}
40 changes: 40 additions & 0 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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);

// If your language uses an external scanner written in C,
// then include this block of code:

/*
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());

// If your language uses an external scanner written in C++,
// then include this block of code:

/*
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
}
52 changes: 52 additions & 0 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! This crate provides pug 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_pug::language()).expect("Error loading pug 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_pug() -> 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_pug() }
}

/// 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: &'static str = include_str!("../../src/node-types.json");

// Uncomment these to include any queries that this grammar contains

pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.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 pug language");
}
}
Loading