init
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
package-lock.json
|
||||
Cargo.lock
|
||||
target
|
26
Cargo.toml
Normal file
26
Cargo.toml
Normal file
@@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "tree-sitter-lila"
|
||||
description = "Lila grammar for the tree-sitter parsing library"
|
||||
version = "0.0.1"
|
||||
keywords = ["incremental", "parsing", "lila"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://git.sr.ht/~rpqt/tree-sitter-lila"
|
||||
edition = "2018"
|
||||
license = "MIT"
|
||||
|
||||
build = "bindings/rust/build.rs"
|
||||
include = [
|
||||
"bindings/rust/*",
|
||||
"grammar.js",
|
||||
"queries/*",
|
||||
"src/*",
|
||||
]
|
||||
|
||||
[lib]
|
||||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter = "~0.20.3"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
19
binding.gyp
Normal file
19
binding.gyp
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_lila_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
],
|
||||
"sources": [
|
||||
"bindings/node/binding.cc",
|
||||
"src/parser.c",
|
||||
# If your language uses an external scanner, add it here.
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
28
bindings/node/binding.cc
Normal file
28
bindings/node/binding.cc
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_lila();
|
||||
|
||||
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_lila());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("lila").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_lila_binding, Init)
|
||||
|
||||
} // namespace
|
19
bindings/node/index.js
Normal file
19
bindings/node/index.js
Normal file
@@ -0,0 +1,19 @@
|
||||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_lila_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_lila_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
}
|
||||
throw error1
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
} catch (_) {}
|
40
bindings/rust/build.rs
Normal file
40
bindings/rust/build.rs
Normal file
@@ -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
bindings/rust/lib.rs
Normal file
52
bindings/rust/lib.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
//! This crate provides lila 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_lila::language()).expect("Error loading lila 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_lila() -> 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_lila() }
|
||||
}
|
||||
|
||||
/// 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 lila language");
|
||||
}
|
||||
}
|
120
grammar.js
Normal file
120
grammar.js
Normal file
@@ -0,0 +1,120 @@
|
||||
module.exports = grammar({
|
||||
name: 'lila',
|
||||
|
||||
word: $ => $.identifier,
|
||||
|
||||
rules: {
|
||||
source_file: $ => repeat($._definition),
|
||||
|
||||
_definition: $ => choice(
|
||||
$.function_definition
|
||||
),
|
||||
|
||||
function_definition: $ => seq(
|
||||
'func',
|
||||
field('name', $.identifier),
|
||||
field('parameters', $.parameters),
|
||||
field('return_type', optional($._type)),
|
||||
field('body', $.block),
|
||||
),
|
||||
|
||||
parameters: $ => seq(
|
||||
'(',
|
||||
optional(seq(
|
||||
repeat(seq($.parameter, ',')),
|
||||
seq($.parameter, optional(',')),
|
||||
)),
|
||||
')',
|
||||
),
|
||||
|
||||
parameter: $ => seq(
|
||||
$.identifier,
|
||||
' ',
|
||||
$._type,
|
||||
),
|
||||
|
||||
block: $ => seq(
|
||||
'{',
|
||||
repeat($._statement),
|
||||
optional($._expression),
|
||||
'}',
|
||||
),
|
||||
|
||||
_statement: $ => choice(
|
||||
$.return_statement,
|
||||
$.assign_statement,
|
||||
$.if_statement,
|
||||
),
|
||||
|
||||
if_statement: $ => seq(
|
||||
'if',
|
||||
field('condition', $._expression),
|
||||
field('body', $.block),
|
||||
';'
|
||||
),
|
||||
|
||||
if_expression: $ => seq(
|
||||
'if',
|
||||
field('condition', $._expression),
|
||||
field('body', $.block),
|
||||
field('else',
|
||||
seq('else', choice(
|
||||
$._expression,
|
||||
$.block,
|
||||
))
|
||||
),
|
||||
),
|
||||
|
||||
return_statement: $ => seq(
|
||||
'return',
|
||||
optional($._expression),
|
||||
';',
|
||||
),
|
||||
|
||||
assign_statement: $ => seq(
|
||||
$.identifier,
|
||||
'=',
|
||||
$._expression,
|
||||
';',
|
||||
),
|
||||
|
||||
_expression: $ => choice(
|
||||
$.unary_expression,
|
||||
$.binary_expression,
|
||||
$.if_expression,
|
||||
$.boolean_literal,
|
||||
$.integer_literal,
|
||||
$.identifier,
|
||||
),
|
||||
|
||||
unary_expression: $ => prec(10, choice(
|
||||
seq('-', $._expression),
|
||||
seq('!', $._expression),
|
||||
)),
|
||||
|
||||
binary_expression: $ => choice(
|
||||
prec.left(4, seq($._expression, '*', $._expression)),
|
||||
prec.left(3, seq($._expression, '+', $._expression)),
|
||||
prec.left(2, seq($._expression, '||', $._expression)),
|
||||
prec.left(1, seq($._expression, '&&', $._expression)),
|
||||
),
|
||||
|
||||
identifier: $ => /[a-z_]+[a-zA-Z0-9_]*/,
|
||||
|
||||
integer_literal: $ => /\d+/,
|
||||
|
||||
boolean_literal: $ => choice('true', 'false'),
|
||||
|
||||
//string_literal: $ => /"[]"/,
|
||||
|
||||
_type: $ => choice(
|
||||
$.primitive_type,
|
||||
),
|
||||
|
||||
primitive_type: $ => choice(
|
||||
'bool',
|
||||
'int',
|
||||
'uint',
|
||||
),
|
||||
}
|
||||
});
|
27
package.json
Normal file
27
package.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "tree-sitter-lila",
|
||||
"version": "0.0.1",
|
||||
"description": "Lila grammar for tree-sitter",
|
||||
"main": "bindings/node",
|
||||
"keywords": [
|
||||
"parsing",
|
||||
"incremental"
|
||||
],
|
||||
"dependencies": {
|
||||
"nan": "^2.12.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.20.8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tree-sitter test"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.lila",
|
||||
"file-types": [
|
||||
"lila"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
14
queries/highlights.scm
Normal file
14
queries/highlights.scm
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
"func" @keyword
|
||||
"return" @keyword
|
||||
"if" @keyword
|
||||
"else" @keyword
|
||||
;"while" @keyword
|
||||
|
||||
"uint" @type
|
||||
"int" @type
|
||||
|
||||
(integer_literal) @number
|
||||
|
||||
(function_definition name: (identifier) @function)
|
538
src/grammar.json
Normal file
538
src/grammar.json
Normal file
@@ -0,0 +1,538 @@
|
||||
{
|
||||
"name": "lila",
|
||||
"word": "identifier",
|
||||
"rules": {
|
||||
"source_file": {
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_definition"
|
||||
}
|
||||
},
|
||||
"_definition": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "function_definition"
|
||||
}
|
||||
]
|
||||
},
|
||||
"function_definition": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "func"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "name",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "parameters",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "parameters"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "return_type",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_type"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "body",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "parameter"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "parameter"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
}
|
||||
]
|
||||
},
|
||||
"parameter": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": " "
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_type"
|
||||
}
|
||||
]
|
||||
},
|
||||
"block": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_statement"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
},
|
||||
"_statement": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "return_statement"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "assign_statement"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "if_statement"
|
||||
}
|
||||
]
|
||||
},
|
||||
"if_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "if"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "condition",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "body",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
}
|
||||
]
|
||||
},
|
||||
"if_expression": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "if"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "condition",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "body",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "else",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "else"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"return_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "return"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
}
|
||||
]
|
||||
},
|
||||
"assign_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "="
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
}
|
||||
]
|
||||
},
|
||||
"_expression": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "unary_expression"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "binary_expression"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "if_expression"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "boolean_literal"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "integer_literal"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
"unary_expression": {
|
||||
"type": "PREC",
|
||||
"value": 10,
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "-"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "!"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"binary_expression": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 4,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "*"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 3,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "+"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "||"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PREC_LEFT",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "&&"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"identifier": {
|
||||
"type": "PATTERN",
|
||||
"value": "[a-z_]+[a-zA-Z0-9_]*"
|
||||
},
|
||||
"integer_literal": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\d+"
|
||||
},
|
||||
"boolean_literal": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "true"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "false"
|
||||
}
|
||||
]
|
||||
},
|
||||
"_type": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "primitive_type"
|
||||
}
|
||||
]
|
||||
},
|
||||
"primitive_type": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "bool"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "int"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "uint"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s"
|
||||
}
|
||||
],
|
||||
"conflicts": [],
|
||||
"precedences": [],
|
||||
"externals": [],
|
||||
"inline": [],
|
||||
"supertypes": []
|
||||
}
|
||||
|
524
src/node-types.json
Normal file
524
src/node-types.json
Normal file
@@ -0,0 +1,524 @@
|
||||
[
|
||||
{
|
||||
"type": "assign_statement",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "block",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "assign_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "return_statement",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"body": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"parameters": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "parameters",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"return_type": {
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "primitive_type",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"body": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"condition": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"else": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "else",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "if_statement",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"body": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "block",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"condition": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "parameter",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "primitive_type",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "parameters",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "parameter",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "primitive_type",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "return_statement",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "source_file",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "function_definition",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "binary_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "boolean_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": " ",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "!",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "&&",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "(",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ")",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "*",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "+",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "-",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ";",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "bool",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "else",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "false",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "func",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "int",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "integer_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "return",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "true",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "uint",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "{",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "||",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "}",
|
||||
"named": false
|
||||
}
|
||||
]
|
1747
src/parser.c
Normal file
1747
src/parser.c
Normal file
File diff suppressed because it is too large
Load Diff
224
src/tree_sitter/parser.h
Normal file
224
src/tree_sitter/parser.h
Normal file
@@ -0,0 +1,224 @@
|
||||
#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
|
||||
|
||||
typedef uint16_t TSStateId;
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
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;
|
||||
|
||||
#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_
|
75
test/corpus/booleans.txt
Normal file
75
test/corpus/booleans.txt
Normal file
@@ -0,0 +1,75 @@
|
||||
===============================================================================
|
||||
Booleans
|
||||
===============================================================================
|
||||
|
||||
func boolean() bool {
|
||||
right = true;
|
||||
wrong = false;
|
||||
right_or_wrong = right || wrong;
|
||||
right_and_wrong = right && wrong;
|
||||
return true;
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
(identifier)
|
||||
(parameters)
|
||||
(primitive_type)
|
||||
(block
|
||||
(assign_statement
|
||||
(identifier)
|
||||
(boolean_literal))
|
||||
(assign_statement
|
||||
(identifier)
|
||||
(boolean_literal))
|
||||
(assign_statement
|
||||
(identifier)
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(assign_statement
|
||||
(identifier)
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(return_statement (boolean_literal)))))
|
||||
|
||||
===============
|
||||
literal 'true'
|
||||
===============
|
||||
|
||||
func a() bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
(identifier)
|
||||
(parameters)
|
||||
(primitive_type)
|
||||
(block
|
||||
(return_statement
|
||||
(boolean_literal)))))
|
||||
|
||||
===============================================================================
|
||||
literal 'false'
|
||||
===============================================================================
|
||||
|
||||
func a() bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
(identifier)
|
||||
(parameters)
|
||||
(primitive_type)
|
||||
(block
|
||||
(return_statement
|
||||
(boolean_literal)))))
|
114
test/corpus/function_parameters.txt
Normal file
114
test/corpus/function_parameters.txt
Normal file
@@ -0,0 +1,114 @@
|
||||
===============================================================================
|
||||
No parameters
|
||||
===============================================================================
|
||||
|
||||
func one() int {}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
return_type: (primitive_type)
|
||||
body: (block)))
|
||||
|
||||
===============================================================================
|
||||
1 parameter
|
||||
===============================================================================
|
||||
|
||||
func one(x int) int {}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters
|
||||
(parameter
|
||||
(identifier)
|
||||
(primitive_type)))
|
||||
return_type: (primitive_type)
|
||||
body: (block)))
|
||||
|
||||
===============================================================================
|
||||
1 parameter with trailing comma
|
||||
===============================================================================
|
||||
|
||||
func one(
|
||||
x int,
|
||||
) int {}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters
|
||||
(parameter
|
||||
(identifier)
|
||||
(primitive_type)))
|
||||
return_type: (primitive_type)
|
||||
body: (block)))
|
||||
|
||||
===============================================================================
|
||||
2 parameters
|
||||
===============================================================================
|
||||
|
||||
func one(x int, y int) int {}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters
|
||||
(parameter
|
||||
(identifier)
|
||||
(primitive_type))
|
||||
(parameter
|
||||
(identifier)
|
||||
(primitive_type)))
|
||||
return_type: (primitive_type)
|
||||
body: (block)))
|
||||
|
||||
===============================================================================
|
||||
2 parameters with trailing comma
|
||||
===============================================================================
|
||||
|
||||
func one(
|
||||
x int,
|
||||
y int,
|
||||
) int {}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters
|
||||
(parameter
|
||||
(identifier)
|
||||
(primitive_type))
|
||||
(parameter
|
||||
(identifier)
|
||||
(primitive_type)))
|
||||
return_type: (primitive_type)
|
||||
body: (block)))
|
||||
|
||||
===============================================================================
|
||||
[Error] No space between parameter name and type
|
||||
===============================================================================
|
||||
|
||||
func one(xint) int {}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters
|
||||
(ERROR
|
||||
(identifier)))
|
||||
return_type: (primitive_type)
|
||||
body: (block)))
|
95
test/corpus/if.txt
Normal file
95
test/corpus/if.txt
Normal file
@@ -0,0 +1,95 @@
|
||||
====================================================
|
||||
if statement
|
||||
====================================================
|
||||
|
||||
func main() {
|
||||
if true {
|
||||
false
|
||||
};
|
||||
}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
body: (block
|
||||
(if_statement
|
||||
condition: (boolean_literal)
|
||||
body: (block
|
||||
(boolean_literal))))))
|
||||
|
||||
====================================================
|
||||
if else expression
|
||||
====================================================
|
||||
|
||||
func main() {
|
||||
return if true {
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
body: (block
|
||||
(return_statement
|
||||
(if_expression
|
||||
condition: (boolean_literal)
|
||||
body: (block
|
||||
(boolean_literal))
|
||||
else: (block
|
||||
(boolean_literal)))))))
|
||||
|
||||
====================================================
|
||||
if else expression (no brackets in else)
|
||||
====================================================
|
||||
|
||||
func main() {
|
||||
return if true {
|
||||
false
|
||||
} else true;
|
||||
}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
body: (block
|
||||
(return_statement
|
||||
(if_expression
|
||||
condition: (boolean_literal)
|
||||
body: (block
|
||||
(boolean_literal))
|
||||
else: (boolean_literal))))))
|
||||
|
||||
====================================================
|
||||
[Error] if expression (missing else)
|
||||
====================================================
|
||||
|
||||
func main() {
|
||||
return if true {
|
||||
false
|
||||
};
|
||||
}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
body: (block
|
||||
(return_statement
|
||||
(ERROR
|
||||
(boolean_literal)
|
||||
(block
|
||||
(boolean_literal)))))))
|
56
test/corpus/return.txt
Normal file
56
test/corpus/return.txt
Normal file
@@ -0,0 +1,56 @@
|
||||
===============================================================================
|
||||
Return int literal
|
||||
===============================================================================
|
||||
|
||||
func x() int {
|
||||
return 1;
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
return_type: (primitive_type)
|
||||
body:
|
||||
(block
|
||||
(return_statement (integer_literal)))))
|
||||
|
||||
===============================================================================
|
||||
Return nothing
|
||||
===============================================================================
|
||||
|
||||
func x() int {
|
||||
return;
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
return_type: (primitive_type)
|
||||
body:
|
||||
(block
|
||||
(return_statement))))
|
||||
|
||||
===============================================================================
|
||||
[Error] Return nothing with missing ';'
|
||||
===============================================================================
|
||||
|
||||
func x() int {
|
||||
return
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
return_type: (primitive_type)
|
||||
body:
|
||||
(block
|
||||
(ERROR))))
|
30
test/corpus/return_types.txt
Normal file
30
test/corpus/return_types.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
===============================================================================
|
||||
int return type
|
||||
===============================================================================
|
||||
|
||||
func a() int {
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
return_type: (primitive_type)
|
||||
body: (block)))
|
||||
|
||||
===============================================================================
|
||||
No return type
|
||||
===============================================================================
|
||||
|
||||
func a() {
|
||||
}
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_definition
|
||||
name: (identifier)
|
||||
parameters: (parameters)
|
||||
body: (block)))
|
1
ts_verify_ts.conf
Normal file
1
ts_verify_ts.conf
Normal file
@@ -0,0 +1 @@
|
||||
module_raw input
|
Reference in New Issue
Block a user