#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
use super::*;
use crate::c_declarator::declarator_name;
const GENERIC_ANGLES: GenericAngleKinds = GenericAngleKinds {
lists: &[
Objc::GenericSpecifier as u16,
Objc::ProtocolReferenceList as u16,
Objc::ParameterizedArguments as u16,
Objc::ArgumentList2 as u16,
],
openers: &[Objc::LT as u16, Objc::LT2 as u16],
closers: &[Objc::GT as u16],
is_misparse: objc_argument_list_misparse,
};
fn objc_argument_list_misparse(list: &Node, _ancestors: Ancestors) -> bool {
list.kind_id() == Objc::ArgumentList2 as u16 && list.has_error()
}
impl Getter for ObjcCode {
fn get_func_space_name<'a, 'tree>(
node: &Node<'tree>,
code: &'a [u8],
_ancestors: Ancestors<'tree, '_>,
) -> Option<&'a str> {
match node.kind_id().into() {
Objc::FunctionDefinition | Objc::FunctionDefinition2 => {
if let Some(name) = declarator_name::<Self>(node)
&& matches!(
name.kind_id().into(),
Objc::TypeIdentifier | Objc::Identifier | Objc::FieldIdentifier
)
{
return node_text(code, &name);
}
}
Objc::MethodDefinition
| Objc::ClassInterface
| Objc::ClassImplementation
| Objc::ProtocolDeclaration => {
if let Some(ident) = node.first_child(|id| Objc::Identifier == id) {
return node_text(code, &ident);
}
}
_ => {
if let Some(name) = node.child_by_field_name("name") {
return node_text(code, &name);
}
}
}
None
}
impl_byte_less_space_kind!(objc);
fn get_space_kind_with_code<'a>(
node: &Node<'a>,
code: &[u8],
ancestors: Ancestors<'a, '_>,
) -> SpaceKind {
crate::roles::objc::opens_space(node, code, ancestors)
}
keyword_roles!(objc);
paying_roles!(objc, control_flow);
fn get_op_type<'a>(node: &Node<'a>, ancestors: Ancestors<'a, '_>) -> TokenRole {
use Objc::*;
if GENERIC_ANGLES.is_closer(node, ancestors) {
return TokenRole::Unknown;
}
match node.kind_id().into() {
AT if ancestors.parent_has_kind(node, StringLiteral as u16) => TokenRole::Unknown,
LT | GT | LT2 | DOT | LPAREN | LPAREN2 | COMMA | STAR | GTGT | COLON | SEMI
| Return | Break | Continue | Else | Switch | Default | Goto | Do | EQ | DASH
| DASHDASH | DASHGT | PLUS | PLUSPLUS | SLASH | PERCENT | PIPE | AMP | LTLT | TILDE
| PLUSEQ | DASHEQ | BANG | STAREQ | SLASHEQ | PERCENTEQ | GTGTEQ | LTLTEQ | AMPEQ
| CARET | CARETEQ | PIPEEQ | LBRACK | LBRACE | Sizeof | In | AT | ATtry | ATcatch
| ATfinally | ATthrow | ATsynchronized | ATautoreleasepool | ATselector | ATencode => {
TokenRole::Operator
}
Identifier | TypeIdentifier | FieldIdentifier | StringLiteral | CharLiteral
| NumberLiteral | True | False | Null | DOTDOTDOT => TokenRole::Operand,
_ => TokenRole::Unknown,
}
}
fn get_operator_spelling<'a>(
node: &Node<'a>,
ancestors: Ancestors<'a, '_>,
) -> Option<&'static str> {
GENERIC_ANGLES.opener_spelling(node, ancestors)
}
get_operator!(Objc);
}