Add 'vendor/tree-sitter-elvish/' from commit 'e50787cadd3bc54f6d9c0704493a79078bb8a4e5'

git-subtree-dir: vendor/tree-sitter-elvish
git-subtree-mainline: a8d064eacf
git-subtree-split: e50787cadd
pull/226/head
cherryblossom 2022-05-07 20:10:28 +07:00
commit ffcb39e041
19 changed files with 22791 additions and 0 deletions

@ -0,0 +1,26 @@
[package]
name = "tree-sitter-elvish"
description = "elvish grammar for the tree-sitter parsing library"
version = "0.0.1"
keywords = ["incremental", "parsing", "elvish"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-elvish"
edition = "2018"
license = "0BSD"
build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
[lib]
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "~0.20"
[build-dependencies]
cc = "1.0"

@ -0,0 +1,3 @@
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

@ -0,0 +1,8 @@
tree-sitter-elvish
================
[Elvish](https://elv.sh) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
#### References
* [Elvish Language Specification](https://elv.sh/ref/language.html)

@ -0,0 +1,19 @@
{
"targets": [
{
"target_name": "tree_sitter_elvish_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",
]
}
]
}

@ -0,0 +1,28 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_elvish();
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_elvish());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("elvish").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_elvish_binding, Init)
} // namespace

@ -0,0 +1,19 @@
try {
module.exports = require("../../build/Release/tree_sitter_elvish_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_elvish_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}

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

@ -0,0 +1,52 @@
//! This crate provides elvish 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_elvish::language()).expect("Error loading elvish 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_elvish() -> 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_elvish() }
}
/// 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 elvish language");
}
}

