diff --git a/.gitmodules b/.gitmodules index 1cfb97a19..1eec6c4ea 100644 --- a/.gitmodules +++ b/.gitmodules @@ -38,3 +38,6 @@ [submodule "parsers/sql"] path = parsers/sql url = https://github.com/rien/tree-sitter-sql.git +[submodule "parsers/verilog"] + path = parsers/verilog + url = https://github.com/tree-sitter/tree-sitter-verilog.git diff --git a/lib/src/lib/language.ts b/lib/src/lib/language.ts index 451c38822..1feaef68f 100644 --- a/lib/src/lib/language.ts +++ b/lib/src/lib/language.ts @@ -122,6 +122,7 @@ export class LanguagePicker { new ProgrammingLanguage("sql", [".sql"]), new ProgrammingLanguage("typescript", [".ts"]), new ProgrammingLanguage("tsx", [".tsx"]), + new ProgrammingLanguage("verilog", [".v", ".vh"]), new CustomTokenizerLanguage("char", [".txt", ".md"], async self => { const { CharTokenizer } = await import("./tokenizer/charTokenizer.js"); return new CharTokenizer(self); diff --git a/lib/src/test/snapshots/tokenizer.test.ts.md b/lib/src/test/snapshots/tokenizer.test.ts.md index 3c52936ab..5b872fca2 100644 --- a/lib/src/test/snapshots/tokenizer.test.ts.md +++ b/lib/src/test/snapshots/tokenizer.test.ts.md @@ -20605,3 +20605,2494 @@ Generated by [AVA](https://avajs.dev). ')', ')', ] + +## tokenizer works for verilog + +> stable tokenization + + [ + '(', + 'source_file', + '(', + 'comment', + ')', + '(', + 'package_declaration', + '(', + 'package_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'zero_directive', + ')', + '(', + 'zero_directive', + ')', + '(', + 'include_compiler_directive', + '(', + 'double_quoted_string', + ')', + ')', + '(', + 'id_directive', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'text_macro_definition', + '(', + 'text_macro_name', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'macro_text', + ')', + ')', + '(', + 'text_macro_definition', + '(', + 'text_macro_name', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'macro_text', + ')', + ')', + '(', + 'text_macro_definition', + '(', + 'text_macro_name', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'macro_text', + ')', + ')', + '(', + 'module_declaration', + '(', + 'module_header', + '(', + 'module_keyword', + ')', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'module_nonansi_header', + '(', + 'list_of_ports', + '(', + 'port', + '(', + 'port_reference', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'port', + '(', + 'port_reference', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'port', + '(', + 'port_reference', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'port', + '(', + 'port_reference', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'package_or_generate_item_declaration', + '(', + 'parameter_declaration', + '(', + 'list_of_param_assignments', + '(', + 'param_assignment', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'constant_param_expression', + '(', + 'constant_mintypmax_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'package_or_generate_item_declaration', + '(', + 'parameter_declaration', + '(', + 'list_of_param_assignments', + '(', + 'param_assignment', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'constant_param_expression', + '(', + 'constant_mintypmax_expression', + '(', + 'constant_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'port_declaration', + '(', + 'input_declaration', + '(', + 'net_port_type1', + '(', + 'data_type_or_implicit1', + '(', + 'implicit_data_type1', + '(', + 'packed_dimension', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'list_of_port_identifiers', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + '(', + 'port_declaration', + '(', + 'output_declaration', + '(', + 'list_of_port_identifiers', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + '(', + 'port_declaration', + '(', + 'output_declaration', + '(', + 'net_port_type1', + '(', + 'data_type_or_implicit1', + '(', + 'implicit_data_type1', + '(', + 'packed_dimension', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'list_of_port_identifiers', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + '(', + 'port_declaration', + '(', + 'input_declaration', + '(', + 'list_of_port_identifiers', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'package_or_generate_item_declaration', + '(', + 'net_declaration', + '(', + 'net_type', + ')', + '(', + 'data_type_or_implicit1', + '(', + 'implicit_data_type1', + '(', + 'packed_dimension', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'list_of_net_decl_assignments', + '(', + 'net_decl_assignment', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'net_decl_assignment', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + '(', + 'id_directive', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'id_directive', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'zero_directive', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'zero_directive', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'conditional_expression', + '(', + 'cond_predicate', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'text_macro_usage', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'list_of_actual_arguments', + '(', + 'expression', + '(', + 'primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'package_or_generate_item_declaration', + ')', + ')', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'module_declaration', + '(', + 'module_header', + '(', + 'module_keyword', + ')', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'module_nonansi_header', + '(', + 'list_of_ports', + '(', + 'ERROR', + '(', + 'ansi_port_declaration', + '(', + 'net_port_header1', + '(', + 'port_direction', + ')', + ')', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + '(', + 'line_compiler_directive', + '(', + 'unsigned_number', + ')', + '(', + 'double_quoted_string', + ')', + '(', + 'unsigned_number', + ')', + ')', + '(', + 'port', + '(', + 'port_reference', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'ERROR', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_declaration', + '(', + 'module_header', + '(', + 'module_keyword', + ')', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'module_ansi_header', + '(', + 'list_of_port_declarations', + '(', + 'ansi_port_declaration', + '(', + 'net_port_header1', + '(', + 'port_direction', + ')', + '(', + 'net_port_type1', + '(', + 'data_type_or_implicit1', + '(', + 'implicit_data_type1', + '(', + 'packed_dimension', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'ansi_port_declaration', + '(', + 'net_port_header1', + '(', + 'port_direction', + ')', + '(', + 'net_port_type1', + '(', + 'data_type_or_implicit1', + '(', + 'implicit_data_type1', + '(', + 'packed_dimension', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'ansi_port_declaration', + '(', + 'net_port_header1', + '(', + 'port_direction', + ')', + '(', + 'net_port_type1', + '(', + 'data_type_or_implicit1', + '(', + 'implicit_data_type1', + '(', + 'packed_dimension', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'ansi_port_declaration', + '(', + 'net_port_header1', + '(', + 'port_direction', + ')', + ')', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'package_or_generate_item_declaration', + '(', + 'net_declaration', + '(', + 'net_type', + ')', + '(', + 'data_type_or_implicit1', + '(', + 'implicit_data_type1', + '(', + 'packed_dimension', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'list_of_net_decl_assignments', + '(', + 'net_decl_assignment', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'program_instantiation', + '(', + 'program_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'parameter_value_assignment', + '(', + 'list_of_parameter_assignments', + '(', + 'ordered_parameter_assignment', + '(', + '_ordered_parameter_assignment', + '(', + 'mintypmax_expression', + '(', + 'expression', + '(', + 'primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'hierarchical_instance', + '(', + 'name_of_instance', + '(', + 'instance_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'list_of_port_connections', + '(', + 'named_port_connection', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'named_port_connection', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'ERROR', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'named_port_connection', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'ERROR', + ')', + '(', + 'named_port_connection', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'named_port_connection', + '(', + 'port_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'binary_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'program_instantiation', + '(', + 'program_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'parameter_value_assignment', + '(', + 'list_of_parameter_assignments', + '(', + 'ordered_parameter_assignment', + '(', + '_ordered_parameter_assignment', + '(', + 'mintypmax_expression', + '(', + 'expression', + '(', + 'primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'hierarchical_instance', + '(', + 'name_of_instance', + '(', + 'instance_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'list_of_port_connections', + '(', + 'ordered_port_connection', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'ordered_port_connection', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'ERROR', + ')', + '(', + 'comment', + ')', + '(', + 'ordered_port_connection', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + '(', + 'select1', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + '(', + 'ordered_port_connection', + '(', + 'expression', + '(', + 'primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'binary_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_declaration', + '(', + 'module_header', + '(', + 'module_keyword', + ')', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'module_nonansi_header', + '(', + 'parameter_port_list', + '(', + 'parameter_port_declaration', + '(', + 'parameter_declaration', + '(', + 'list_of_param_assignments', + '(', + 'param_assignment', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'constant_param_expression', + '(', + 'constant_mintypmax_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'parameter_port_declaration', + '(', + 'parameter_declaration', + '(', + 'list_of_param_assignments', + '(', + 'param_assignment', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'constant_param_expression', + '(', + 'constant_mintypmax_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'constant_mintypmax_expression', + '(', + 'constant_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + '(', + 'parameter_port_declaration', + '(', + 'parameter_declaration', + '(', + 'list_of_param_assignments', + '(', + 'param_assignment', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'constant_param_expression', + '(', + 'constant_mintypmax_expression', + '(', + 'constant_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + ')', + '(', + 'list_of_ports', + ')', + ')', + '(', + 'module_declaration', + '(', + 'module_header', + '(', + 'module_keyword', + ')', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'module_nonansi_header', + '(', + 'list_of_ports', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'always_construct', + '(', + 'always_keyword', + ')', + '(', + 'statement', + '(', + 'statement_item', + '(', + 'blocking_assignment', + '(', + 'operator_assignment', + '(', + 'variable_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'assignment_operator', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + '(', + 'select1', + '(', + 'member_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'always_construct', + '(', + 'always_keyword', + ')', + '(', + 'statement', + '(', + 'statement_item', + '(', + 'procedural_timing_control_statement', + '(', + 'event_control', + '(', + 'event_expression', + '(', + 'edge_identifier', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + '(', + 'statement_or_null', + '(', + 'statement', + '(', + 'statement_item', + '(', + 'seq_block', + '(', + 'statement_or_null', + '(', + 'statement', + '(', + 'statement_item', + '(', + 'clocking_drive', + '(', + 'clockvar_expression', + '(', + 'clockvar', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'select1', + '(', + 'member_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'ERROR', + '(', + 'clockvar_expression', + '(', + 'clockvar', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'select1', + '(', + 'member_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'statement_or_null', + '(', + 'statement', + '(', + 'statement_item', + '(', + 'nonblocking_assignment', + '(', + 'variable_lvalue', + '(', + 'variable_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'variable_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'variable_lvalue', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + '(', + 'statement_or_null', + '(', + 'statement', + '(', + 'statement_item', + '(', + 'clocking_drive', + '(', + 'clockvar_expression', + '(', + 'clockvar', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'primary_literal', + '(', + 'simple_text_macro_usage', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'ERROR', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'unary_operator', + ')', + '(', + 'primary', + '(', + 'mintypmax_expression', + '(', + 'expression', + '(', + 'expression', + '(', + 'primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + '(', + 'constant_select1', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'parameter_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'ERROR', + '(', + 'casting_type', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'simple_text_macro_usage', + '(', + 'text_macro_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'function_subroutine_call', + '(', + 'subroutine_call', + '(', + 'system_tf_call', + '(', + 'system_tf_identifier', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'comment', + ')', + '(', + 'module_or_generate_item', + '(', + 'continuous_assign', + '(', + 'list_of_net_assignments', + '(', + 'net_assignment', + '(', + 'net_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'let_expression', + '(', + 'package_scope', + '(', + 'package_identifier', + '(', + 'simple_identifier', + ')', + ')', + ')', + '(', + 'simple_identifier', + ')', + '(', + 'ERROR', + '(', + 'ERROR', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'module_declaration', + '(', + 'module_header', + '(', + 'module_keyword', + ')', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'module_nonansi_header', + '(', + 'list_of_ports', + ')', + ')', + '(', + 'module_or_generate_item', + '(', + 'always_construct', + '(', + 'always_keyword', + ')', + '(', + 'statement', + '(', + 'statement_item', + '(', + 'blocking_assignment', + '(', + 'operator_assignment', + '(', + 'variable_lvalue', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'assignment_operator', + ')', + '(', + 'expression', + '(', + 'primary', + '(', + 'simple_identifier', + ')', + '(', + 'select1', + '(', + 'member_identifier', + '(', + 'simple_identifier', + ')', + ')', + '(', + 'constant_range', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + '(', + 'constant_expression', + '(', + 'constant_primary', + '(', + 'primary_literal', + '(', + 'integral_number', + '(', + 'decimal_number', + '(', + 'unsigned_number', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ')', + ] diff --git a/lib/src/test/snapshots/tokenizer.test.ts.snap b/lib/src/test/snapshots/tokenizer.test.ts.snap index 8c89da39c..e7176804a 100644 Binary files a/lib/src/test/snapshots/tokenizer.test.ts.snap and b/lib/src/test/snapshots/tokenizer.test.ts.snap differ diff --git a/lib/src/test/tokenizer.test.ts b/lib/src/test/tokenizer.test.ts index d13d1cd1d..55aec7e8b 100644 --- a/lib/src/test/tokenizer.test.ts +++ b/lib/src/test/tokenizer.test.ts @@ -19,6 +19,7 @@ const languageFiles = { "sql": "../samples/sql/sample.sql", "tsx": "../samples/tsx/sample.tsx", "typescript": "../samples/typescript/caesar.ts", + "verilog": "../samples/verilog/module.v" } as {[key: string]: string}; for (const [languageName, languageFile] of Object.entries(languageFiles)) { diff --git a/package-lock.json b/package-lock.json index 7dfea7576..7b80cb54a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7061,6 +7061,7 @@ "parsers": { "name": "@dodona/dolos-parsers", "version": "1.0.0", + "hasInstallScript": true, "license": "MIT", "dependencies": { "nan": "^2.19.0" diff --git a/parsers/binding.gyp b/parsers/binding.gyp index 7d239f0af..20f45e326 100644 --- a/parsers/binding.gyp +++ b/parsers/binding.gyp @@ -12,6 +12,7 @@ "python/binding.gyp", "r/binding.gyp", "sql/binding.gyp", - "typescript/binding.gyp" + "typescript/binding.gyp", + "verilog/binding.gyp" ] } diff --git a/parsers/index.js b/parsers/index.js index a7c291e7c..b91102e1d 100644 --- a/parsers/index.js +++ b/parsers/index.js @@ -41,3 +41,6 @@ module.exports.typescript.nodeTypeInfo = require("./typescript/typescript/src/no module.exports.tsx = typescript_tsx.tsx; module.exports.tsx.nodeTypeInfo = require("./typescript/tsx/src/node-types.json"); + +module.exports.verilog = require("./build/Release/tree_sitter_verilog_binding"); +module.exports.verilog.nodeTypeInfo = require("./verilog/src/node-types.json"); diff --git a/parsers/verilog b/parsers/verilog new file mode 160000 index 000000000..2dfddfcb8 --- /dev/null +++ b/parsers/verilog @@ -0,0 +1 @@ +Subproject commit 2dfddfcb891f74a1cdb9d8ce480a997d11846e17 diff --git a/samples/verilog/module.v b/samples/verilog/module.v new file mode 100644 index 000000000..4cdf503ae --- /dev/null +++ b/samples/verilog/module.v @@ -0,0 +1,106 @@ +/* + zoo module +*/ +package mypkg; + +`resetall +`undefineall +`include "isa.vh" +`undef D +`define D(x, y) initial $display("start", x, y) +`define DELAY #1 +`define WIDTH 32 + + +module add_sub (x, y, z, sign); + + parameter WIDTH = 8; + parameter W2 = 8 * WIDTH; + + input [WIDTH-1:0] x, y; + output carry; + output [WIDTH-1:0] z; + input sign; + +wire [WIDTH-1:0] add, sub; + +// logic +`ifdef E0 + assign add = x + y; +`elsif E1 + assign add = x + y; +`else + assign add = x + y; +`endif + +assign sub = x - y; +assign z = sign ? sub : add; + +`D(5, 7); + +endmodule: add_sub + +module bar ( + input a, // `line define in the port list +`line 123 "foo.v" 0 + output b +); +endmodule + +module alu ( + input [31:0] a, + input [31:0] b, + output [31:0] res, + input clk +); + +wire [31:0] tmp; + +add_sub #(32) u0 ( + .x(a), + .y(b), +`ifdef CARRY + .carry(carry), +`endif + .z(tmp), + .sign(1'b0) +); + +add_sub #(32) u0 ( + a, b, , // missing argument + tmp[PARAM-1:0], // expressions with parameters + 1'b0 +); + +assign res = tmp; + +endmodule + +module foo #( + parameter P1 = 32, + parameter P2 = (P1 / 8), // parrents + parameter P3 = P1 ? P2 : 64 // trinary +)(); + +module mod (); + always_comb foo = bar.baz[7:0]; +endmodule + +always @ (posedge clk) begin + a.b <= b; + a.b(c); + {x0, x1, x2} <= y; // deconcat + x <= `DELAY y; // define delay +end + +assign x = -(8 * W); +assign x[P1-1:0] = y; // vector slice assignment +assign x = `WIDTH'b0; // define as vector size +assign x = $random(seed); // system functions +assign x = mypkg::add(1, 3); + +endmodule + +module mod (); +always_comb foo = bar.baz[7:0]; +endmodule diff --git a/web/src/components/upload/UploadFormCard.vue b/web/src/components/upload/UploadFormCard.vue index 0dca5ea8a..a5cf36775 100644 --- a/web/src/components/upload/UploadFormCard.vue +++ b/web/src/components/upload/UploadFormCard.vue @@ -104,6 +104,10 @@ const languages = [ name: "TSX", value: "tsx", }, + { + name: "Verilog", + value: "verilog" + } ]; const accept = shallowRef(false);