Skip to content

Commit

Permalink
feat: move delimiter parsing to the scanner
Browse files Browse the repository at this point in the history
Co-Authored-By: ObserverOfTime <[email protected]>
  • Loading branch information
amaanq and ObserverOfTime committed Mar 5, 2024
1 parent 3301ff2 commit 3414d99
Show file tree
Hide file tree
Showing 17 changed files with 1,426 additions and 777 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,20 @@ jobs:
uses: tree-sitter/[email protected]
with:
node-version: ${{vars.NODE_VERSION}}
- name: Check for scanner changes
uses: tj-actions/changed-files@v42
id: scanner-check
if: runner.os == 'Linux'
with:
files: src/scanner.c
- name: Fuzz scanner
uses: tree-sitter/fuzz-action@v4
if: steps.scanner-check.outputs.any_changed == 'true'
with:
corpus: examples
- name: Run tests
uses: tree-sitter/[email protected]
with:
test-library: ${{runner.os == 'Linux'}}
corpus-files: examples/*
invalid-files: examples/invalid.tst
1 change: 1 addition & 0 deletions Package.swift

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

1 change: 1 addition & 0 deletions binding.gyp

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

1 change: 1 addition & 0 deletions bindings/go/binding.go

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

4 changes: 4 additions & 0 deletions bindings/rust/build.rs

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

17 changes: 17 additions & 0 deletions bindings/rust/lib.rs

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

39 changes: 39 additions & 0 deletions examples/attributes.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
=========================
Test that will be skipped
:skip
=========================

int main() {}

-------------------------

====================================
Test that will run on Linux or macOS

:platform(linux)
:platform(macos)
====================================

int main() {}

------------------------------------

========================================================================
Test that expects an error, and will fail fast if there's no parse error
:fail-fast
:error
========================================================================

int main ( {}

------------------------------------------------------------------------

=================================================
Test that will parse with both Typescript and TSX
:language(typescript)
:language(tsx)
=================================================

console.log('Hello, world!');

-------------------------------------------------
9 changes: 9 additions & 0 deletions examples/invalid.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
==================|||
Invalid suffix
==================|||

foo

---||

(foo)
17 changes: 17 additions & 0 deletions examples/simple.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
==================
Return statements
==================

func x() int {
return 1;
}

---

(source_file
(function_definition
(identifier)
(parameter_list)
(primitive_type)
(block
(return_statement (number)))))
15 changes: 15 additions & 0 deletions examples/suffix.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
==================|||
Basic module
==================|||

---- MODULE Test ----
increment(n) == n + 1
====

---|||

(source_file
(module (identifier)
(operator (identifier)
(parameter_list (identifier))
(plus (identifier_ref) (number)))))
76 changes: 40 additions & 36 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,69 @@
/// <reference types="./types/dsl" />
// @ts-check

const I = token.immediate;

module.exports = grammar({
name: "test",

extras: _ => [/\r?\n/],
externals: $ => [
$._equals_begin,
$._equals_end,
$._dashes,
],

extras: _ => [],

rules: {
file: $ => repeat($.test),
file: $ => repeat(
choice($.test, $._eol)
),

test: $ => seq(
test: $ => prec.right(seq(
$.header,
alias(repeat1(/./), $.input),
alias($._body, $.input),
alias($._dashes, $.separator),
alias(repeat(/./), $.output)
),
optional(alias($._body, $.output)),
)),

_line: _ => /[^\r\n]+/,

_body: $ => repeat1(choice($._line, $._eol)),

header: $ => seq(
alias($._equals, $.separator),
alias(repeat1(/[^\r\n]/), $.name),
alias($._equals_begin, $.separator),
alias($._line, $.name),
optional($.attributes),
alias($._equals, $.separator)
alias($._equals_end, $.separator),
),

attributes: $ => repeat1(
field("attribute", choice(
$.skip,
$.error,
$.fail_fast,
$.language,
$.platform,
))
choice($.attribute, $._eol)
),

skip: _ => ":skip",

error: _ => ":error",

fail_fast: _ => ":fail-fast",
attribute: $ => choice(
":skip",
":error",
":fail-fast",
$._language,
$._platform,
),

language: $ => seq(
_language: $ => seq(
":language",
I("("),
alias($._lang, $.parameter),
I(")")
"(",
field("language", alias($._lang, $.parameter)),
")"
),

platform: $ => seq(
_platform: $ => seq(
":platform",
I("("),
alias($._os, $.parameter),
I(")")
"(",
field("platform", alias($._os, $.parameter)),
")"
),

_lang: _ => I(repeat1(/[\w.-]/)),
_lang: _ => token(repeat1(/[\w.-]/)),

_os: _ => I(choice(
_os: _ => token(choice(
"linux",
"macos",
"ios",
Expand All @@ -70,8 +76,6 @@ module.exports = grammar({
"windows",
)),

_equals: $ => token(prec(1, repeat1("="))),

_dashes: $ => token(prec(1, seq("---", repeat("-"))))
_eol: _ => /[\r\n]|\r\n/
}
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
{
"scope": "text.test",
"highlights": "queries/highlights.scm",
"injections": "queries/injections.scm"
"injections": "queries/injections.scm",
"file-types": ["tst"]
}
]
}
1 change: 1 addition & 0 deletions setup.py

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

Loading

0 comments on commit 3414d99

Please sign in to comment.