Initial working
This commit is contained in:
commit
b1fbbe6612
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
Cargo.lock
|
||||
node_modules
|
||||
build
|
||||
*.log
|
||||
package-lock.json
|
||||
target
|
26
Cargo.toml
Normal file
26
Cargo.toml
Normal file
|
@ -0,0 +1,26 @@
|
|||
[package]
|
||||
name = "tree-sitter-dockerfile"
|
||||
description = "dockerfile grammar for the tree-sitter parsing library"
|
||||
version = "0.0.1"
|
||||
keywords = ["incremental", "parsing", "dockerfile"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-javascript"
|
||||
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.17"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
19
binding.gyp
Normal file
19
binding.gyp
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_dockerfile_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_dockerfile();
|
||||
|
||||
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_dockerfile());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("dockerfile").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_dockerfile_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_dockerfile_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_dockerfile_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 dockerfile 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_dockerfile::language()).expect("Error loading dockerfile 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_dockerfile() -> 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_dockerfile() }
|
||||
}
|
||||
|
||||
/// 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 dockerfile language");
|
||||
}
|
||||
}
|
27
corpus/add.txt
Normal file
27
corpus/add.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
==================
|
||||
No param
|
||||
==================
|
||||
|
||||
ADD /src ./dst
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(add_instruction
|
||||
(path)
|
||||
(path)))
|
||||
|
||||
==================
|
||||
With param
|
||||
==================
|
||||
|
||||
ADD --chown=a:b /src ./dst
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(add_instruction
|
||||
(param)
|
||||
(path)
|
||||
(path)))
|
||||
|
40
corpus/arg.txt
Normal file
40
corpus/arg.txt
Normal file
|
@ -0,0 +1,40 @@
|
|||
==================
|
||||
No default
|
||||
==================
|
||||
|
||||
ARG test
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(arg_instruction
|
||||
name: (unquoted_string)))
|
||||
|
||||
==================
|
||||
With default
|
||||
==================
|
||||
|
||||
ARG foo=bar
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(arg_instruction
|
||||
name: (unquoted_string)
|
||||
default: (unquoted_string)))
|
||||
|
||||
|
||||
==================
|
||||
With quoted default
|
||||
==================
|
||||
|
||||
ARG foo="bar"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(arg_instruction
|
||||
name: (unquoted_string)
|
||||
default: (double_quoted_string)))
|
||||
|
||||
|
53
corpus/cmd.txt
Normal file
53
corpus/cmd.txt
Normal file
|
@ -0,0 +1,53 @@
|
|||
==================
|
||||
Shell command
|
||||
==================
|
||||
|
||||
CMD echo "test"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(cmd_instruction
|
||||
(shell_command)))
|
||||
|
||||
==================
|
||||
Shell command multiline
|
||||
==================
|
||||
|
||||
CMD echo "test" \
|
||||
"foo" \
|
||||
bar
|
||||
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(cmd_instruction
|
||||
(shell_command)))
|
||||
|
||||
==================
|
||||
Run with shell empty array
|
||||
==================
|
||||
|
||||
cmd []
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(cmd_instruction
|
||||
(string_array)))
|
||||
|
||||
==================
|
||||
Run with shell array
|
||||
==================
|
||||
|
||||
cmd ["echo", "test"]
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(cmd_instruction
|
||||
(string_array
|
||||
(double_quoted_string)
|
||||
(double_quoted_string))))
|
||||
|
27
corpus/copy.txt
Normal file
27
corpus/copy.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
==================
|
||||
No param
|
||||
==================
|
||||
|
||||
COPY /src ./dst
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(copy_instruction
|
||||
(path)
|
||||
(path)))
|
||||
|
||||
==================
|
||||
With param
|
||||
==================
|
||||
|
||||
COPY --chown=a:b /src ./dst
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(copy_instruction
|
||||
(param)
|
||||
(path)
|
||||
(path)))
|
||||
|
53
corpus/entrypoint.txt
Normal file
53
corpus/entrypoint.txt
Normal file
|
@ -0,0 +1,53 @@
|
|||
==================
|
||||
Shell command
|
||||
==================
|
||||
|
||||
ENTRYPOINT echo "test"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(entrypoint_instruction
|
||||
(shell_command)))
|
||||
|
||||
==================
|
||||
Shell command multiline
|
||||
==================
|
||||
|
||||
ENTRYPOINT echo "test" \
|
||||
"foo" \
|
||||
bar
|
||||
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(entrypoint_instruction
|
||||
(shell_command)))
|
||||
|
||||
==================
|
||||
Run with shell empty array
|
||||
==================
|
||||
|
||||
ENTRYPOINT []
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(entrypoint_instruction
|
||||
(string_array)))
|
||||
|
||||
==================
|
||||
Run with shell array
|
||||
==================
|
||||
|
||||
ENTRYPOINT ["echo", "test"]
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(entrypoint_instruction
|
||||
(string_array
|
||||
(double_quoted_string)
|
||||
(double_quoted_string))))
|
||||
|
81
corpus/env.txt
Normal file
81
corpus/env.txt
Normal file
|
@ -0,0 +1,81 @@
|
|||
==================
|
||||
Quoted value
|
||||
==================
|
||||
|
||||
ENV TEST="okay"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(env_instruction
|
||||
(env_pair
|
||||
name: (unquoted_string)
|
||||
value: (double_quoted_string))))
|
||||
|
||||
==================
|
||||
Unquoted value
|
||||
==================
|
||||
|
||||
ENV TEST_2=value\ 2
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(env_instruction
|
||||
(env_pair
|
||||
name: (unquoted_string)
|
||||
value: (unquoted_string))))
|
||||
|
||||
==================
|
||||
Multiple
|
||||
==================
|
||||
|
||||
ENV TEST="foo" TEST_2=foo\ bar
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(env_instruction
|
||||
(env_pair
|
||||
name: (unquoted_string)
|
||||
value: (double_quoted_string))
|
||||
(env_pair
|
||||
name: (unquoted_string)
|
||||
value: (unquoted_string))))
|
||||
|
||||
==================
|
||||
Multiline
|
||||
==================
|
||||
|
||||
ENV TEST1="foo" \
|
||||
TEST2=bar
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(env_instruction
|
||||
(env_pair
|
||||
name: (unquoted_string)
|
||||
value: (double_quoted_string))
|
||||
(env_pair
|
||||
name: (unquoted_string)
|
||||
value: (unquoted_string))))
|
||||
|
||||
==================
|
||||
Multiple instructions
|
||||
==================
|
||||
|
||||
ENV TEST1="foo"
|
||||
ENV TEST2="bar"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(env_instruction
|
||||
(env_pair
|
||||
name: (unquoted_string)
|
||||
value: (double_quoted_string)))
|
||||
(env_instruction
|
||||
(env_pair
|
||||
name: (unquoted_string)
|
||||
value: (double_quoted_string))))
|
27
corpus/expose.txt
Normal file
27
corpus/expose.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
==================
|
||||
Single port
|
||||
==================
|
||||
|
||||
EXPOSE 80
|
||||
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(expose_instruction
|
||||
(expose_port)))
|
||||
|
||||
==================
|
||||
Multiple ports
|
||||
==================
|
||||
|
||||
EXPOSE 80 90/tcp 100/udp
|
||||
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(expose_instruction
|
||||
(expose_port)
|
||||
(expose_port)
|
||||
(expose_port)))
|
68
corpus/from.txt
Normal file
68
corpus/from.txt
Normal file
|
@ -0,0 +1,68 @@
|
|||
==================
|
||||
Only image
|
||||
==================
|
||||
|
||||
FROM testimage
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(from_instruction
|
||||
(image_spec)))
|
||||
|
||||
==================
|
||||
Image with tag
|
||||
==================
|
||||
|
||||
FROM testimage:tag
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(from_instruction
|
||||
(image_spec
|
||||
(image_tag))))
|
||||
|
||||
==================
|
||||
Image with digest
|
||||
==================
|
||||
|
||||
FROM testimage@sha256:skgshlshg
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(from_instruction
|
||||
(image_spec
|
||||
(image_digest))))
|
||||
|
||||
==================
|
||||
Image with tag and digest
|
||||
==================
|
||||
|
||||
FROM testimage:tag@sha256:452525
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(from_instruction
|
||||
(image_spec
|
||||
(image_tag)
|
||||
(image_digest))))
|
||||
|
||||
|
||||
==================
|
||||
Tag and digest with as
|
||||
==================
|
||||
|
||||
FROM sourcegraph/alpine:3.12@sha256:ce099fbcd3cf70b338fc4cb2a4e1fa9ae847de21afdb0a849a393b87d94fb174 AS monitoring_builder
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(from_instruction
|
||||
(image_spec
|
||||
(image_tag)
|
||||
(image_digest))
|
||||
(name)))
|
||||
|
39
corpus/healthcheck.txt
Normal file
39
corpus/healthcheck.txt
Normal file
|
@ -0,0 +1,39 @@
|
|||
==================
|
||||
None
|
||||
==================
|
||||
|
||||
HEALTHCHECK NONE
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(healthcheck_instruction))
|
||||
|
||||
==================
|
||||
Custom command
|
||||
==================
|
||||
|
||||
HEALTHCHECK CMD echo "test"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(healthcheck_instruction
|
||||
(cmd_instruction
|
||||
(shell_command))))
|
||||
|
||||
==================
|
||||
With options
|
||||
==================
|
||||
|
||||
HEALTHCHECK --interval=10s --retries=10 CMD echo "test"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(healthcheck_instruction
|
||||
(param)
|
||||
(param)
|
||||
(cmd_instruction
|
||||
(shell_command))))
|
||||
|
48
corpus/label.txt
Normal file
48
corpus/label.txt
Normal file
|
@ -0,0 +1,48 @@
|
|||
==================
|
||||
Single key-value
|
||||
==================
|
||||
|
||||
LABEL key="value"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(label_instruction
|
||||
(label_pair
|
||||
key: (unquoted_string)
|
||||
value: (double_quoted_string))))
|
||||
|
||||
==================
|
||||
Multi key-value
|
||||
==================
|
||||
|
||||
LABEL key.1="value1" key.2="value2"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(label_instruction
|
||||
(label_pair
|
||||
key: (unquoted_string)
|
||||
value: (double_quoted_string))
|
||||
(label_pair
|
||||
key: (unquoted_string)
|
||||
value: (double_quoted_string))))
|
||||
|
||||
==================
|
||||
Multiline
|
||||
==================
|
||||
|
||||
LABEL key.1="value1" \
|
||||
key.2="value2"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(label_instruction
|
||||
(label_pair
|
||||
key: (unquoted_string)
|
||||
value: (double_quoted_string))
|
||||
(label_pair
|
||||
key: (unquoted_string)
|
||||
value: (double_quoted_string))))
|
26
corpus/onbuild.txt
Normal file
26
corpus/onbuild.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
==================
|
||||
Simple add
|
||||
==================
|
||||
|
||||
ONBUILD ADD . /app/src
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(onbuild_instruction
|
||||
(add_instruction
|
||||
(path)
|
||||
(path))))
|
||||
|
||||
==================
|
||||
Simple run
|
||||
==================
|
||||
|
||||
ONBUILD RUN /usr/local/bin/python-build --dir /app/src
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(onbuild_instruction
|
||||
(run_instruction
|
||||
(shell_command))))
|
53
corpus/run.txt
Normal file
53
corpus/run.txt
Normal file
|
@ -0,0 +1,53 @@
|
|||
==================
|
||||
Shell command
|
||||
==================
|
||||
|
||||
RUN echo "test"
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(run_instruction
|
||||
(shell_command)))
|
||||
|
||||
==================
|
||||
Shell command multiline
|
||||
==================
|
||||
|
||||
RUN echo "test" \
|
||||
"foo" \
|
||||
bar
|
||||
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(run_instruction
|
||||
(shell_command)))
|
||||
|
||||
==================
|
||||
Run with shell empty array
|
||||
==================
|
||||
|
||||
run []
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(run_instruction
|
||||
(string_array)))
|
||||
|
||||
==================
|
||||
Run with shell array
|
||||
==================
|
||||
|
||||
run ["echo", "test"]
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(run_instruction
|
||||
(string_array
|
||||
(double_quoted_string)
|
||||
(double_quoted_string))))
|
||||
|
14
corpus/shell_instruction.txt
Normal file
14
corpus/shell_instruction.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
==================
|
||||
Simple
|
||||
==================
|
||||
|
||||
SHELL ["powershell","-command"]
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(shell_instruction
|
||||
(string_array
|
||||
(double_quoted_string)
|
||||
(double_quoted_string))))
|
||||
|
21
corpus/stopsignal.txt
Normal file
21
corpus/stopsignal.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
==================
|
||||
Integer
|
||||
==================
|
||||
|
||||
STOPSIGNAL 9
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(stopsignal_instruction))
|
||||
|
||||
==================
|
||||
Signal name
|
||||
==================
|
||||
|
||||
STOPSIGNAL SIGKILL
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(stopsignal_instruction))
|
26
corpus/user.txt
Normal file
26
corpus/user.txt
Normal file
|
@ -0,0 +1,26 @@
|
|||
==================
|
||||
No group
|
||||
==================
|
||||
|
||||
USER foo
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(user_instruction
|
||||
user: (unquoted_string)))
|
||||
|
||||
==================
|
||||
With group
|
||||
==================
|
||||
|
||||
USER foo:bar
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(user_instruction
|
||||
user: (unquoted_string)
|
||||
group: (unquoted_string)))
|
||||
|
||||
|
67
corpus/volume.txt
Normal file
67
corpus/volume.txt
Normal file
|
@ -0,0 +1,67 @@
|
|||
==================
|
||||
Single volume
|
||||
==================
|
||||
|
||||
VOLUME /myvol
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(volume_instruction
|
||||
(path)))
|
||||
|
||||
==================
|
||||
Multiple volumes
|
||||
==================
|
||||
|
||||
volume /myvol1 /myvol2
|
||||
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(volume_instruction
|
||||
(path)
|
||||
(path)))
|
||||
|
||||
==================
|
||||
Multiline volumes
|
||||
==================
|
||||
|
||||
VOLUME /myvol1 \
|
||||
/myvol2
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(volume_instruction
|
||||
(path)
|
||||
(path)))
|
||||
|
||||
==================
|
||||
Array
|
||||
==================
|
||||
|
||||
VOLUME ["/test/myvol"]
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(volume_instruction
|
||||
(string_array
|
||||
(double_quoted_string))))
|
||||
|
||||
==================
|
||||
Multiline array
|
||||
==================
|
||||
|
||||
VOLUME ["/test/myvol", \
|
||||
"/test/myvol2"]
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(volume_instruction
|
||||
(string_array
|
||||
(double_quoted_string)
|
||||
(double_quoted_string))))
|
12
corpus/workdir.txt
Normal file
12
corpus/workdir.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
==================
|
||||
Simple
|
||||
==================
|
||||
|
||||
WORKDIR /tmp/test
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(workdir_instruction
|
||||
(path)))
|
||||
|
268
grammar.js
Normal file
268
grammar.js
Normal file
|
@ -0,0 +1,268 @@
|
|||
module.exports = grammar({
|
||||
name: 'dockerfile',
|
||||
|
||||
extras: $ => [$.comment, /\s+/, '\\\n'],
|
||||
|
||||
rules: {
|
||||
source_file: $ => repeat(seq($._instruction, "\n")),
|
||||
|
||||
_instruction: $ => choice(
|
||||
$.from_instruction,
|
||||
$.run_instruction,
|
||||
$.cmd_instruction,
|
||||
$.label_instruction,
|
||||
$.expose_instruction,
|
||||
$.env_instruction,
|
||||
$.add_instruction,
|
||||
$.copy_instruction,
|
||||
$.entrypoint_instruction,
|
||||
$.volume_instruction,
|
||||
$.user_instruction,
|
||||
$.workdir_instruction,
|
||||
$.arg_instruction,
|
||||
$.onbuild_instruction,
|
||||
$.stopsignal_instruction,
|
||||
$.healthcheck_instruction,
|
||||
$.shell_instruction,
|
||||
),
|
||||
|
||||
from_instruction: $ => seq(
|
||||
alias(/[fF][rR][oO][mM]/, "FROM"),
|
||||
$._non_newline_whitespace,
|
||||
optional($.param),
|
||||
$.image_spec,
|
||||
optional(seq(
|
||||
alias(/[aA][sS]/, "AS"),
|
||||
$.name,
|
||||
)),
|
||||
),
|
||||
|
||||
run_instruction: $ => seq(
|
||||
alias(/[rR][uU][nN]/, "RUN"),
|
||||
$._non_newline_whitespace,
|
||||
choice(
|
||||
$.string_array,
|
||||
$.shell_command,
|
||||
),
|
||||
),
|
||||
|
||||
cmd_instruction: $ => seq(
|
||||
alias(/[cC][mM][dD]/, "CMD"),
|
||||
$._non_newline_whitespace,
|
||||
choice(
|
||||
$.string_array,
|
||||
$.shell_command,
|
||||
),
|
||||
),
|
||||
|
||||
label_instruction: $ => seq(
|
||||
alias(/[lL][aA][bB][eE][lL]/, "LABEL"),
|
||||
$._non_newline_whitespace,
|
||||
repeat1($.label_pair),
|
||||
),
|
||||
|
||||
expose_instruction: $ => seq(
|
||||
alias(/[eE][xX][pP][oO][sS][eE]/, "EXPOSE"),
|
||||
$._non_newline_whitespace,
|
||||
repeat1($.expose_port),
|
||||
),
|
||||
|
||||
env_instruction: $ => seq(
|
||||
alias(/[eE][nN][vV]/, "ENV"),
|
||||
$._non_newline_whitespace,
|
||||
repeat1($.env_pair),
|
||||
),
|
||||
|
||||
add_instruction: $ => seq(
|
||||
alias(/[aA][dD][dD]/, "ADD"),
|
||||
$._non_newline_whitespace,
|
||||
optional($.param),
|
||||
$.path,
|
||||
$.path,
|
||||
),
|
||||
|
||||
copy_instruction: $ => seq(
|
||||
alias(/[cC][oO][pP][yY]/, "COPY"),
|
||||
$._non_newline_whitespace,
|
||||
optional($.param),
|
||||
$.path,
|
||||
$.path,
|
||||
),
|
||||
|
||||
entrypoint_instruction: $ => seq(
|
||||
alias(/[eE][nN][tT][rR][yY][pP][oO][iI][nN][tT]/, "ENTRYPOINT"),
|
||||
$._non_newline_whitespace,
|
||||
choice(
|
||||
$.string_array,
|
||||
$.shell_command,
|
||||
),
|
||||
),
|
||||
|
||||
volume_instruction: $ => seq(
|
||||
alias(/[vV][oO][lL][uU][mM][eE]/, "VOLUME"),
|
||||
$._non_newline_whitespace,
|
||||
choice(
|
||||
$.string_array,
|
||||
repeat1($.path),
|
||||
),
|
||||
),
|
||||
|
||||
user_instruction: $ => seq(
|
||||
alias(/[uU][sS][eE][rR]/, "USER"),
|
||||
$._non_newline_whitespace,
|
||||
field("user", alias(/[a-z][-a-z0-9_]*/, $.unquoted_string)),
|
||||
optional(seq(
|
||||
token.immediate(":"),
|
||||
field("group", alias(token.immediate(/[a-z][-a-z0-9_]*/), $.unquoted_string)),
|
||||
)),
|
||||
),
|
||||
|
||||
workdir_instruction: $ => seq(
|
||||
alias(/[wW][oO][rR][kK][dD][iI][rR]/, "WORKDIR"),
|
||||
$._non_newline_whitespace,
|
||||
$.path,
|
||||
),
|
||||
|
||||
arg_instruction: $ => seq(
|
||||
alias(/[aA][rR][gG]/, "ARG"),
|
||||
$._non_newline_whitespace,
|
||||
field("name", alias(/[a-zA-Z0-9_]+/, $.unquoted_string)),
|
||||
optional(seq(
|
||||
token.immediate("="),
|
||||
field("default", choice(
|
||||
$.double_quoted_string,
|
||||
$.unquoted_string,
|
||||
)),
|
||||
)),
|
||||
),
|
||||
|
||||
onbuild_instruction: $ => seq(
|
||||
alias(/[oO][nN][bB][uU][iI][lL][dD]/, "ONBUILD"),
|
||||
$._non_newline_whitespace,
|
||||
$._instruction,
|
||||
),
|
||||
|
||||
stopsignal_instruction: $ => seq(
|
||||
alias(/[sS][tT][oO][pP][sS][iI][gG][nN][aA][lL]/, "STOPSIGNAL"),
|
||||
$._non_newline_whitespace,
|
||||
/[A-Z0-9]+/,
|
||||
),
|
||||
|
||||
healthcheck_instruction: $ => seq(
|
||||
alias(/[hH][eE][aA][lL][tT][hH][cC][hH][eE][cC][kK]/, "HEALTHCHECK"),
|
||||
$._non_newline_whitespace,
|
||||
choice(
|
||||
"NONE",
|
||||
seq(
|
||||
repeat($.param),
|
||||
$.cmd_instruction,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
shell_instruction: $ => seq(
|
||||
alias(/[sS][hH][eE][lL][lL]/, "SHELL"),
|
||||
$._non_newline_whitespace,
|
||||
$.string_array,
|
||||
),
|
||||
|
||||
path: $ => /[^-\[][^\s]*/,
|
||||
|
||||
env_pair: $ => seq(
|
||||
field("name", alias(/[a-zA-Z][a-zA-Z0-9_]+[a-zA-Z0-9]/, $.unquoted_string)),
|
||||
token.immediate("="),
|
||||
field("value", choice(
|
||||
$.double_quoted_string,
|
||||
$.unquoted_string,
|
||||
)),
|
||||
),
|
||||
|
||||
expose_port: $ => seq(
|
||||
/\d+/,
|
||||
optional(choice(
|
||||
"/tcp",
|
||||
"/udp",
|
||||
)),
|
||||
),
|
||||
|
||||
label_pair: $ => seq(
|
||||
field("key", alias(/[-a-zA-Z0-9\._]+/, $.unquoted_string)),
|
||||
token.immediate("="),
|
||||
field("value", choice(
|
||||
$.double_quoted_string,
|
||||
$.unquoted_string,
|
||||
)),
|
||||
),
|
||||
|
||||
image_spec: $ => seq(
|
||||
alias(/[^:@\s]+/, "name"),
|
||||
seq(
|
||||
optional($.image_tag),
|
||||
optional($.image_digest),
|
||||
),
|
||||
),
|
||||
|
||||
image_tag: $ => token.immediate(seq(
|
||||
":",
|
||||
/[^\s@]+/,
|
||||
)),
|
||||
|
||||
image_digest: $ => token.immediate(seq(
|
||||
"@",
|
||||
/[^\s]+/,
|
||||
)),
|
||||
|
||||
param: $ => seq(
|
||||
"--",
|
||||
field("name", /[a-z][-a-z]*/),
|
||||
"=",
|
||||
field("value", /[^\s]+/),
|
||||
),
|
||||
|
||||
name: $ => /[-a-z_]+/,
|
||||
|
||||
string_array: $ => seq(
|
||||
"[",
|
||||
optional(seq(
|
||||
$.double_quoted_string,
|
||||
repeat(seq(",", $.double_quoted_string)),
|
||||
)),
|
||||
"]",
|
||||
),
|
||||
|
||||
shell_command: $ => seq(
|
||||
/[^\[\s].*[^\\\n]/,
|
||||
repeat(seq("\\\n", /.*[^\\\n]/)),
|
||||
),
|
||||
|
||||
double_quoted_string: $ => seq(
|
||||
'"',
|
||||
repeat(choice(
|
||||
token.immediate(prec(1, /[^"\n\\]+/)),
|
||||
$.escape_sequence
|
||||
)),
|
||||
'"'
|
||||
),
|
||||
|
||||
unquoted_string: $ => repeat1(choice(
|
||||
token.immediate(/[^\s\n\"\\]+/),
|
||||
token.immediate("\\ "),
|
||||
)),
|
||||
|
||||
escape_sequence: $ => token.immediate(seq(
|
||||
'\\',
|
||||
choice(
|
||||
/[^xuU]/,
|
||||
/\d{2,3}/,
|
||||
/x[0-9a-fA-F]{2,}/,
|
||||
/u[0-9a-fA-F]{4}/,
|
||||
/U[0-9a-fA-F]{8}/
|
||||
)
|
||||
)),
|
||||
|
||||
_non_newline_whitespace: $ => /[\t ]*/,
|
||||
|
||||
comment: $ => seq("#", /.*/),
|
||||
}
|
||||
});
|
||||
|
17
package.json
Normal file
17
package.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "tree-sitter-dockerfile",
|
||||
"version": "0.1.0",
|
||||
"description": "A tree-sitter module for the Dockerfile grammar",
|
||||
"main": "bindings/node",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Camden Cheek <camden@ccheek.com>",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"nan": "^2.14.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tree-sitter-cli": "^0.19.4"
|
||||
}
|
||||
}
|
1127
src/grammar.json
Normal file
1127
src/grammar.json
Normal file
File diff suppressed because it is too large
Load diff
738
src/node-types.json
Normal file
738
src/node-types.json
Normal file
|
@ -0,0 +1,738 @@
|
|||
[
|
||||
{
|
||||
"type": "add_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "param",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "arg_instruction",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"default": {
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "double_quoted_string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"name": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "cmd_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "shell_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string_array",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "comment",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "copy_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "param",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "double_quoted_string",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "entrypoint_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "shell_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string_array",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "env_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "env_pair",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "env_pair",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"name": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "double_quoted_string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "expose_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expose_port",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "expose_port",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "from_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "image_spec",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "name",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "param",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "healthcheck_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "cmd_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "param",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "image_spec",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "image_digest",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "image_tag",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "label_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "label_pair",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "label_pair",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"key": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"value": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "double_quoted_string",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "onbuild_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "add_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "arg_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "cmd_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "copy_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "entrypoint_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "env_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expose_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "from_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "healthcheck_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "label_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "onbuild_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "run_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "shell_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "stopsignal_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "user_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "volume_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "workdir_instruction",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "param",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "run_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "shell_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string_array",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "shell_command",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "shell_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "string_array",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "source_file",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "add_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "arg_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "cmd_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "copy_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "entrypoint_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "env_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expose_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "from_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "healthcheck_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "label_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "onbuild_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "run_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "shell_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "stopsignal_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "user_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "volume_instruction",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "workdir_instruction",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "stopsignal_instruction",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "string_array",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "double_quoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "user_instruction",
|
||||
"named": true,
|
||||
"fields": {
|
||||
"group": {
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"user": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "unquoted_string",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "volume_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "path",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "string_array",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "workdir_instruction",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "path",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "\n",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "\"",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "#",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ",",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "--",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "/tcp",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "/udp",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": ":",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ADD",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ARG",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "AS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "CMD",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "COPY",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ENTRYPOINT",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ENV",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "EXPOSE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "FROM",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "HEALTHCHECK",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "LABEL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "NONE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ONBUILD",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "RUN",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "SHELL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "STOPSIGNAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "USER",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "VOLUME",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "WORKDIR",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "[",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "\\\n",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "\\ ",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "]",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "image_digest",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "image_tag",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "name",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "name",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "path",
|
||||
"named": true
|
||||
}
|
||||
]
|
5892
src/parser.c
Normal file
5892
src/parser.c
Normal file
File diff suppressed because it is too large
Load diff
223
src/tree_sitter/parser.h
Normal file
223
src/tree_sitter/parser.h
Normal file
|
@ -0,0 +1,223 @@
|
|||
#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 **symbol_names;
|
||||
const char **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;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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_
|
Loading…
Reference in a new issue