Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Implement naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
chbk committed Jan 12, 2021
1 parent af1e7f5 commit 8b76da9
Show file tree
Hide file tree
Showing 2 changed files with 498 additions and 229 deletions.
302 changes: 207 additions & 95 deletions grammars/tree-sitter-c.cson
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ comments:

scopes:
'translation_unit': 'source.c'
'comment': 'comment.block'

'identifier': [
{match: '^[A-Z\\d_]+$', scopes: 'constant.other'}
]

# Keyword
'"#if"': 'keyword.control.directive'
'"#ifdef"': 'keyword.control.directive'
'"#ifndef"': 'keyword.control.directive'
Expand All @@ -74,112 +70,228 @@ scopes:
'"#define"': 'keyword.control.directive'
'"#include"': 'keyword.control.directive'
'preproc_directive': 'keyword.control.directive'
'"__attribute__"': 'keyword.control.directive'

'"if"': 'keyword.control'
'"else"': 'keyword.control'
'"do"': 'keyword.control'
'"for"': 'keyword.control'
'"while"': 'keyword.control'
'"break"': 'keyword.control'
'"continue"': 'keyword.control'
'"return"': 'keyword.control'
'"switch"': 'keyword.control'
'"case"': 'keyword.control'
'"default"': 'keyword.control'
'"goto"': 'keyword.control'

'"struct"': 'keyword.control'
'"enum"': 'keyword.control'
'"union"': 'keyword.control'
'"typedef"': 'keyword.control'

'preproc_function_def > identifier:nth-child(1)': 'entity.name.function.preprocessor'
'preproc_arg': 'meta.preprocessor.macro'
'"if"': 'keyword.control.condition'
'"else"': 'keyword.control.condition'
'"switch"': 'keyword.control.condition'
'"case"': 'keyword.control.condition'
'"default"': 'keyword.control.condition'
'"do"': 'keyword.control.loop'
'"for"': 'keyword.control.loop'
'"while"': 'keyword.control.loop'
'"break"': 'keyword.control.jump'
'"continue"': 'keyword.control.jump'
'"return"': 'keyword.control.jump'
'"goto"': 'keyword.control.jump'

'''
call_expression > identifier,
call_expression > field_expression > field_identifier,
function_declarator > identifier
''': 'entity.name.function'
'"sizeof"': 'keyword.operator.sizeof'

'statement_identifier': 'constant.variable'
'"+"': 'keyword.operator.arithmetic.symbolic'
'"-"': 'keyword.operator.arithmetic.symbolic'
'binary_expression > "*"': 'keyword.operator.arithmetic.symbolic'
'"/"': 'keyword.operator.arithmetic.symbolic'
'"%"': 'keyword.operator.arithmetic.symbolic'
'"++"': 'keyword.operator.arithmetic.symbolic'
'"--"': 'keyword.operator.arithmetic.symbolic'

'field_identifier': 'variable.other.member'
'binary_expression > "&"': 'keyword.operator.bitwise.symbolic'
'"|"': 'keyword.operator.bitwise.symbolic'
'"^"': 'keyword.operator.bitwise.symbolic'
'"~"': 'keyword.operator.bitwise.symbolic'
'"<<"': 'keyword.operator.bitwise.shift.symbolic'
'">>"': 'keyword.operator.bitwise.shift.symbolic'

'type_identifier': 'support.storage.type'
'primitive_type': 'support.storage.type'
'"signed"': 'support.storage.type'
'"unsigned"': 'support.storage.type'
'"short"': 'support.storage.type'
'"long"': 'support.storage.type'
'"="': 'keyword.operator.assignment.symbolic'
'"+="': 'keyword.operator.assignment.compound.symbolic'
'"-="': 'keyword.operator.assignment.compound.symbolic'
'"*="': 'keyword.operator.assignment.compound.symbolic'
'"/="': 'keyword.operator.assignment.compound.symbolic'
'"%="': 'keyword.operator.assignment.compound.symbolic'
'"<<="': 'keyword.operator.assignment.compound.symbolic'
'">>="': 'keyword.operator.assignment.compound.symbolic'
'"&="': 'keyword.operator.assignment.compound.symbolic'
'"|="': 'keyword.operator.assignment.compound.symbolic'
'"^="': 'keyword.operator.assignment.compound.symbolic'

'char_literal': 'string.quoted.single'
'string_literal': 'string.quoted.double'
'system_lib_string': 'string.quoted.other'
'escape_sequence': 'constant.character.escape'
'"=="': 'keyword.operator.comparison.symbolic'
'"!="': 'keyword.operator.comparison.symbolic'
'"<"': 'keyword.operator.comparison.symbolic'
'">"': 'keyword.operator.comparison.symbolic'
'"<="': 'keyword.operator.comparison.symbolic'
'">="': 'keyword.operator.comparison.symbolic'

