Skip to content

Commit

Permalink
Add script to generate highlights for nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
Riley-Kilgore authored and rvcas committed Jul 3, 2024
1 parent e09b684 commit d6465dc
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions generate_highlights.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
def generate_highlights_scm(rules):
highlights = []

def add_highlight(node_type, capture_name):
if node_type in rules:
highlights.append(f'({node_type}) @{capture_name}')

# More specific function-related highlights
add_highlight('function', 'aiken.function')
add_highlight('validator', 'aiken.function.validator')
add_highlight('test', 'aiken.function.test')
add_highlight('function_argument', 'aiken.function.parameter')

# More specific type-related highlights
add_highlight('type_alias', 'aiken.type.alias')
add_highlight('type_enum', 'aiken.type.enum')
add_highlight('type_struct', 'aiken.type.struct')
add_highlight('type_identifier', 'aiken.type.name')
add_highlight('type_argument', 'aiken.type.argument')

# Variable and constant highlights
add_highlight('identifier', 'aiken.variable')
add_highlight('constant', 'aiken.constant')

# Literal highlights
add_highlight('string', 'aiken.string')
add_highlight('int', 'aiken.number')
add_highlight('bool', 'aiken.boolean')
add_highlight('bytes', 'aiken.bytes')

# Comment highlights
add_highlight('comment', 'comment')
add_highlight('module_comment', 'comment.documentation.module')
add_highlight('definition_comment', 'comment.documentation.definition')

# Aiken-specific constructs
add_highlight('match_pattern', 'aiken.pattern')
add_highlight('field_access', 'aiken.field')
add_highlight('call', 'aiken.function.call')
add_highlight('pipeline', 'aiken.operator.pipeline')
add_highlight('trace', 'aiken.debug.trace')
add_highlight('error_term', 'aiken.error')

# Control flow
add_highlight('if', 'aiken.control.conditional')
add_highlight('when', 'aiken.control.when')

# Keywords
keywords = ['use', 'pub', 'opaque', 'type', 'fn', 'validator', 'test', 'let', 'expect', 'when', 'is', 'if', 'else', 'and', 'or', 'trace', 'fail', 'as']
for keyword in keywords:
highlights.append(f'"{keyword}" @aiken.keyword')

# Special keywords
add_highlight('todo', 'aiken.keyword.todo')

# Operators
operators = ['!', '-', '+', '*', '/', '%', '==', '!=', '<', '<=', '>', '>=', '&&', '||', '|>']
for operator in operators:
highlights.append(f'"{operator}" @aiken.operator')

return '\n'.join(highlights)

0 comments on commit d6465dc

Please sign in to comment.