-
Notifications
You must be signed in to change notification settings - Fork 591
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
[D] Syntax Improvements #1850
Merged
Merged
[D] Syntax Improvements #1850
Changes from 1 commit
Commits
Show all changes
108 commits
Select commit
Hold shift + click to select a range
162671c
Fix D doc comments
BenjaminSchaaf 23299b9
Fix spacing in D snippets
BenjaminSchaaf 972c2da
Add rdmd to build system for running a single file immediately
BenjaminSchaaf 9f746a4
Implement proper literal parsing for strings and numbers; fix nested …
BenjaminSchaaf 61f9c41
Fix module declaration parsing
BenjaminSchaaf f5326d5
Fix attribute parsing with support for UDAs
BenjaminSchaaf f04ef62
Implement shebang parsing and module validation
BenjaminSchaaf 3eccd67
Implement proper import parsing
BenjaminSchaaf 2caa34b
Rudimentary reimplementation of function and variable parsing
BenjaminSchaaf 2b6488a
Rename all contexts to match usage
BenjaminSchaaf e02d1c2
Implement alias parsing
BenjaminSchaaf 0563c54
Implement validation-less token parsing for token strings
BenjaminSchaaf 561fb1f
Implement non-templated aggregate parsing
BenjaminSchaaf cd763de
Implement enum parsing
BenjaminSchaaf c4ceaf6
Implement conditional declaration parsing
BenjaminSchaaf a506b68
Implement static foreach parsing
BenjaminSchaaf 8478fbf
Implement static assert
BenjaminSchaaf d7c9368
Implement constructor parsing
BenjaminSchaaf 79a6bb3
Fix meta_scope for token strings
BenjaminSchaaf 7d2ecc8
Add function parsing tests
BenjaminSchaaf 67d2413
Implement invariant parsing
BenjaminSchaaf 551cb3c
Make comment inclusion implicit with prototype
BenjaminSchaaf 2bc8445
Implement unittest parsing
BenjaminSchaaf af536c0
Implement special case alias this parsing
BenjaminSchaaf c243559
Implement version and debug spec parsing
BenjaminSchaaf e546000
Implement template and mixin parsing
BenjaminSchaaf aa78501
Fix static if else block not allowing an else static if
BenjaminSchaaf 0ce5bc6
Bit of a refactor and add parsing for conditionals, loops and other f…
BenjaminSchaaf ed980b1
Implement with, synchronized, try/catch/finally, throw and scope stat…
BenjaminSchaaf 4ed36e0
Implement asm statement
BenjaminSchaaf e2a6af7
Fix tests
BenjaminSchaaf 81a86f5
Reimplement number parsing, fixing any inconsistencies
BenjaminSchaaf 2fb7412
Implement aggregate template parsing
BenjaminSchaaf 35ba040
Fix doc comment ligatures
BenjaminSchaaf 303472f
Implement initial proper value parsing with heavy validation
BenjaminSchaaf d502658
Fix some expression and type parsing inconsistencies
BenjaminSchaaf 97aba5f
Fix more minor inconsistencies and implement switch parsing
BenjaminSchaaf 66a10aa
Implement typeof parsing
BenjaminSchaaf 1b47eb1
Fix some more edge cases
BenjaminSchaaf 37dfe2c
Fix typeof(return)
BenjaminSchaaf c3e956e
Initial lambda parsing implementation
BenjaminSchaaf 0498955
Fix auto declarations
BenjaminSchaaf b1459ae
Implement parsing of single enum assignments and template constraints
BenjaminSchaaf 553c4e0
Properly implement lambda parsing
BenjaminSchaaf 8a25a0e
Fix some more small inconsistencies
BenjaminSchaaf e96ecc5
Implement function type parsing and fix small inconsistencies
BenjaminSchaaf b487bd2
Implement __traits parsing and fix small inconsistency with debug
BenjaminSchaaf 1c4e621
Fix some remaining inconsistencies
BenjaminSchaaf cc32808
Fix some more inconsistencies
BenjaminSchaaf 7792a51
Fix *= not being parsed correctly
BenjaminSchaaf b29a9d0
Implement function contract parsing
BenjaminSchaaf 2f83a67
Fixed remaining inconsistencies again
BenjaminSchaaf af294cb
Fix some function/delegate inconsistencies
BenjaminSchaaf ef5bcae
Some remaining small fixes
BenjaminSchaaf 6ffd4a7
Rework tmPreferences for D
BenjaminSchaaf de44796
Improve sublime-build files for D
BenjaminSchaaf 19e5576
Fix destructor with attributes not being parsed correctly
BenjaminSchaaf 6c2cc4f
Add DMD output parsing for building system
BenjaminSchaaf 8cae9fa
Fix main snippets
BenjaminSchaaf 51ebb72
Fix out contracts not being parsed correctly
BenjaminSchaaf edf762f
Add back old tests, fixing matches where required
BenjaminSchaaf f049ab7
Fix not all entities being included in symbol list
BenjaminSchaaf 0290235
Replace `[^\s]` with `\S`
BenjaminSchaaf c7a789e
Replace `(?=.)` with ''
BenjaminSchaaf 78effb9
Add meta.namespace scope for files declaring a module name
BenjaminSchaaf 8b65012
Improve shebang handling
BenjaminSchaaf 475a8a8
s/keyword.control.module.d/keyword.declaration.module.d/g
BenjaminSchaaf e8b230d
Clean up parser a little
BenjaminSchaaf a1934d0
Fix indentation and improve spacing
BenjaminSchaaf 346b883
Change storage.modifier to punctuation.definition.numeric for binary …
BenjaminSchaaf 8464f4a
Make loop keywords use keyword.control.loop.d
BenjaminSchaaf 7de31ea
Change try/catch/finally/throw keywords to use exception scope
BenjaminSchaaf d7b705b
Fix brackets/parens confusion
BenjaminSchaaf 2416707
Replace shebang single regex with a simple context
BenjaminSchaaf 90d9fa0
Improve buile files and DMD output highlighting
BenjaminSchaaf 421ea67
Clean up tmPreferences
BenjaminSchaaf 1d9382d
Rework start of file parsing, including modules and shebangs. Also fi…
BenjaminSchaaf 3767a04
Rename keyword.declaration.module to keyword.declaration.namespace
BenjaminSchaaf 8f3565e
Fix number literal scopes
BenjaminSchaaf a75da79
Add proper identifier parsing and fix assert not being handled as a k…
BenjaminSchaaf f7d82f3
Fix variadic and slice scopes
BenjaminSchaaf e071f6e
Add keyword.declaration scopes to storage type declarations
BenjaminSchaaf d24d133
Fix switch ':' scope
BenjaminSchaaf ba37b44
Improve tests
BenjaminSchaaf 06f7d69
Fix annotation parens scopes
BenjaminSchaaf 3bae0ff
Fix import expression scope
BenjaminSchaaf 0354835
Improve type specialization scopes
BenjaminSchaaf d776db5
Remove dead code
BenjaminSchaaf 69a591b
Add meta.namespace to the module declaration
BenjaminSchaaf dbb212f
Add meta.string.d scope to strings and highlight string prefixes spec…
BenjaminSchaaf c6891c0
Add meta.function scopes for functions
BenjaminSchaaf 7c3c130
Add meta.function scopes for lambdas
BenjaminSchaaf 00a3967
Fix lambda operator scope
BenjaminSchaaf ea7f25c
Add function call meta scopes
BenjaminSchaaf 76534e3
Fix line comment not including newlines
BenjaminSchaaf fe30031
Add class meta scope
BenjaminSchaaf bb450a1
Add interface, struct, union and enum meta scopes
BenjaminSchaaf c7a4857
Add meta.path to identifiers
BenjaminSchaaf 43f8ebe
Fix ternary scope
BenjaminSchaaf 2819f1d
Fix scope of `:` when used for comparison
BenjaminSchaaf 4d168e8
Fix tests
BenjaminSchaaf 141373d
Fix operator overloads being highlighted as keywords instead of entities
BenjaminSchaaf 012b2e2
Fix scope for builtin at-attributes
BenjaminSchaaf 06d1a44
Fix single value template arguments not popping
BenjaminSchaaf 8b09acf
Fix switch with not working
BenjaminSchaaf 8d63290
Add special case for `new` instances of classes using variable.function
BenjaminSchaaf 8b359df
Fix concatenation operator scope
BenjaminSchaaf 95c77fe
Fix template call operator scope
BenjaminSchaaf 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
Implement shebang parsing and module validation
- Loading branch information
commit f04ef6269fd00d87216cb33612db168f3184ce4e
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#! SYNTAX TEST "Packages/D/D.sublime-syntax" | ||
#! <- comment.line.shebang.d | ||
#! <- comment.line.shebang.d | ||
#!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.shebang.d | ||
|
||
// foo | ||
#! ^^^ comment.line.double-slash.d | ||
|
||
#! foo | ||
#! ^^^ - comment.line.shebang.d |
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.
#
should be scoped aspunctuation.definition.comment.number-sign
to match the current shell syntax.Otherwise I am not sure about the global strategy to support shebang directly.
The main shell scope is
source.shell
The bash syntax currently usessoure.shell.bash
.To follow this kind of scheme of different shell types any syntax would need to use
source.shell.<syntax>
.Example:
source.shell.python
,source.shell.erlang
,source.shell.tcl
, ... .Therefore each syntax, which wants to assign itself as a shell type, should provide a dedicated
<Syntax> Shell.sublime-syntax
, I think. (Btw. might be worth a RFC discussion?).@ALL: Maybe something like that would be worth thinking about?
Note: We propably should not be too restrictive with whitespace in front of shebangs?
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.
In relation to the whitespace restriction in front of the
#!
: putting a space in front fails to compile with D.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.
I'm not sure why we'd want a separate syntax for these files. They are still just files in D with a shebang. Imo just highlight the shebang line as a comment, assign appropriate scopes and be done with it.
We could probably unify this across syntaxes as
comment.line.number-sign.shebang
and special-case it.Lua also supports a shebang on the first line only, as does node iirc.
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.
I tried to illustrate the motivation above.
What does the shebang do? It is used by the login shell to decide which interpreter to run for the file.
The ShellScript package defines the
source.shell
scope. It is extended tosource.shell.bash
by the Bash syntax.The idea is just to have a
source.shell.<syntax>
like top-level scope for each syntax, which can be run by the unix shell. ST can then display "D ShellScript" or something like that in the status bar.Another question is, why is the shebang supported by the languages in the first line only? To be compatible with the unix shell.
Anyway, nothing changes but the opportunity to see, whether the file was loaded as shellscript or directly as D-file.
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.
I agree with @FichteFoll, KISS!
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.
I am fine with this strategy as well.
But anyway: the current solution breaks
embed
statements, by callingset: ...
to leave themain
context.The
escape
of the following statement would be ignored.Note: Found it while applying that strategy to Erlang.
The JavaScript syntax uses
push
which works fine withembed
.So something like that might work
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.
Pushing away might on the other hand cause issues, if the syntax is
include
ed into another one, as themain-after-shebang
is never popped off.With that said: This kind of shebang handling is problematic for syntaxes which might want to be ebedded/included into other ones.
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.
see: sublimehq/sublime_text#2395