'number_literal': 'constant.numeric.decimal'
'null': 'constant.language.null'
'true': 'constant.language.boolean'
'false': 'constant.language.boolean'
'"!"': 'keyword.operator.logical.symbolic'
'"&&"': 'keyword.operator.logical.symbolic'
'"||"': 'keyword.operator.logical.symbolic'

'"&"': 'keyword.operator.pointer.reference.symbolic'
'"*"': 'keyword.operator.pointer.dereference.symbolic'

'"?"': 'keyword.operator.ternary.symbolic'
'conditional_expression > ":"': 'keyword.operator.ternary.symbolic'

# Storage
'"typedef"': 'storage.declaration.datatype'
'"struct"': 'storage.declaration.structure'
'"enum"': 'storage.declaration.enumeration'
'"union"': 'storage.declaration.union'

'auto': 'storage.modifier'
'"extern"': 'storage.modifier'
'"register"': 'storage.modifier'
'"static"': 'storage.modifier'
'"register"': 'storage.modifier'
'"inline"': 'storage.modifier'
'"const"': 'storage.modifier'
'"volatile"': 'storage.modifier'
'"restrict"': 'storage.modifier'
'"_Atomic"': 'storage.modifier'
'auto': 'storage.modifier'
'function_specifier': 'storage.modifier'

'";"': 'punctuation.terminator.statement'
'"["': 'punctuation.definition.begin.bracket.square'
'"]"': 'punctuation.definition.end.bracket.square'
'","': 'punctuation.separator.delimiter'
'char_literal > "\'"': 'punctuation.definition.string'
'"unsigned"': 'storage.type.fundamental'
'"signed"': 'storage.type.fundamental'
'"short"': 'storage.type.fundamental'
'"long"': 'storage.type.fundamental'
'primitive_type': 'storage.type.fundamental'

# Entity
'type_identifier': 'entity.type'

'identifier': [
{
match: '^[A-Z\\d_]+$',
scopes: 'entity.variable.immutable'
},
'entity.variable'
]

'field_identifier': [
{
match: '^[A-Z\\d_]+$',
scopes: 'entity.variable.member.immutable'
},
'entity.variable.member'
]

'statement_identifier': 'entity.label'

'''
preproc_function_def > identifier:nth-child(1),
function_declarator > identifier
''': 'entity.function'

'''
call_expression > identifier,
call_expression > field_expression > field_identifier
''': 'entity.function.call'

# String
'string_literal': 'string.quoted'
'system_lib_string': 'string.quoted'

# Constant
'char_literal': 'constant.character'
'escape_sequence': [
{
match: '^\\\\[uUxftvnrabe0-9]',
scopes: 'constant.character.escape.code'
},
'constant.character.escape'
]
'preproc_include > string_literal > escape_sequence': '' # No escape characters in include directive

'number_literal': 'constant.numeric.decimal'

'null': 'constant.language.null'
'true': 'constant.language.boolean.true'
'false': 'constant.language.boolean.false'

# Comment
'comment': 'comment.block'

# Punctuation
'"."': 'punctuation.accessor.member'
'"->"': 'punctuation.accessor.member'
'";"': 'punctuation.delimiter.statement'
'":"': 'punctuation.delimiter'
'","': 'punctuation.delimiter'
'"("': 'punctuation.delimiter'
'")"': 'punctuation.delimiter'
'"{"': 'punctuation.delimiter'
'"}"': 'punctuation.delimiter'
'"["': 'punctuation.delimiter'
'"]"': 'punctuation.delimiter'
'"..."': 'punctuation.alteration.variadic'
'char_literal > "\'"': 'punctuation.definition.constant.character'
'string_literal > "\\""': 'punctuation.definition.string'
'"{"': 'punctuation.section.block.begin.bracket.curly'
'"}"': 'punctuation.section.block.end.bracket.curly'
'"("': 'punctuation.section.parens.begin.bracket.round'
'")"': 'punctuation.section.parens.end.bracket.round'

