MCPcopy Create free account
hub / github.com/MariaSolOs/shebling / function

Function function

crates/shebling-parser-old/src/parser/function.rs:26–104  ·  view source on GitHub ↗
(span: Span)

Source from the content-addressed store, hash-verified

24}
25
26pub(super) fn function(span: Span) -> ParseResult<Function> {
27 fn parens(span: Span) -> ParseResult<()> {
28 swallow(pair(
29 terminated(char('('), trivia),
30 terminated(
31 alt((char(')'), |span| {
32 // No need for parameter lists.
33 let (span, (_, range)) = ranged(is_not("\n){"))(span)?;
34 span.extra.diag(
35 ParseDiagnostic::builder(ParseDiagnosticKind::NotShellCode)
36 .label("parameter list", range)
37 .help("Just use '()' and refer to the parameters as $1, $2..."),
38 );
39
40 char(')')(span)
41 })),
42 trivia,
43 ),
44 ))(span)
45 }
46
47 fn with_keyword(span: Span) -> ParseResult<String> {
48 // Read 'function' followed by the name.
49 let (span, name) = preceded(
50 pair(token(Keyword::Function), many1(line_space)),
51 recognize_string(many1(alt((
52 satisfy(|c: char| c.is_ascii_alphanumeric()),
53 one_of("_:+?-./^@,[]*=!"),
54 )))),
55 )(span)?;
56
57 let (span, (trivia, parens, body_follows)) =
58 tuple((trivia, opt(parens), followed_by(one_of("{("))))(span)?;
59
60 // Without parentheses, we need space before the function's body.
61 if trivia.is_empty() && parens.is_none() && body_follows {
62 span.extra.diag(
63 ParseDiagnostic::builder(ParseDiagnosticKind::MissingSpace)
64 .range(&span)
65 .help("Add a space or new line between the function name and body."),
66 );
67 }
68
69 Ok((span, name))
70 }
71
72 fn without_keyword(span: Span) -> ParseResult<String> {
73 // Read the name, making sure it isn't 'time'.
74 let (span, name) = verify(
75 recognize_string(many1(alt((
76 satisfy(|c: char| c.is_ascii_alphanumeric()),
77 one_of("_:+?-./^@,"),
78 )))),
79 |name: &String| name != "time",
80 )(span)?;
81
82 let (span, _) = pair(trivia, parens)(span)?;
83

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected