use crate::facts::{Declaration, DeclarationKind, Facts, Import, Reference, ReferenceKind, Span};
use crate::syntax::Language;
use crate::token::{Mode, Token, TokenKind, Tokenizer};
#[must_use]
pub fn extract(source: &str) -> Facts {
let tokens = Tokenizer::new(source, Language::Bash)
.mode(Mode::Lite)
.collect::<Vec<_>>();
let mut state = Extractor {
source,
tokens: &tokens,
facts: Facts::default(),
function: None,
depth: 0,
};
state.run();
state.facts
}
const CLIENTS: &[&str] = &[
"curl", "wget", "http", "https", "xh", "httpie", "nc", "ncat", "grpcurl", "ab", "hey", "siege",
"wrk",
];
const RUNNERS: &[&str] = &["source", ".", "bash", "sh", "zsh", "ksh"];
const KEYWORDS: &[&str] = &[
"then", "do", "else", "elif", "fi", "done", "if", "while", "until", "for", "case", "esac",
"in", "function", "return", "local", "export", "declare", "readonly", "eval", "exec", "time",
];
struct Extractor<'source, 'tokens> {
source: &'source str,
tokens: &'tokens [Token],
facts: Facts,
function: Option<(String, i32)>,
depth: i32,
}
fn endpoints(arguments: &[String]) -> Vec<String> {
let mut found = Vec::new();
let mut expecting_method = false;
for argument in arguments {
if expecting_method {
found.push(argument.clone());
expecting_method = false;
continue;
}
if argument == "-X" || argument == "--request" {
expecting_method = true;
continue;
}
if argument.contains("://") || argument.starts_with("localhost:") {
found.push(argument.clone());
}
}
found
}
mod extractor;
#[cfg(test)]
mod tests;