This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Rewrite functions, again #214
Open
winstliu
wants to merge
5
commits into
master
Choose a base branch
from
wl-rewrite-functions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5cfe611
Initial rewrite of functions and function calls
winstliu 779981c
Get return types in C++ working
winstliu 3094776
Operator overloading
winstliu 7bec2cd
L: not required
winstliu ce67f07
Merge branch 'master' into wl-rewrite-functions
winstliu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,6 @@ | |
'match': '\\b(break|case|continue|default|do|else|for|goto|if|_Pragma|return|switch|while)\\b' | ||
'name': 'keyword.control.c' | ||
} | ||
{ | ||
'include': '#storage_types' | ||
} | ||
{ | ||
'match': '\\b(const|extern|register|restrict|static|volatile|inline)\\b' | ||
'name': 'storage.modifier.c' | ||
|
@@ -218,6 +215,50 @@ | |
} | ||
] | ||
} | ||
{ | ||
'include': '#block' | ||
} | ||
{ | ||
'include': '#parens' | ||
} | ||
{ | ||
# FIRST CAPTURE meta.function.c scope (provides an injectable scope, balanced parentheses and prevents unnecessary scope nesting) | ||
# TODO: Try to make this C-only | ||
'begin': '''(?x) | ||
(?= | ||
[A-Za-z_]\\w* # Type modifier | ||
\\s+ | ||
( | ||
([A-Za-z_]\\w*+|::)++ # Actual name | ||
| | ||
(operator([-*&<>=+!]+|\\(\\)|\\[\\])) # Operator overloading (for C++) | ||
) | ||
\\s*\\( | ||
) | ||
''' | ||
'end': '(?<=})|(?=;)' | ||
'name': 'meta.function.c' | ||
'patterns': [ | ||
{ | ||
'include': '#function-body' | ||
} | ||
{ | ||
'begin': '\\G' | ||
'end': '(?<=\\))' | ||
'patterns': [ | ||
{ | ||
'include': '#function-innards' | ||
} | ||
] | ||
} | ||
{ | ||
'include': '#comments' | ||
} | ||
] | ||
} | ||
{ | ||
'include': '#function-call' | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There can be no function calls here at $base (only func. declarations or definitions can). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was mostly for testing purposes so that I didn't have to constantly create the necessary scaffolding. |
||
{ | ||
'match': '\\b(u_char|u_short|u_int|u_long|ushort|uint|u_quad_t|quad_t|qaddr_t|caddr_t|daddr_t|div_t|dev_t|fixpt_t|blkcnt_t|blksize_t|gid_t|in_addr_t|in_port_t|ino_t|key_t|mode_t|nlink_t|id_t|pid_t|off_t|segsz_t|swblk_t|uid_t|id_t|clock_t|size_t|ssize_t|time_t|useconds_t|suseconds_t)\\b' | ||
'name': 'support.type.sys-types.c' | ||
|
@@ -258,28 +299,7 @@ | |
'name': 'support.type.posix-reserved.c' | ||
} | ||
{ | ||
'include': '#block' | ||
} | ||
{ | ||
'include': '#parens' | ||
} | ||
{ | ||
# FIRST CAPTURE meta.function.c scope (provides an injectable scope, balanced parentheses and prevents unnecessary scope nesting) | ||
'begin': '''(?x) | ||
(?!(?:while|for|do|if|else|switch|catch|enumerate|return|sizeof|[cr]?iterate|asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|_Imaginary|int|long|short|signed|struct|typedef|union|unsigned|void)\\s*\\() | ||
(?= | ||
(?:[A-Za-z_][A-Za-z0-9_]*+|::)++\\s*\\( # actual name | ||
| | ||
(?:(?<=operator)(?:[-*&<>=+!]+|\\(\\)|\\[\\]))\\s*\\( | ||
) | ||
''' | ||
'end': '(?<=\\))(?!\\w)' | ||
'name': 'meta.function.c' | ||
'patterns': [ | ||
{ | ||
'include': '#function-innards' | ||
} | ||
] | ||
'include': '#storage_types' | ||
} | ||
{ | ||
'include': '#line_continuation_character' | ||
|
@@ -311,6 +331,21 @@ | |
'4': | ||
'name': 'variable.other.member.c' | ||
'match': '((\\.)|(->))\\s*(([a-zA-Z_][a-zA-Z_0-9]*)\\b(?!\\s*\\())?' | ||
'arguments': | ||
'begin': '\\(' | ||
'beginCaptures': | ||
'0': | ||
'name': 'punctuation.definition.arguments.begin.bracket.round.c' | ||
'end': '\\)' | ||
'endCaptures': | ||
'0': | ||
'name': 'punctuation.definition.arguments.end.bracket.round.c' | ||
'name': 'meta.arguments.c' | ||
'patterns': [ | ||
{ | ||
'include': '$base' | ||
} | ||
] | ||
'block': | ||
'patterns': [ | ||
{ | ||
|
@@ -347,9 +382,6 @@ | |
{ | ||
'include': '#libc' | ||
} | ||
{ | ||
'include': '#c_function_call' | ||
} | ||
{ | ||
'captures': | ||
'1': | ||
|
@@ -395,21 +427,17 @@ | |
'include': '$base' | ||
} | ||
] | ||
'c_function_call': | ||
'function-call': | ||
# FIRST CAPTURE meta.function-call.c scope (provides an injectable scope, balanced parentheses and prevents unnecessary scope nesting) | ||
'begin': '''(?x) | ||
(?!(?:while|for|do|if|else|switch|catch|enumerate|return|sizeof|[cr]?iterate)\\s*\\() | ||
(?= | ||
(?:[A-Za-z_][A-Za-z0-9_]*+|::)++\\s*\\( # actual name | ||
| | ||
(?:(?<=operator)(?:[-*&<>=+!]+|\\(\\)|\\[\\]))\\s*\\( | ||
) | ||
''' | ||
'end': '(?<=\\))(?!\\w)' | ||
'begin': '([A-Za-z_]\\w*)(?=\\s*\\()' | ||
'beginCaptures': | ||
'1': | ||
'name': 'entity.name.function.c' | ||
'end': '(?<=\\))' | ||
'name': 'meta.function-call.c' | ||
'patterns': [ | ||
{ | ||
'include': '#function-call-innards' | ||
'include': '#arguments' | ||
} | ||
] | ||
'comments': | ||
|
@@ -526,6 +554,40 @@ | |
'name': 'constant.numeric.c' | ||
} | ||
] | ||
'parameters': | ||
'patterns': [ | ||
{ | ||
'begin': '\\(' | ||
'beginCaptures': | ||
'0': | ||
'name': 'punctuation.definition.parameters.begin.bracket.round.c' | ||
'end': '\\)' | ||
'endCaptures': | ||
'0': | ||
'name': 'punctuation.definition.parameters.end.bracket.round.c' | ||
'name': 'meta.parameters.c' | ||
'patterns': [ | ||
{ | ||
'include': '#vararg_ellipses' | ||
} | ||
{ | ||
'match': '\\b(const)\\b' | ||
'name': 'storage.modifier.c' | ||
} | ||
{ | ||
'include': '#storage_types' | ||
} | ||
{ | ||
'match': '[A-Za-z_]\\w*' | ||
'name': 'variable.parameter.c' | ||
} | ||
{ | ||
'match': ',' | ||
'name': 'punctuation.separator.delimiter.c' | ||
} | ||
] | ||
} | ||
] | ||
'parens': | ||
'begin': '\\(' | ||
'beginCaptures': | ||
|
@@ -629,10 +691,7 @@ | |
'include': '#libc' | ||
} | ||
{ | ||
'include': '#c_function_call' | ||
} | ||
{ | ||
'include': '$self' | ||
'include': '$base' | ||
} | ||
] | ||
} | ||
|
@@ -1679,63 +1738,47 @@ | |
'include': '#preprocessor-rule-define-line-contents' | ||
} | ||
] | ||
'function-innards': | ||
'function-body': | ||
'patterns': [ | ||
{ | ||
'include': '#comments' | ||
} | ||
{ | ||
'include': '#storage_types' | ||
} | ||
{ | ||
'include': '#operators' | ||
} | ||
{ | ||
'include': '#vararg_ellipses' | ||
} | ||
{ | ||
'begin': '''(?x) | ||
(?!(?:while|for|do|if|else|switch|catch|enumerate|return|sizeof|[cr]?iterate)\\s*\\() | ||
( | ||
(?:[A-Za-z_][A-Za-z0-9_]*+|::)++ # actual name | ||
| | ||
(?:(?<=operator)(?:[-*&<>=+!]+|\\(\\)|\\[\\])) | ||
) | ||
\\s*(\\() | ||
''' | ||
'begin': '{' | ||
'beginCaptures': | ||
'1': | ||
'name': 'entity.name.function.c' | ||
'2': | ||
'name': 'punctuation.section.parameters.begin.bracket.round.c' | ||
'end': '\\)' | ||
'0': | ||
'name': 'punctuation.definition.function.begin.bracket.curly.c' | ||
'end': '}' | ||
'endCaptures': | ||
'0': | ||
'name': 'punctuation.section.parameters.end.bracket.round.c' | ||
'name': 'punctuation.definition.function.end.bracket.curly.c' | ||
'contentName': 'meta.function.body.c' | ||
'patterns': [ | ||
{ | ||
'include': '#function-innards' | ||
'include': '#block_innards' | ||
} | ||
] | ||
} | ||
] | ||
'function-innards': | ||
'patterns': [ | ||
{ | ||
'begin': '\\(' | ||
'beginCaptures': | ||
'0': | ||
'name': 'punctuation.section.parens.begin.bracket.round.c' | ||
'end': '\\)' | ||
'endCaptures': | ||
'0': | ||
'name': 'punctuation.section.parens.end.bracket.round.c' | ||
'include': '#comments' | ||
} | ||
{ | ||
'match': '[A-Za-z_]\\w*(?=\\s*\\()' | ||
'name': 'entity.name.function.c' | ||
} | ||
{ | ||
'include': '#parameters' | ||
} | ||
{ | ||
'begin': '(?=[A-Za-z_]\\w*\\s+[A-Za-z_]\\w*\\s*\\()' | ||
'end': '(?!\\G)' | ||
'name': 'meta.function.return-type.c' | ||
'patterns': [ | ||
{ | ||
'include': '#function-innards' | ||
'include': '#storage_types' | ||
} | ||
] | ||
} | ||
{ | ||
'include': '$base' | ||
} | ||
] | ||
'function-call-innards': | ||
'patterns': [ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not require a return type for functions.
That will break:
main()
(with noint
) convention (before C99)(which works at the moment as below)
(which work at the moment as below)
A_Macro()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Then I think this will become trickier, because I've mostly been relying on the return type to figure out if it's a function or a function call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some tips for you:
You should go according to these.