'"sizeof"': 'keyword.operator.sizeof'
'"."': 'keyword.operator.member'
'"->"': 'keyword.operator.member'
'"*"': 'keyword.operator'
'"-"': 'keyword.operator'
'"+"': 'keyword.operator'
'"/"': 'keyword.operator'
'"%"': 'keyword.operator'
'"++"': 'keyword.operator'
'"--"': 'keyword.operator'
'"=="': 'keyword.operator'
'"!"': 'keyword.operator'
'"!="': 'keyword.operator'
'"<"': 'keyword.operator'
'">"': 'keyword.operator'
'">="': 'keyword.operator'
'"<="': 'keyword.operator'
'"&&"': 'keyword.operator'
'"||"': 'keyword.operator'
'"&"': 'keyword.operator'
'"|"': 'keyword.operator'
'"^"': 'keyword.operator'
'"~"': 'keyword.operator'
'"<<"': 'keyword.operator'
'">>"': 'keyword.operator'
'"="': 'keyword.operator'
'"+="': 'keyword.operator'
'"-="': 'keyword.operator'
'"*="': 'keyword.operator'
'"/="': 'keyword.operator'
'"%="': 'keyword.operator'
'"<<="': 'keyword.operator'
'">>="': 'keyword.operator'
'"&="': 'keyword.operator'
'"^="': 'keyword.operator'
'"|="': 'keyword.operator'
'"?"': 'keyword.operator'
'":"': 'keyword.operator'
'array_declarator > "["': 'punctuation.delimiter.array.size'
'array_declarator > "]"': 'punctuation.delimiter.array.size'
'abstract_array_declarator > "["': 'punctuation.delimiter.array.size'
'abstract_array_declarator > "]"': 'punctuation.delimiter.array.size'

'subscript_expression > "["': 'punctuation.accessor.subscript'
'subscript_expression > "]"': 'punctuation.accessor.subscript'
'subscript_designator > "["': 'punctuation.accessor.subscript'
'subscript_designator > "]"': 'punctuation.accessor.subscript'

'initializer_list > "{"': 'punctuation.definition.collection'
'initializer_list > "}"': 'punctuation.definition.collection'

'compound_statement > "{"': 'punctuation.delimiter.statement'
'compound_statement > "}"': 'punctuation.delimiter.statement'

'function_definition > compound_statement > "{"': 'punctuation.delimiter.body.function'
'function_definition > compound_statement > "}"': 'punctuation.delimiter.body.function'

'enumerator_list > "{"': 'punctuation.delimiter.body.enumeration'
'enumerator_list > "}"': 'punctuation.delimiter.body.enumeration'

'union_specifier > field_declaration_list > "{"': 'punctuation.delimiter.body.union'
'union_specifier > field_declaration_list > "}"': 'punctuation.delimiter.body.union'

'struct_specifier > field_declaration_list > "{"': 'punctuation.delimiter.body.structure'
'struct_specifier > field_declaration_list > "}"': 'punctuation.delimiter.body.structure'

'preproc_params > "("': 'punctuation.delimiter.parameters'
'preproc_params > ")"': 'punctuation.delimiter.parameters'

'parameter_list > "("': 'punctuation.delimiter.parameters'
'parameter_list > ")"': 'punctuation.delimiter.parameters'
'argument_list > "("': 'punctuation.delimiter.arguments'
'argument_list > ")"': 'punctuation.delimiter.arguments'

'sizeof_expression > "("': 'punctuation.delimiter.arguments'
'sizeof_expression > ")"': 'punctuation.delimiter.arguments'
'sizeof_expression > parenthesized_expression > "("': 'punctuation.delimiter.arguments'
'sizeof_expression > parenthesized_expression > ")"': 'punctuation.delimiter.arguments'

'attribute_specifier > "("': 'punctuation.delimiter.arguments'
'attribute_specifier > ")"': 'punctuation.delimiter.arguments'

'cast_expression > "("': 'punctuation.delimiter.cast'
'cast_expression > ")"': 'punctuation.delimiter.cast'

'compound_literal_expression > "("': 'punctuation.delimiter.expression'
'compound_literal_expression > ")"': 'punctuation.delimiter.expression'

'parenthesized_expression > "("': 'punctuation.delimiter.expression'
'parenthesized_expression > ")"': 'punctuation.delimiter.expression'

'for_statement > "("': 'punctuation.delimiter.expression'
'for_statement > ")"': 'punctuation.delimiter.expression'

'ERROR > "."': 'punctuation.accessor.member.invalid.illegal'
'ERROR > "->"': 'punctuation.accessor.member.invalid.illegal'
'ERROR > ";"': 'punctuation.delimiter.statement.invalid.illegal'
'ERROR > ":"': 'punctuation.delimiter.invalid.illegal'
'ERROR > ","': 'punctuation.delimiter.invalid.illegal'
'ERROR > "("': 'punctuation.delimiter.invalid.illegal'
'ERROR > ")"': 'punctuation.delimiter.invalid.illegal'
'ERROR > "{"': 'punctuation.delimiter.invalid.illegal'
'ERROR > "}"': 'punctuation.delimiter.invalid.illegal'
'ERROR > "["': 'punctuation.delimiter.invalid.illegal'
'ERROR > "]"': 'punctuation.delimiter.invalid.illegal'
'ERROR > "..."': 'punctuation.alteration.variadic.invalid.illegal'
'ERROR > "\'"': 'punctuation.definition.constant.character.invalid.illegal'
'ERROR > "\\""': 'punctuation.definition.string.invalid.illegal'
Loading

0 comments on commit 8b76da9

Please sign in to comment.