Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach outer attributes to the elements they annotate #245

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
@@ -137,7 +137,6 @@ module.exports = grammar({
$.macro_invocation,
$.macro_definition,
$.empty_statement,
$.attribute_item,
$.inner_attribute_item,
$.mod_item,
$.foreign_mod_item,
@@ -269,6 +268,7 @@ module.exports = grammar({
),

mod_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'mod',
field('name', $.identifier),
@@ -279,6 +279,7 @@ module.exports = grammar({
),

foreign_mod_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
$.extern_modifier,
choice(
@@ -294,6 +295,7 @@ module.exports = grammar({
),

struct_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'struct',
field('name', $._type_identifier),
@@ -313,6 +315,7 @@ module.exports = grammar({
),

union_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'union',
field('name', $._type_identifier),
@@ -322,6 +325,7 @@ module.exports = grammar({
),

enum_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'enum',
field('name', $._type_identifier),
@@ -376,6 +380,7 @@ module.exports = grammar({
),

extern_crate_declaration: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'extern',
$.crate,
@@ -388,6 +393,7 @@ module.exports = grammar({
),

const_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'const',
field('name', $.identifier),
@@ -403,6 +409,7 @@ module.exports = grammar({
),

static_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'static',

@@ -421,6 +428,7 @@ module.exports = grammar({
),

type_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'type',
field('name', $._type_identifier),
@@ -433,6 +441,7 @@ module.exports = grammar({
),

function_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
optional($.function_modifiers),
'fn',
@@ -445,6 +454,7 @@ module.exports = grammar({
),

function_signature_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
optional($.function_modifiers),
'fn',
@@ -489,6 +499,7 @@ module.exports = grammar({
),

impl_item: $ => seq(
repeat($.attribute_item),
optional('unsafe'),
'impl',
field('type_parameters', optional($.type_parameters)),
@@ -507,6 +518,7 @@ module.exports = grammar({
),

trait_item: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
optional('unsafe'),
'trait',
@@ -518,6 +530,7 @@ module.exports = grammar({
),

associated_type: $ => seq(
repeat($.attribute_item),
'type',
field('name', $._type_identifier),
field('type_parameters', optional($.type_parameters)),
@@ -598,6 +611,7 @@ module.exports = grammar({
)),

let_declaration: $ => seq(
repeat($.attribute_item),
'let',
optional($.mutable_specifier),
field('pattern', $._pattern),
@@ -617,6 +631,7 @@ module.exports = grammar({
),

use_declaration: $ => seq(
repeat($.attribute_item),
optional($.visibility_modifier),
'use',
field('argument', $._use_clause),
116 changes: 112 additions & 4 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 70 additions & 10 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

248,575 changes: 137,113 additions & 111,462 deletions src/parser.c

Large diffs are not rendered by default.

86 changes: 43 additions & 43 deletions test/corpus/declarations.txt
Original file line number Diff line number Diff line change
@@ -1234,41 +1234,41 @@ mod macos_only {}

#![allow(clippy::useless_transmute)]

#[clippy::cyclomatic_complexity = "100"]
#![clippy::cyclomatic_complexity = "100"]

--------------------------------------------------------------------------------

(source_file
(attribute_item
(attribute
(identifier)))
(function_item
(attribute_item
(attribute
(identifier)))
name: (identifier)
parameters: (parameters)
body: (block))
(attribute_item
(attribute
(identifier)
arguments: (token_tree
(identifier))))
(struct_item
name: (type_identifier))
(attribute_item
(attribute
(identifier)
arguments: (token_tree
(attribute_item
(attribute
(identifier)
(identifier))))
(struct_item
arguments: (token_tree
(identifier))))
name: (type_identifier))
(attribute_item
(attribute
(identifier)
arguments: (token_tree
(struct_item
(attribute_item
(attribute
(identifier)
(string_literal
(string_content)))))
arguments: (token_tree
(identifier)
(identifier))))
name: (type_identifier))
(mod_item
(attribute_item
(attribute
(identifier)
arguments: (token_tree
(identifier)
(string_literal
(string_content)))))
name: (identifier)
body: (declaration_list))
(inner_attribute_item
@@ -1277,7 +1277,7 @@ mod macos_only {}
arguments: (token_tree
(identifier)
(identifier))))
(attribute_item
(inner_attribute_item
(attribute
(scoped_identifier
path: (identifier)
@@ -1358,25 +1358,25 @@ fn baz() {}
--------------------------------------------------------------------------------

(source_file
(attribute_item
(attribute
(identifier)
(macro_invocation
(identifier)
(token_tree
(string_literal
(string_content))))))
(function_item
(attribute_item
(attribute
(identifier)
(macro_invocation
(identifier)
(token_tree
(string_literal
(string_content))))))
(identifier)
(parameters)
(block))
(attribute_item
(attribute
(identifier)
(scoped_identifier
(identifier)
(identifier))))
(function_item
(attribute_item
(attribute
(identifier)
(scoped_identifier
(identifier)
(identifier))))
(identifier)
(parameters)
(block)))
@@ -1447,13 +1447,13 @@ pub enum Error {
(scoped_identifier
(identifier)
(identifier)))
(attribute_item
(attribute
(identifier)
(token_tree
(identifier)
(identifier))))
(enum_item
(attribute_item
(attribute
(identifier)
(token_tree
(identifier)
(identifier))))
(visibility_modifier)
(type_identifier)
(enum_variant_list