@ -0,0 +1,308 @@
// SPDX-License-Identifier: 0BSD
// SPDX-FileCopyrightText: 2022 Tobias Frilling
module.exports = grammar({
name: 'elvish',
extras: $ => [
/\s/,
$.comment
],
word: $ => $.identifier,
inline: $ => [
$._statement,
$._expression,
$._literal,
$._string_like,
$._terminator,
],
rules: {
source_file: $ => optional($._statements),
comment: $ => token(seq('#', /.*/)),
_statements: $ => prec(1, seq(
repeat(seq(
$._statement,
$._terminator
)),
$._statement,
optional($._terminator)
)),
_statement: $ => choice(
$.command,
$.if,
$.while,
$.for,
$.try,
$.import,
$.function_definition,
$.variable_declaration,
$.variable_assignment,
$.temporary_assignment,
$.variable_deletion,
$.lambda,
$.pipeline,
),
_expression: $ => choice(
$._literal,
$.variable,
$.output_capture,
$.exception_capture,
$.braced_list,
$.indexing,
$.lambda,
$.wildcard
),
_literal: $ => choice(
$.number,
$._string_like,
$.list,
$.map,
),
_terminator: $ => choice(";", "\n"),
identifier: $ => /[\p{L}\p{N}_:~-]+/,
// ==========
// Statements
// ==========
//
import: $ => seq(
"use",
$._string_like,
optional($._string_like)
),
command: $ => seq(
field("head", choice(
$.identifier,
$.variable,
$.output_capture,
"+", "-", "*", "/", "%", "<", "<=","==", "!=",
">", ">=", "<s", "<=s", "==s", "!=s", ">s", ">=s"
)),
repeat(field("argument", choice($._expression, $.option))),
optional($.redirection),
optional("&"),
),
pipeline: $ => seq(
repeat1(seq($.command, "|")),
$.command
),
redirection: $ => {
const port = token(
choice(/\d+/, "-", "stdin", "stdout", "stderr")
)
return seq(
choice(
">", "<", ">>", "<>",
// Why do I have to wrap this in a token?
alias(token(
seq(port, token.immediate(">"))
), $.io_port),
),
choice(
alias($.bareword, $.file),
alias(token(seq(optional("&"), port)), $.io_port)
)
)
},
variable_declaration: $ => seq("var", $._assignment),
variable_assignment: $ => seq("set", $._assignment),
temporary_assignment: $ => seq("tmp", $._assignment),
variable_deletion: $ => seq("del", repeat1($.identifier)),
_assignment: $ => seq(
alias(repeat1(seq(
optional("@"),
$.identifier,
repeat(seq(
token.immediate("["),
alias(repeat1($._expression), $.indices),
"]"
))
)),
$.lhs
),
optional(seq(
"=",
alias(repeat1($._expression), $.rhs)
))
),
function_definition: $ => seq(
"fn", $.identifier, $.lambda
),
if: $ => seq(
"if", field("condition", $._expression),
"{", alias($._statements, $.chunk), "}",
optional($.elif),
optional($.else),
),
elif: $ => seq(
"elif", field("condition", $._expression),
"{", alias($._statements, $.chunk), "}"
),
else: $ => seq("else", "{", alias($._statements, $.chunk), "}"),
while: $ => seq(
"while", field("condition", $._expression),
"{", alias($._statements, $.chunk), "}",
optional($.else),
),
for: $ => seq(
"for",
field("var", $.identifier),
field("container", $._expression),
"{", alias($._statements, $.chunk), "}",
optional($.else),
),
try: $ => seq(
"try", "{", alias($._statements, $.chunk), "}",
optional($.catch),
optional($.else),
optional($.finally),
),
catch: $ => seq(
"catch", field("exception", $.identifier),
"{", alias($._statements, $.chunk), "}"
),
finally: $ => seq("finally", "{", alias($._statements, $.chunk), "}"),
// ===========
// Expressions
// ===========
lambda: $ => seq(
"{",
choice(/\s+/, $.parameter_list),
alias($._statements, $.chunk),
"}"
),
parameter_list: $ => seq(
"|",
repeat1(field(
"parameter",
choice(
$.option,
seq(optional("@"), $.identifier),
)
)),
"|"
),
option: $ => seq(
"&", $.identifier, "=", $._expression
),
indexing: $ => seq(
choice(
$.variable,
$.list,
$.map,
$.output_capture,
),
repeat1(seq(
token.immediate("["),
alias(repeat1($._expression), $.indices),
"]"
)),
),
braced_list: $ => seq(
"{", repeat($._expression), "}"
),
output_capture: $ => seq(
"(", alias($._statements, $.chunk), ")"
),
exception_capture: $ => seq(
"?(", alias($._statements, $.chunk), ")"
),
variable: $ => choice(
seq("$", optional("@"), $.identifier),
),
number: $ => {
const decimal = /\d(_?\d)*/
const integer = choice(
decimal,
seq(choice("0x", "0X"), /[\da-fA-F](_?[\da-fA-F])*/),
seq(choice("0o", "0O"), /[0-7](_?[0-7])*/),
seq(choice('0b', '0B'), /[0-1](_?[0-1])*/),
)
return token(seq(
optional(choice("+", "-")),
choice(
integer,
seq(integer, "/", integer),
seq(
choice(
seq(decimal, optional("."), optional(decimal)),
seq(".", decimal)
),
optional(seq(/[eE][+-]?/, decimal))
),
"Inf",
"NaN"
)
))
},
_string_like: $ => choice($.string, $.bareword),
string: $ => token(choice(
seq("'", /([^']|'')*/, "'"),
seq('"', /([^"]|\\")*/, '"')
)),
bareword: $ => /[\p{L}\p{N}!%+,./:@\\_~=-]+/,
wildcard: $ => seq(
choice("*", "**", "?"),
repeat(seq(
token.immediate("["),
alias($._expression, $.modifier),
"]"
))
),
list: $ => seq("[", repeat($._expression), "]"),
map: $ => seq("[", repeat1($.pair), "]"),
pair: $ => seq(
"&",
field("key", $.identifier),
"=",
field("value", $._expression)
),
}
});

@ -0,0 +1,19 @@
{
"name": "tree-sitter-elvish",
"version": "0.0.1",
"description": "elvish grammar for tree-sitter",
"main": "bindings/node",
"keywords": [
"parsing",
"incremental"
],
"dependencies": {
"nan": "^2.12.1"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.6"
},
"scripts": {
"test": "tree-sitter test"
}
}

@ -0,0 +1,82 @@
;; SPDX-License-Identifier: 0BSD
;; SPDX-FileCopyrightText: 2022 Tobias Frilling
(comment) @comment
(if "if" @conditional)
(if (elif "elif" @conditional))
(if (else "else" @conditional))
(while "while" @repeat)
(while (else "else" @repeat))
(for "for" @repeat)
(for (else "else" @repeat))
(try "try" @exception)
(try (catch "catch" @exception))
(try (else "else" @exception))
(try (finally "finally" @exception))
(import "use" @include)
(import (bareword) @string.special)
(wildcard ["*" "**" "?"] @string.special)
(command argument: (bareword) @parameter)
(command head: (identifier) @function)
((command head: (identifier) @keyword.return)
(#eq? @keyword.return "return"))
((command (identifier) @keyword.operator)
(#any-of? @keyword.operator "and" "or" "coalesce"))
((command head: _ @function)
(#any-of? @function
"+" "-" "*" "/" "%" "<" "<=""==" "!=" ">"
">=" "<s" "<=s" "==s" "!=s" ">s" ">=s"
))
(pipeline "|" @operator)
(redirection [">" "<" ">>" "<>"] @operator)
(io_port) @number
(function_definition
"fn" @keyword.function
(identifier) @function)
(parameter_list) @parameter
(parameter_list "|" @punctuation.bracket)
(variable_declaration
"var" @keyword
(lhs (identifier) @variable))
(variable_assignment
"set" @keyword
(lhs (identifier) @variable))
(temporary_assignment
"tmp" @keyword
(lhs (identifier) @variable))
(variable_deletion
"del" @keyword
(identifier) @variable)
(number) @number
(string) @string
(variable (identifier) @variable)
((variable (identifier) @function)
(#match? @function ".+\\~$"))
((variable (identifier) @boolean)
(#any-of? @boolean "true" "false"))
((variable (identifier) @constant.builtin)
(#any-of? @constant.builtin
"_" "after-chdir" "args" "before-chdir" "buildinfo" "nil"
"notify-bg-job-success" "num-bg-jobs" "ok" "paths" "pid"
"pwd" "value-out-indicator" "version"))
["$" "@"] @punctuation.special
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
";" @punctuation.delimiter

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -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_

@ -0,0 +1,117 @@
===
Variable
===
nop $foo $edit:location:start $E:PATH
---
(source_file
(command (identifier)
(variable (identifier))
(variable (identifier))
(variable (identifier))))
===
Output Capture
===
nop (nop)
---
(source_file
(command (identifier)
(output_capture
(chunk (command (identifier))))))
===
Exception Capture
===
nop ?(nop)
---
(source_file
(command (identifier)
(exception_capture
(chunk (command (identifier))))))
===
Braced list
===
nop {a b} {}
---
(source_file
(command (identifier)
(braced_list (bareword) (bareword))
(braced_list)))
===
Indexing
===
nop [a b][0 1] [&a=lorem &b=ipsum][a b] $list[(put 1)] $list[$indices] $list[0][0]
---
(source_file
(command (identifier)
(indexing
(list (bareword) (bareword))
(indices (number) (number)))
(indexing
(map
(pair (identifier) (bareword))
(pair (identifier) (bareword)))
(indices (bareword) (bareword)))
(indexing
(variable (identifier))
(indices (output_capture
(chunk (command (identifier) (number))))))
(indexing
(variable (identifier))
(indices (variable (identifier))))
(indexing
(variable (identifier))
(indices (number))
(indices (number)))))
===
Lambdas
===
nop { nop} {|a| nop} {|a|nop} {|&o=0|nop}
---
(source_file
(command (identifier)
(lambda (chunk (command (identifier))))
(lambda (parameter_list (identifier))
(chunk (command (identifier))))
(lambda (parameter_list (identifier))
(chunk (command (identifier))))
(lambda
(parameter_list
(option (identifier) (number)))
(chunk (command (identifier))))))
===
Wildcard
===
nop * ** ? *[set:aeoiu] *[set:abc][range:0-9]
---
(source_file
(command (identifier)
(wildcard)
(wildcard)
(wildcard)
(wildcard (modifier))
(wildcard (modifier) (modifier))))

@ -0,0 +1,118 @@
===
Strings
===
nop '*\' 'it''s'
nop "my name is $name" "quoted \" test"
---
(source_file
(command (identifier) (string) (string))
(command (identifier) (string) (string)))
===
Barewords
===
nop a.txt long-bareword elf@elv.sh /usr/local/bin 7of9
---
(source_file
(command
(identifier)
(bareword)
(bareword)
(bareword)
(bareword)
(bareword)))
===
Integers
===
nop 10 0xaAbBcC_eE_fF 0o1_2_3 0b10_10 1_000_000
---
(source_file
(command
(identifier)
(number)
(number)
(number)
(number)
(number)))
===
Rationals
===
nop 1/2 0x10/100
---
(source_file
(command
(identifier)
(number)
(number)))
===
Floats
===
nop 10.0 .1 10. 1e1 1.234_567e-1_2_3 Inf NaN
---
(source_file
(command
(identifier)
(number)
(number)
(number)
(number)
(number)
(number)
(number)))
===
Lists
===
nop [] [[]] [a b] [
a
b
]
---
(source_file
(command
(identifier)
(list)
(list (list))
(list (bareword) (bareword))
(list (bareword) (bareword))))
===
Maps
===
nop [&foo=bar &lorem = ipsum] [
&foo=bar
&lorem = ipsum
]
---
(source_file
(command
(identifier)
(map
(pair (identifier) (bareword))
(pair (identifier) (bareword)))
(map
(pair (identifier) (bareword))
(pair (identifier) (bareword)))))

@ -0,0 +1,188 @@
===
Commands
===
nop a
$nop~ a
(put $nop~) a
nop &o=0
---
(source_file
(command (identifier) (bareword))
(command (variable (identifier)) (bareword))
(command
(output_capture (chunk
(command (identifier) (variable (identifier)))))
(bareword))
(command (identifier)
(option (identifier) (number))))
===
Pipeline
===
put a | put b | nop
---
(source_file
(pipeline
(command (identifier) (bareword))
(command (identifier) (bareword))
(command (identifier))))
===
Redirection
===
echo haha > log
foo >&2
bad 2> error
bad stderr> error
bad 2>&1
---
(source_file
(command (identifier) (bareword)
(redirection (file)))
(command (identifier)
(redirection (io_port)))
(command (identifier)
(redirection (io_port) (file)))
(command (identifier)
(redirection (io_port) (file)))
(command (identifier)
(redirection (io_port) (io_port))))
===
Conditional
===
if $false {
nop
} elif $true {
nop
} else {
nop
}
---
(source_file
(if (variable (identifier)) (chunk (command (identifier)))
(elif (variable (identifier)) (chunk (command (identifier))))
(else (chunk (command (identifier))))))
===
While loop
===
while $true {
nop
} else {
nop
}
---
(source_file
(while (variable (identifier)) (chunk (command (identifier)))
(else (chunk (command (identifier))))))
===
For loop
===
for e [a b] {
nop
} else {
nop
}
---
(source_file
(for (identifier) (list (bareword) (bareword))
(chunk (command (identifier)))
(else (chunk (command (identifier))))))
===
Exception control
===
try {
nop
} catch ident {
nop
} else {
nop
} finally {
nop
}
---
(source_file
(try (chunk (command (identifier)))
(catch (identifier) (chunk (command (identifier))))
(else (chunk (command (identifier))))
(finally (chunk (command (identifier))))))
===
Imports
===
use path
use a/b/c
use a/b/c foo
---
(source_file
(import (bareword))
(import (bareword))
(import (bareword) (bareword)))
===
Function definition
===
fn f { nop }
---
(source_file
(function_definition (identifier)
(lambda (chunk (command (identifier))))))
===
Variable delcaration/assigment
===
var a
var a b = foo bar
set x = foo
set list[1] = x
tmp y = bar
del x
---
(source_file
(variable_declaration (lhs (identifier)))
(variable_declaration
(lhs (identifier) (identifier))
(rhs (bareword) (bareword)))
(variable_assignment
(lhs (identifier)) (rhs (bareword)))
(variable_assignment
(lhs
(identifier)
(indices (number)))
(rhs (bareword)))
(temporary_assignment
(lhs (identifier)) (rhs (bareword)))
(variable_deletion (identifier)))