Skip to content

Commit

Permalink
_add goto label support
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-hykin committed Jun 27, 2019
1 parent 5453efb commit 9e3a583
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 2 deletions.
4 changes: 4 additions & 0 deletions language_tags/cpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ entity.name.function.definition.special.member.destructor.cpp
entity.name.function.destructor.cpp
entity.name.function.member.cpp
entity.name.function.preprocessor.cpp
entity.name.label.call.cpp
entity.name.label.cpp
entity.name.namespace.alias.cpp
entity.name.namespace.cpp
entity.name.operator.cpp
Expand Down Expand Up @@ -342,6 +344,7 @@ keyword.control.directive.pragma.cpp
keyword.control.directive.pragma.pragma-mark.cpp
keyword.control.directive.undef.cpp
keyword.control.exception.$0.cpp
keyword.control.goto.cpp
keyword.control.switch.cpp
keyword.operator.$0.cpp
keyword.operator.alignas.cpp
Expand Down Expand Up @@ -584,6 +587,7 @@ punctuation.separator.delimiter.inheritance.cpp
punctuation.separator.dot-access.cpp
punctuation.separator.inheritance.cpp
punctuation.separator.initializers.cpp
punctuation.separator.label.cpp
punctuation.separator.namespace.access.cpp
punctuation.separator.parameters.cpp
punctuation.separator.pointer-access.cpp
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Better Syntax",
"description": "The bleeding edge of C-like syntaxes",
"icon": "icon.png",
"version": "1.12.4",
"version": "1.12.5",
"scripts": {
"build": "ruby scripts/generate.rb",
"perfall": "ruby scripts/perf_all.rb",
Expand Down
24 changes: 23 additions & 1 deletion source/languages/cpp/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
# TODO: fill out all of the statements here, variable declares, assignment, etc
# control flow
:switch_statement, # needs to be above the "switch" keyword (which will eventually be removed)
:goto_statement,
# eventually, probably, the evaluation_context should be removed from here
:evaluation_context
:evaluation_context,
:label
]
cpp_grammar[:evaluation_context] = [
:ever_present_context,
Expand Down Expand Up @@ -563,6 +565,26 @@ def generateBlockFinder( name:"", tag_as:"", start_pattern:nil, needs_semicolon:
#
# Control flow
#
cpp_grammar[:goto_statement] = newPattern(
newPattern(
match: variableBounds[/goto/],
tag_as: "keyword.control.goto",
).then(std_space).then(
match: identifier,
tag_as: "entity.name.label.call"
)
)
cpp_grammar[:label] = newPattern(
std_space.then(
tag_as: "entity.name.label",
match: variableBounds[identifier],
).then(@word_boundary).lookBehindToAvoid(/case|default/).then(
std_space
).then(
match: /:/,
tag_as: "punctuation.separator.label",
)
)
cpp_grammar[:default_statement] = PatternRange.new(
tag_as: "meta.conditional.case",
start_pattern: newPattern(
Expand Down
103 changes: 103 additions & 0 deletions syntaxes/cpp.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,14 @@
{
"include": "#switch_statement"
},
{
"include": "#goto_statement"
},
{
"include": "#evaluation_context"
},
{
"include": "#label"
}
]
},
Expand Down Expand Up @@ -1212,6 +1218,103 @@
"match": "(?<!\\w)(?:throw|while|for|do|if|else|goto|switch|try|catch|return|break|case|continue|default)(?!\\w)",
"name": "keyword.control.$0.cpp"
},
"goto_statement": {
"match": "((?<!\\w)goto(?!\\w))((?:(?:(?>\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))((?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))*)",
"captures": {
"1": {
"name": "keyword.control.goto.cpp"
},
"2": {
"patterns": [
{
"include": "#inline_comment"
}
]
},
"3": {
"name": "comment.block.cpp punctuation.definition.comment.begin.cpp"
},
"4": {
"name": "comment.block.cpp"
},
"5": {
"patterns": [
{
"match": "\\*\\/",
"name": "comment.block.cpp punctuation.definition.comment.end.cpp"
},
{
"match": "\\*",
"name": "comment.block.cpp"
}
]
},
"6": {
"name": "entity.name.label.call.cpp"
}
}
},
"label": {
"match": "((?:(?:(?>\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))*(?!\\w))\\b(?<!case|default)((?:(?:(?>\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))(:)",
"captures": {
"1": {
"patterns": [
{
"include": "#inline_comment"
}
]
},
"2": {
"name": "comment.block.cpp punctuation.definition.comment.begin.cpp"
},
"3": {
"name": "comment.block.cpp"
},
"4": {
"patterns": [
{
"match": "\\*\\/",
"name": "comment.block.cpp punctuation.definition.comment.end.cpp"
},
{
"match": "\\*",
"name": "comment.block.cpp"
}
]
},
"5": {
"name": "entity.name.label.cpp"
},
"6": {
"patterns": [
{
"include": "#inline_comment"
}
]
},
"7": {
"name": "comment.block.cpp punctuation.definition.comment.begin.cpp"
},
"8": {
"name": "comment.block.cpp"
},
"9": {
"patterns": [
{
"match": "\\*\\/",
"name": "comment.block.cpp punctuation.definition.comment.end.cpp"
},
{
"match": "\\*",
"name": "comment.block.cpp"
}
]
},
"10": {
"name": "punctuation.separator.label.cpp"
}
}
},
"default_statement": {
"name": "meta.conditional.case.cpp",
"begin": "((?<!\\w)default(?!\\w))",
Expand Down
55 changes: 55 additions & 0 deletions syntaxes/cpp.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@
- include: "#assembly"
- include: "#function_pointer"
- include: "#switch_statement"
- include: "#goto_statement"
- include: "#evaluation_context"
- include: "#label"
evaluation_context:
patterns:
- include: "#ever_present_context"
Expand Down Expand Up @@ -623,6 +625,59 @@
control_flow_keywords:
match: "(?<!\\w)(?:throw|while|for|do|if|else|goto|switch|try|catch|return|break|case|continue|default)(?!\\w)"
name: keyword.control.$0.cpp
goto_statement:
match: "((?<!\\w)goto(?!\\w))((?:(?:(?>\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))((?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))*)"
captures:
'1':
name: keyword.control.goto.cpp
'2':
patterns:
- include: "#inline_comment"
'3':
name: comment.block.cpp punctuation.definition.comment.begin.cpp
'4':
name: comment.block.cpp
'5':
patterns:
- match: "\\*\\/"
name: comment.block.cpp punctuation.definition.comment.end.cpp
- match: "\\*"
name: comment.block.cpp
'6':
name: entity.name.label.call.cpp
label:
match: "((?:(?:(?>\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))((?<!\\w)(?:[a-zA-Z_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))(?:[a-zA-Z0-9_]|(?:\\\\u[0-9a-fA-F]{4}|\\\\U[0-9a-fA-F]{8}))*(?!\\w))\\b(?<!case|default)((?:(?:(?>\\s+)|(\\/\\*)((?>(?:[^\\*]|(?>\\*+)[^\\/])*)((?>\\*+)\\/)))+?|(?:(?:(?:(?:\\b|(?<=\\W))|(?=\\W))|\\A)|\\Z)))(:)"
captures:
'1':
patterns:
- include: "#inline_comment"
'2':
name: comment.block.cpp punctuation.definition.comment.begin.cpp
'3':
name: comment.block.cpp
'4':
patterns:
- match: "\\*\\/"
name: comment.block.cpp punctuation.definition.comment.end.cpp
- match: "\\*"
name: comment.block.cpp
'5':
name: entity.name.label.cpp
'6':
patterns:
- include: "#inline_comment"
'7':
name: comment.block.cpp punctuation.definition.comment.begin.cpp
'8':
name: comment.block.cpp
'9':
patterns:
- match: "\\*\\/"
name: comment.block.cpp punctuation.definition.comment.end.cpp
- match: "\\*"
name: comment.block.cpp
'10':
name: punctuation.separator.label.cpp
default_statement:
name: meta.conditional.case.cpp
begin: "((?<!\\w)default(?!\\w))"
Expand Down

0 comments on commit 9e3a583

Please sign in to comment.