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

Add import statments #397

Merged
merged 1 commit into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules
report.json
node_modules
**/.cache
**/dist
**/dist
gem/
1 change: 0 additions & 1 deletion source/languages/c/language_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ invalid.illegal.macro-name.c
invalid.illegal.placeholder.c
invalid.illegal.stray-$1.c
invalid.illegal.unknown-escape.c
invalid.unknown.documentation.command.c
keyword.control.c
keyword.control.case.c
keyword.control.default.c
Expand Down
2 changes: 2 additions & 0 deletions source/languages/cpp/language_tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ keyword.control.directive.conditional.$7.cpp
keyword.control.directive.conditional.defined.cpp
keyword.control.directive.define.cpp
keyword.control.directive.diagnostic.$7.cpp
keyword.control.directive.import.cpp
keyword.control.directive.line.cpp
keyword.control.directive.pragma.cpp
keyword.control.directive.pragma.pragma-mark.cpp
Expand Down Expand Up @@ -210,6 +211,7 @@ meta.parens.cpp
meta.parens.preprocessor.conditional.cpp
meta.preprocessor.conditional.cpp
meta.preprocessor.diagnostic.$reference(directive).cpp
meta.preprocessor.import.cpp
meta.preprocessor.include.cpp
meta.preprocessor.line.cpp
meta.preprocessor.macro.cpp
Expand Down
76 changes: 45 additions & 31 deletions source/languages/cpp/lib/preprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,36 @@
#
# #include
#
include_partial = Pattern.new(
Pattern.new(
# system header [cpp.include]/2
match: Pattern.new(
match: /</,
tag_as: "punctuation.definition.string.begin"
).zeroOrMoreOf(/[^>]/).maybe(
match: />/,
tag_as: "punctuation.definition.string.end"
).then(std_space).then(@end_of_line.or(lookAheadFor(/\/\//))),
tag_as: "string.quoted.other.lt-gt.include"
).or(
# other headers [cpp.include]/3
match: Pattern.new(
match: /\"/,
tag_as: "punctuation.definition.string.begin"
).zeroOrMoreOf(/[^\"]/).maybe(
match: /\"/,
tag_as: "punctuation.definition.string.end"
).then(std_space).then(@end_of_line.or(lookAheadFor(/\/\//))),
tag_as: "string.quoted.double.include"
).or(
# macro includes [cpp.include]/4
match: std_space.then(identifier).zeroOrMoreOf(/\./.then(identifier)).then(std_space).then(@end_of_line.or(lookAheadFor(/\/\//.or(/;/)))),
tag_as: "entity.name.other.preprocessor.macro.include"
).or(
# correctly color a lone `#include`
match: std_space.then(@end_of_line.or(lookAheadFor(/\/\//.or(/;/)))),
)
)
grammar[:include] = Pattern.new(
should_fully_match: ["#include <cstdlib>", "#include \"my_header\"", "#include INC_HEADER","#include", "#include <typing"],
should_partial_match: ["#include <foo> //comment"],
Expand All @@ -69,42 +99,25 @@
match: /#/,
tag_as: "punctuation.definition.directive"
).maybe(@spaces).then(
match: /include/.or(/include_next/).or(/import/),
match: /include/.or(/include_next/),
reference: "include_type"
).then(@word_boundary)
),
).maybe(@spaces).then(
Pattern.new(
# system header [cpp.include]/2
match: Pattern.new(
match: /</,
tag_as: "punctuation.definition.string.begin"
).zeroOrMoreOf(/[^>]/).maybe(
match: />/,
tag_as: "punctuation.definition.string.end"
).then(std_space).then(@end_of_line.or(lookAheadFor(/\/\//))),
tag_as: "string.quoted.other.lt-gt.include"
).or(
# other headers [cpp.include]/3
match: Pattern.new(
match: /\"/,
tag_as: "punctuation.definition.string.begin"
).zeroOrMoreOf(/[^\"]/).maybe(
match: /\"/,
tag_as: "punctuation.definition.string.end"
).then(std_space).then(@end_of_line.or(lookAheadFor(/\/\//))),
tag_as: "string.quoted.double.include"
).or(
# macro includes [cpp.include]/4
match: identifier.then(std_space).then(@end_of_line.or(lookAheadFor(/\/\//))),
tag_as: "entity.name.other.preprocessor.macro.include"
).or(
# correctly color a lone `#include`
match: std_space.then(@end_of_line.or(lookAheadFor(/\/\//))),
)
),
).maybe(@spaces).then(include_partial),
tag_as: "meta.preprocessor.include"
)
grammar[:module_import] = Pattern.new(
should_fully_match: ["import <cstdlib>", "import \"my_header\"", "import INC_HEADER","import", "import <typing"],
should_partial_match: ["import <foo> //comment"],
match: @start_of_line.then(std_space).then(
tag_as: "keyword.control.directive.import",
match: Pattern.new(
match: /import/,
reference: "include_type",
),
).maybe(@spaces).then(include_partial).maybe(@spaces).maybe(/;/),
tag_as: "meta.preprocessor.import",
)
#
# #line
#
Expand Down Expand Up @@ -351,6 +364,7 @@
:pragma_mark,
:pragma,
:include,
:module_import,
:line,
:diagnostic,
:undef,
Expand Down
146 changes: 68 additions & 78 deletions syntaxes/c.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -1152,89 +1152,87 @@
"comments": {
"patterns": [
{
"match": "(?:^)(?>\\s*)(\\/\\/[!\\/]+)(.*)",
"captures": {
"name": "comment.line.double-slash.documentation.c",
"begin": "(?:^)(?>\\s*)(\\/\\/[!\\/]+)",
"beginCaptures": {
"1": {
"name": "punctuation.definition.comment.documentation.c"
}
},
"end": "(?<=\\n)(?<!\\\\\\n)",
"patterns": [
{
"include": "#line_continuation_character"
},
"2": {
"patterns": [
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:callergraph|callgraph|else|endif|f\\$|f\\[|f\\]|hidecallergraph|hidecallgraph|hiderefby|hiderefs|hideinitializer|htmlinclude|n|nosubgrouping|private|privatesection|protected|protectedsection|public|publicsection|pure|showinitializer|showrefby|showrefs|tableofcontents|\\$|\\#|<|>|%|\"|\\.|=|::|\\||\\-\\-|\\-\\-\\-)\\b(?:\\{[^}]*\\})?",
"name": "storage.type.class.doxygen.c"
},
{
"match": "((?<=[\\s*!\\/])[\\\\@](?:a|em|e))\\s+(\\S+)",
"captures": {
"1": {
"name": "storage.type.class.doxygen.c"
},
"2": {
"name": "markup.italic.doxygen.c"
}
}
},
{
"match": "((?<=[\\s*!\\/])[\\\\@]b)\\s+(\\S+)",
"captures": {
"1": {
"name": "storage.type.class.doxygen.c"
},
"2": {
"name": "markup.bold.doxygen.c"
}
}
},
{
"match": "((?<=[\\s*!\\/])[\\\\@](?:c|p))\\s+(\\S+)",
"captures": {
"1": {
"name": "storage.type.class.doxygen.c"
},
"2": {
"name": "markup.inline.raw.string.c"
}
}
},
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:a|anchor|b|c|cite|copybrief|copydetail|copydoc|def|dir|dontinclude|e|em|emoji|enum|example|extends|file|idlexcept|implements|include|includedoc|includelineno|latexinclude|link|memberof|namespace|p|package|ref|refitem|related|relates|relatedalso|relatesalso|verbinclude)\\b(?:\\{[^}]*\\})?",
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:callergraph|callgraph|else|endif|f\\$|f\\[|f\\]|hidecallergraph|hidecallgraph|hiderefby|hiderefs|hideinitializer|htmlinclude|n|nosubgrouping|private|privatesection|protected|protectedsection|public|publicsection|pure|showinitializer|showrefby|showrefs|tableofcontents|\\$|\\#|<|>|%|\"|\\.|=|::|\\||\\-\\-|\\-\\-\\-)\\b(?:\\{[^}]*\\})?",
"name": "storage.type.class.doxygen.c"
},
{
"match": "((?<=[\\s*!\\/])[\\\\@](?:a|em|e))\\s+(\\S+)",
"captures": {
"1": {
"name": "storage.type.class.doxygen.c"
},
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:addindex|addtogroup|category|class|defgroup|diafile|dotfile|elseif|fn|headerfile|if|ifnot|image|ingroup|interface|line|mainpage|mscfile|name|overload|page|property|protocol|section|skip|skipline|snippet|snippetdoc|snippetlineno|struct|subpage|subsection|subsubsection|typedef|union|until|vhdlflow|weakgroup)\\b(?:\\{[^}]*\\})?",
"2": {
"name": "markup.italic.doxygen.c"
}
}
},
{
"match": "((?<=[\\s*!\\/])[\\\\@]b)\\s+(\\S+)",
"captures": {
"1": {
"name": "storage.type.class.doxygen.c"
},
{
"match": "((?<=[\\s*!\\/])[\\\\@]param)\\s+(\\b\\w+\\b)",
"captures": {
"1": {
"name": "storage.type.class.doxygen.c"
},
"2": {
"name": "variable.parameter.c"
}
}
},
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:arg|attention|author|authors|brief|bug|copyright|date|deprecated|details|exception|invariant|li|note|par|paragraph|param|post|pre|remark|remarks|result|return|returns|retval|sa|see|short|since|test|throw|todo|tparam|version|warning|xrefitem)\\b(?:\\{[^}]*\\})?",
"2": {
"name": "markup.bold.doxygen.c"
}
}
},
{
"match": "((?<=[\\s*!\\/])[\\\\@](?:c|p))\\s+(\\S+)",
"captures": {
"1": {
"name": "storage.type.class.doxygen.c"
},
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:code|cond|docbookonly|dot|htmlonly|internal|latexonly|link|manonly|msc|parblock|rtfonly|secreflist|uml|verbatim|xmlonly|endcode|endcond|enddocbookonly|enddot|endhtmlonly|endinternal|endlatexonly|endlink|endmanonly|endmsc|endparblock|endrtfonly|endsecreflist|enduml|endverbatim|endxmlonly)\\b(?:\\{[^}]*\\})?",
"2": {
"name": "markup.inline.raw.string.c"
}
}
},
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:a|anchor|b|c|cite|copybrief|copydetail|copydoc|def|dir|dontinclude|e|em|emoji|enum|example|extends|file|idlexcept|implements|include|includedoc|includelineno|latexinclude|link|memberof|namespace|p|package|ref|refitem|related|relates|relatedalso|relatesalso|verbinclude)\\b(?:\\{[^}]*\\})?",
"name": "storage.type.class.doxygen.c"
},
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:addindex|addtogroup|category|class|defgroup|diafile|dotfile|elseif|fn|headerfile|if|ifnot|image|ingroup|interface|line|mainpage|mscfile|name|overload|page|property|protocol|section|skip|skipline|snippet|snippetdoc|snippetlineno|struct|subpage|subsection|subsubsection|typedef|union|until|vhdlflow|weakgroup)\\b(?:\\{[^}]*\\})?",
"name": "storage.type.class.doxygen.c"
},
{
"match": "((?<=[\\s*!\\/])[\\\\@]param)\\s+(\\b\\w+\\b)",
"captures": {
"1": {
"name": "storage.type.class.doxygen.c"
},
{
"match": "(?:\\b[A-Z]+:|@[a-z_]+:)",
"name": "storage.type.class.gtkdoc"
},
{
"match": "[\\\\@]\\S++(?!(?:\\n|$))",
"name": "invalid.unknown.documentation.command.c"
"2": {
"name": "variable.parameter.c"
}
]
}
},
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:arg|attention|author|authors|brief|bug|copyright|date|deprecated|details|exception|invariant|li|note|par|paragraph|param|post|pre|remark|remarks|result|return|returns|retval|sa|see|short|since|test|throw|todo|tparam|version|warning|xrefitem)\\b(?:\\{[^}]*\\})?",
"name": "storage.type.class.doxygen.c"
},
{
"match": "(?<=[\\s*!\\/])[\\\\@](?:code|cond|docbookonly|dot|htmlonly|internal|latexonly|link|manonly|msc|parblock|rtfonly|secreflist|uml|verbatim|xmlonly|endcode|endcond|enddocbookonly|enddot|endhtmlonly|endinternal|endlatexonly|endlink|endmanonly|endmsc|endparblock|endrtfonly|endsecreflist|enduml|endverbatim|endxmlonly)\\b(?:\\{[^}]*\\})?",
"name": "storage.type.class.doxygen.c"
},
{
"match": "(?:\\b[A-Z]+:|@[a-z_]+:)",
"name": "storage.type.class.gtkdoc"
}
},
"name": "comment.line.double-slash.documentation.c"
]
},
{
"match": "(\\/\\*[!*]+(?=\\s))(.+)([!*]*\\*\\/)",
Expand Down Expand Up @@ -1311,10 +1309,6 @@
{
"match": "(?:\\b[A-Z]+:|@[a-z_]+:)",
"name": "storage.type.class.gtkdoc"
},
{
"match": "[\\\\@]\\S++(?!(?:\\n|$))",
"name": "invalid.unknown.documentation.command.c"
}
]
},
Expand Down Expand Up @@ -1406,10 +1400,6 @@
{
"match": "(?:\\b[A-Z]+:|@[a-z_]+:)",
"name": "storage.type.class.gtkdoc"
},
{
"match": "[\\\\@]\\S++(?!(?:\\n|$))",
"name": "invalid.unknown.documentation.command.c"
}
]
},
Expand Down
Loading