Merge pull request #2606 from ahlinc/ffi-rm-c-enum-pfx
chore(ffi): remove enum name prefixes from all C enum values
This commit is contained in:
commit
796c5a2ccf
6 changed files with 57 additions and 58 deletions
|
|
@ -448,8 +448,8 @@ fn run() -> Result<()> {
|
|||
matches
|
||||
.values_of("encoding")
|
||||
.map_or(Ok(None), |mut e| match e.next() {
|
||||
Some("utf16") => Ok(Some(ffi::TSInputEncoding_TSInputEncodingUTF16)),
|
||||
Some("utf8") => Ok(Some(ffi::TSInputEncoding_TSInputEncodingUTF8)),
|
||||
Some("utf16") => Ok(Some(ffi::TSInputEncodingUTF16)),
|
||||
Some("utf8") => Ok(Some(ffi::TSInputEncodingUTF8)),
|
||||
Some(_) => Err(anyhow!("Invalid encoding. Expected one of: utf8, utf16")),
|
||||
None => Ok(None),
|
||||
})?;
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ pub fn parse_file_at_path(opts: ParseFileOptions) -> Result<bool> {
|
|||
}
|
||||
|
||||
let tree = match opts.encoding {
|
||||
Some(encoding) if encoding == ffi::TSInputEncoding_TSInputEncodingUTF16 => {
|
||||
Some(encoding) if encoding == ffi::TSInputEncodingUTF16 => {
|
||||
let source_code_utf16 = source_code
|
||||
.chunks_exact(2)
|
||||
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ pub struct TSQueryCursor {
|
|||
pub struct TSLookaheadIterator {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
pub const TSInputEncoding_TSInputEncodingUTF8: TSInputEncoding = 0;
|
||||
pub const TSInputEncoding_TSInputEncodingUTF16: TSInputEncoding = 1;
|
||||
pub const TSInputEncodingUTF8: TSInputEncoding = 0;
|
||||
pub const TSInputEncodingUTF16: TSInputEncoding = 1;
|
||||
pub type TSInputEncoding = ::std::os::raw::c_uint;
|
||||
pub const TSSymbolType_TSSymbolTypeRegular: TSSymbolType = 0;
|
||||
pub const TSSymbolType_TSSymbolTypeAnonymous: TSSymbolType = 1;
|
||||
pub const TSSymbolType_TSSymbolTypeAuxiliary: TSSymbolType = 2;
|
||||
pub const TSSymbolTypeRegular: TSSymbolType = 0;
|
||||
pub const TSSymbolTypeAnonymous: TSSymbolType = 1;
|
||||
pub const TSSymbolTypeAuxiliary: TSSymbolType = 2;
|
||||
pub type TSSymbolType = ::std::os::raw::c_uint;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
|
|
@ -70,8 +70,8 @@ pub struct TSInput {
|
|||
>,
|
||||
pub encoding: TSInputEncoding,
|
||||
}
|
||||
pub const TSLogType_TSLogTypeParse: TSLogType = 0;
|
||||
pub const TSLogType_TSLogTypeLex: TSLogType = 1;
|
||||
pub const TSLogTypeParse: TSLogType = 0;
|
||||
pub const TSLogTypeLex: TSLogType = 1;
|
||||
pub type TSLogType = ::std::os::raw::c_uint;
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
|
|
@ -115,11 +115,11 @@ pub struct TSQueryCapture {
|
|||
pub node: TSNode,
|
||||
pub index: u32,
|
||||
}
|
||||
pub const TSQuantifier_TSQuantifierZero: TSQuantifier = 0;
|
||||
pub const TSQuantifier_TSQuantifierZeroOrOne: TSQuantifier = 1;
|
||||
pub const TSQuantifier_TSQuantifierZeroOrMore: TSQuantifier = 2;
|
||||
pub const TSQuantifier_TSQuantifierOne: TSQuantifier = 3;
|
||||
pub const TSQuantifier_TSQuantifierOneOrMore: TSQuantifier = 4;
|
||||
pub const TSQuantifierZero: TSQuantifier = 0;
|
||||
pub const TSQuantifierZeroOrOne: TSQuantifier = 1;
|
||||
pub const TSQuantifierZeroOrMore: TSQuantifier = 2;
|
||||
pub const TSQuantifierOne: TSQuantifier = 3;
|
||||
pub const TSQuantifierOneOrMore: TSQuantifier = 4;
|
||||
pub type TSQuantifier = ::std::os::raw::c_uint;
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
|
|
@ -129,9 +129,9 @@ pub struct TSQueryMatch {
|
|||
pub capture_count: u16,
|
||||
pub captures: *const TSQueryCapture,
|
||||
}
|
||||
pub const TSQueryPredicateStepType_TSQueryPredicateStepTypeDone: TSQueryPredicateStepType = 0;
|
||||
pub const TSQueryPredicateStepType_TSQueryPredicateStepTypeCapture: TSQueryPredicateStepType = 1;
|
||||
pub const TSQueryPredicateStepType_TSQueryPredicateStepTypeString: TSQueryPredicateStepType = 2;
|
||||
pub const TSQueryPredicateStepTypeDone: TSQueryPredicateStepType = 0;
|
||||
pub const TSQueryPredicateStepTypeCapture: TSQueryPredicateStepType = 1;
|
||||
pub const TSQueryPredicateStepTypeString: TSQueryPredicateStepType = 2;
|
||||
pub type TSQueryPredicateStepType = ::std::os::raw::c_uint;
|
||||
#[repr(C)]
|
||||
#[derive(Debug)]
|
||||
|
|
@ -139,13 +139,13 @@ pub struct TSQueryPredicateStep {
|
|||
pub type_: TSQueryPredicateStepType,
|
||||
pub value_id: u32,
|
||||
}
|
||||
pub const TSQueryError_TSQueryErrorNone: TSQueryError = 0;
|
||||
pub const TSQueryError_TSQueryErrorSyntax: TSQueryError = 1;
|
||||
pub const TSQueryError_TSQueryErrorNodeType: TSQueryError = 2;
|
||||
pub const TSQueryError_TSQueryErrorField: TSQueryError = 3;
|
||||
pub const TSQueryError_TSQueryErrorCapture: TSQueryError = 4;
|
||||
pub const TSQueryError_TSQueryErrorStructure: TSQueryError = 5;
|
||||
pub const TSQueryError_TSQueryErrorLanguage: TSQueryError = 6;
|
||||
pub const TSQueryErrorNone: TSQueryError = 0;
|
||||
pub const TSQueryErrorSyntax: TSQueryError = 1;
|
||||
pub const TSQueryErrorNodeType: TSQueryError = 2;
|
||||
pub const TSQueryErrorField: TSQueryError = 3;
|
||||
pub const TSQueryErrorCapture: TSQueryError = 4;
|
||||
pub const TSQueryErrorStructure: TSQueryError = 5;
|
||||
pub const TSQueryErrorLanguage: TSQueryError = 6;
|
||||
pub type TSQueryError = ::std::os::raw::c_uint;
|
||||
extern "C" {
|
||||
#[doc = " Create a new parser."]
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ fn generate_bindings() {
|
|||
.allowlist_function("^ts_.*")
|
||||
.allowlist_var("^TREE_SITTER.*")
|
||||
.no_copy(no_copy.join("|"))
|
||||
.prepend_enum_name(false)
|
||||
.generate()
|
||||
.expect("Failed to generate bindings");
|
||||
|
||||
|
|
|
|||
|
|
@ -137,11 +137,11 @@ pub enum CaptureQuantifier {
|
|||
impl From<ffi::TSQuantifier> for CaptureQuantifier {
|
||||
fn from(value: ffi::TSQuantifier) -> Self {
|
||||
match value {
|
||||
ffi::TSQuantifier_TSQuantifierZero => CaptureQuantifier::Zero,
|
||||
ffi::TSQuantifier_TSQuantifierZeroOrOne => CaptureQuantifier::ZeroOrOne,
|
||||
ffi::TSQuantifier_TSQuantifierZeroOrMore => CaptureQuantifier::ZeroOrMore,
|
||||
ffi::TSQuantifier_TSQuantifierOne => CaptureQuantifier::One,
|
||||
ffi::TSQuantifier_TSQuantifierOneOrMore => CaptureQuantifier::OneOrMore,
|
||||
ffi::TSQuantifierZero => CaptureQuantifier::Zero,
|
||||
ffi::TSQuantifierZeroOrOne => CaptureQuantifier::ZeroOrOne,
|
||||
ffi::TSQuantifierZeroOrMore => CaptureQuantifier::ZeroOrMore,
|
||||
ffi::TSQuantifierOne => CaptureQuantifier::One,
|
||||
ffi::TSQuantifierOneOrMore => CaptureQuantifier::OneOrMore,
|
||||
_ => panic!("Unrecognized quantifier: {}", value),
|
||||
}
|
||||
}
|
||||
|
|
@ -312,14 +312,12 @@ impl Language {
|
|||
/// Check if the node type for the given numerical id is named (as opposed
|
||||
/// to an anonymous node type).
|
||||
pub fn node_kind_is_named(&self, id: u16) -> bool {
|
||||
unsafe { ffi::ts_language_symbol_type(self.0, id) == ffi::TSSymbolType_TSSymbolTypeRegular }
|
||||
unsafe { ffi::ts_language_symbol_type(self.0, id) == ffi::TSSymbolTypeRegular }
|
||||
}
|
||||
|
||||
#[doc(alias = "ts_language_symbol_type")]
|
||||
pub fn node_kind_is_visible(&self, id: u16) -> bool {
|
||||
unsafe {
|
||||
ffi::ts_language_symbol_type(self.0, id) <= ffi::TSSymbolType_TSSymbolTypeAnonymous
|
||||
}
|
||||
unsafe { ffi::ts_language_symbol_type(self.0, id) <= ffi::TSSymbolTypeAnonymous }
|
||||
}
|
||||
|
||||
/// Get the number of distinct field names in this language.
|
||||
|
|
@ -445,7 +443,7 @@ impl Parser {
|
|||
) {
|
||||
let callback = (payload as *mut Logger).as_mut().unwrap();
|
||||
if let Ok(message) = CStr::from_ptr(c_message).to_str() {
|
||||
let log_type = if c_log_type == ffi::TSLogType_TSLogTypeParse {
|
||||
let log_type = if c_log_type == ffi::TSLogTypeParse {
|
||||
LogType::Parse
|
||||
} else {
|
||||
LogType::Lex
|
||||
|
|
@ -571,7 +569,7 @@ impl Parser {
|
|||
let c_input = ffi::TSInput {
|
||||
payload: &mut payload as *mut (&mut F, Option<T>) as *mut c_void,
|
||||
read: Some(read::<T, F>),
|
||||
encoding: ffi::TSInputEncoding_TSInputEncodingUTF8,
|
||||
encoding: ffi::TSInputEncodingUTF8,
|
||||
};
|
||||
|
||||
let c_old_tree = old_tree.map_or(ptr::null_mut(), |t| t.0.as_ptr());
|
||||
|
|
@ -627,7 +625,7 @@ impl Parser {
|
|||
let c_input = ffi::TSInput {
|
||||
payload: &mut payload as *mut (&mut F, Option<T>) as *mut c_void,
|
||||
read: Some(read::<T, F>),
|
||||
encoding: ffi::TSInputEncoding_TSInputEncodingUTF16,
|
||||
encoding: ffi::TSInputEncodingUTF16,
|
||||
};
|
||||
|
||||
let c_old_tree = old_tree.map_or(ptr::null_mut(), |t| t.0.as_ptr());
|
||||
|
|
@ -1568,7 +1566,7 @@ impl Query {
|
|||
|
||||
// On failure, build an error based on the error code and offset.
|
||||
if ptr.is_null() {
|
||||
if error_type == ffi::TSQueryError_TSQueryErrorLanguage {
|
||||
if error_type == ffi::TSQueryErrorLanguage {
|
||||
return Err(QueryError {
|
||||
row: 0,
|
||||
column: 0,
|
||||
|
|
@ -1600,18 +1598,16 @@ impl Query {
|
|||
let message;
|
||||
match error_type {
|
||||
// Error types that report names
|
||||
ffi::TSQueryError_TSQueryErrorNodeType
|
||||
| ffi::TSQueryError_TSQueryErrorField
|
||||
| ffi::TSQueryError_TSQueryErrorCapture => {
|
||||
ffi::TSQueryErrorNodeType | ffi::TSQueryErrorField | ffi::TSQueryErrorCapture => {
|
||||
let suffix = source.split_at(offset).1;
|
||||
let end_offset = suffix
|
||||
.find(|c| !char::is_alphanumeric(c) && c != '_' && c != '-')
|
||||
.unwrap_or(suffix.len());
|
||||
message = suffix.split_at(end_offset).0.to_string();
|
||||
kind = match error_type {
|
||||
ffi::TSQueryError_TSQueryErrorNodeType => QueryErrorKind::NodeType,
|
||||
ffi::TSQueryError_TSQueryErrorField => QueryErrorKind::Field,
|
||||
ffi::TSQueryError_TSQueryErrorCapture => QueryErrorKind::Capture,
|
||||
ffi::TSQueryErrorNodeType => QueryErrorKind::NodeType,
|
||||
ffi::TSQueryErrorField => QueryErrorKind::Field,
|
||||
ffi::TSQueryErrorCapture => QueryErrorKind::Capture,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
}
|
||||
|
|
@ -1624,7 +1620,7 @@ impl Query {
|
|||
"Unexpected EOF".to_string()
|
||||
};
|
||||
kind = match error_type {
|
||||
ffi::TSQueryError_TSQueryErrorStructure => QueryErrorKind::Structure,
|
||||
ffi::TSQueryErrorStructure => QueryErrorKind::Structure,
|
||||
_ => QueryErrorKind::Syntax,
|
||||
};
|
||||
}
|
||||
|
|
@ -1720,20 +1716,21 @@ impl Query {
|
|||
.filter(|(_, c)| *c == '\n')
|
||||
.count();
|
||||
|
||||
let type_done = ffi::TSQueryPredicateStepType_TSQueryPredicateStepTypeDone;
|
||||
let type_capture = ffi::TSQueryPredicateStepType_TSQueryPredicateStepTypeCapture;
|
||||
let type_string = ffi::TSQueryPredicateStepType_TSQueryPredicateStepTypeString;
|
||||
use ffi::TSQueryPredicateStepType as T;
|
||||
const TYPE_DONE: T = ffi::TSQueryPredicateStepTypeDone;
|
||||
const TYPE_CAPTURE: T = ffi::TSQueryPredicateStepTypeCapture;
|
||||
const TYPE_STRING: T = ffi::TSQueryPredicateStepTypeString;
|
||||
|
||||
let mut text_predicates = Vec::new();
|
||||
let mut property_predicates = Vec::new();
|
||||
let mut property_settings = Vec::new();
|
||||
let mut general_predicates = Vec::new();
|
||||
for p in predicate_steps.split(|s| s.type_ == type_done) {
|
||||
for p in predicate_steps.split(|s| s.type_ == TYPE_DONE) {
|
||||
if p.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if p[0].type_ != type_string {
|
||||
if p[0].type_ != TYPE_STRING {
|
||||
return Err(predicate_error(
|
||||
row,
|
||||
format!(
|
||||
|
|
@ -1756,7 +1753,7 @@ impl Query {
|
|||
),
|
||||
));
|
||||
}
|
||||
if p[1].type_ != type_capture {
|
||||
if p[1].type_ != TYPE_CAPTURE {
|
||||
return Err(predicate_error(row, format!(
|
||||
"First argument to #eq? predicate must be a capture name. Got literal \"{}\".",
|
||||
string_values[p[1].value_id as usize],
|
||||
|
|
@ -1769,7 +1766,7 @@ impl Query {
|
|||
"any-eq?" | "any-not-eq?" => false,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
text_predicates.push(if p[2].type_ == type_capture {
|
||||
text_predicates.push(if p[2].type_ == TYPE_CAPTURE {
|
||||
TextPredicateCapture::EqCapture(
|
||||
p[1].value_id,
|
||||
p[2].value_id,
|
||||
|
|
@ -1793,13 +1790,13 @@ impl Query {
|
|||
p.len() - 1
|
||||
)));
|
||||
}
|
||||
if p[1].type_ != type_capture {
|
||||
if p[1].type_ != TYPE_CAPTURE {
|
||||
return Err(predicate_error(row, format!(
|
||||
"First argument to #match? predicate must be a capture name. Got literal \"{}\".",
|
||||
string_values[p[1].value_id as usize],
|
||||
)));
|
||||
}
|
||||
if p[2].type_ == type_capture {
|
||||
if p[2].type_ == TYPE_CAPTURE {
|
||||
return Err(predicate_error(row, format!(
|
||||
"Second argument to #match? predicate must be a literal. Got capture @{}.",
|
||||
capture_names[p[2].value_id as usize],
|
||||
|
|
@ -1850,7 +1847,7 @@ impl Query {
|
|||
p.len() - 1
|
||||
)));
|
||||
}
|
||||
if p[1].type_ != type_capture {
|
||||
if p[1].type_ != TYPE_CAPTURE {
|
||||
return Err(predicate_error(row, format!(
|
||||
"First argument to #any-of? predicate must be a capture name. Got literal \"{}\".",
|
||||
string_values[p[1].value_id as usize],
|
||||
|
|
@ -1860,7 +1857,7 @@ impl Query {
|
|||
let is_positive = operator_name == "any-of?";
|
||||
let mut values = Vec::new();
|
||||
for arg in &p[2..] {
|
||||
if arg.type_ == type_capture {
|
||||
if arg.type_ == TYPE_CAPTURE {
|
||||
return Err(predicate_error(row, format!(
|
||||
"Arguments to #any-of? predicate must be literals. Got capture @{}.",
|
||||
capture_names[arg.value_id as usize],
|
||||
|
|
@ -1884,7 +1881,7 @@ impl Query {
|
|||
args: p[1..]
|
||||
.iter()
|
||||
.map(|a| {
|
||||
if a.type_ == type_capture {
|
||||
if a.type_ == TYPE_CAPTURE {
|
||||
QueryPredicateArg::Capture(a.value_id)
|
||||
} else {
|
||||
QueryPredicateArg::String(
|
||||
|
|
@ -2052,7 +2049,7 @@ impl Query {
|
|||
let mut value = None;
|
||||
|
||||
for arg in args {
|
||||
if arg.type_ == ffi::TSQueryPredicateStepType_TSQueryPredicateStepTypeCapture {
|
||||
if arg.type_ == ffi::TSQueryPredicateStepTypeCapture {
|
||||
if capture_id.is_some() {
|
||||
return Err(predicate_error(
|
||||
row,
|
||||
|
|
|
|||
|
|
@ -35,5 +35,6 @@ bindgen \
|
|||
--allowlist-function '^ts_.*' \
|
||||
--allowlist-var "^TREE_SITTER.*" \
|
||||
--blocklist-type '^__.*' \
|
||||
--no-prepend-enum-name \
|
||||
--no-copy "$no_copy" \
|
||||
$header_path > $output_path
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue