1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! `Checker` implementation for Tcl.
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
use super::*;
use crate::lang_helpers::tcl::BRACED_WORD_KINDS;
impl Checker for TclCode {
fn is_comment(node: &Node) -> bool {
node.kind_id() == Tcl::Comment
}
fn is_func_space(node: &Node) -> bool {
matches!(node.kind_id().into(), Tcl::SourceFile | Tcl::Procedure)
}
fn is_func<'a>(node: &Node<'a>, _ancestors: Ancestors<'a, '_>) -> bool {
node.kind_id() == Tcl::Procedure
}
// Tcl closures (`apply`) are ordinary commands; the grammar has no distinct closure node.
fn is_closure<'a>(_: &Node<'a>, _ancestors: Ancestors<'a, '_>) -> bool {
false
}
fn is_call(node: &Node) -> bool {
node.kind_id() == Tcl::Command
}
// Tcl arguments are whitespace-separated; no punctuation to exclude.
fn is_non_arg(_: &Node) -> bool {
false
}
// `BracedWord` is listed because it *is* the literal of
// `lappend x {a b}` — the grammar reserves `BracedWordSimple` for the
// handful of commands it models (`set`, `foreach`, `regexp`, …) and
// spells every other command's braced argument `BracedWord`. The same
// kind is also the `proc` / `if` body, which this table cannot
// exclude; `is_string_with_code` below does, and is what the walk
// calls.
impl_simple_is_string!(Tcl, QuotedWord, BracedWord, BracedWordSimple);
// The half of the rule that needs the source bytes (#1381), the twin
// of `TclCode::get_op_type_with_code`. Since #1382 both call the same
// `Getter::is_braced_script_word` over one kinds table rather than two
// copies of the reasoning (grammar-dispatch §7), so the value slots
// `is_braced_literal_slot` names (`proc {my proc}`,
// `namespace export {…}`) are a literal to both. They part company in
// one known place: Halstead's *operand* half keys on whether a body
// holds a command, so an empty or comment-only `proc` body is an
// operand there and not a string here.
fn is_string_with_code<'a>(node: &Node<'a>, code: &[u8], ancestors: Ancestors<'a, '_>) -> bool {
Self::is_string(node)
&& !<Self as Getter>::is_braced_script_word(node, code, ancestors, &BRACED_WORD_KINDS)
}
// Tcl grammar has a dedicated `elseif` named node, not a nested `if`.
impl_is_else_if_clause!(Tcl, Elseif);
}