Comments (16)
Pkg.add()
from julia-sublime.
Now all built-in modules are scoped with support.module
. I fetch all built-in modules with
filter!(x -> isa(eval(x), Module), [names(Base); names(Core)])
Note that support.module
is usually not highlighted, so this change will not be visible (with the default color scheme).
So far, I do not scope add
in Pkg.add
with support.function
. I wish to discuss this with you: As I see it, ideally we have, in Pkg.add()
, that Pkg
is scoped with support.module
and add
is scoped with support.function
. Similarly for all built-in modules and their built-in functions. The issue is that this leads to lots of special cases (there are 25 built-in modules), could be a mess to maintain. Should this be done or not, what do you think? (Regardless, built-in functions that can be directly used, such as abs()
, get the scope support.function
, but if this discussed part is not fixed, then abs
in Base.abs()
is not scoped with support.function
.)
This also made me realize that .
was always scoped as an operator. This was wrong, for example in
Module.foo()
the dot is not an operator, it should not be scoped as such. I've fixed this also, so that .
is only scoped as an operator when it acts like an operator, the only case is broadcasting, such as in
foo.(vector)
from julia-sublime.
There are two three cases. Consider M.foo()
M
is a supported module, butfoo
is not a supported (exported) function, e.g.Base.process_events()
.M
is not a supported module, butfoo
is a supported function. E.g.DataFrames.length()
.
Though in practice, no one will perform such a call sincelength
is available everywhere.- Both
M
andfoo
are supported.
I argue that in case 1, it should not be scoped to indicate that the function is not exported. And in cases 2 and 3, foo
should be scoped as support.function
.
With this logic,
- the
add
inPkg.add()
should not scoped assupport.function
length
inBase.length()
should scoped assupport function
length
inDataFrames.length()
should scoped assupport function
It also raises another issue, consider the followings
Base.Base64.eval()
# ^ this is a module
Base64
is currently scoped as variable.function
, I guess the most appropriate scope is variable.other.member
or simply variable.other
.
from julia-sublime.
It also raises another issue ...
Yes, I messed up a bit. Fixed now!
How do we know that length
in DataFrames.length()
should scoped as support function? length
is not necessarily available everywhere, and even if it is present, it is not necessarily a built-in.
Right now only supported functions from Base and Core are highlighted only when they are used directly, i.e. as abs()
but not Base.abs()
.
from julia-sublime.
How do we know that length in DataFrames.length() should scoped as support function? length is not necessarily available everywhere, and even if it is present, it is not necessarily a built-in.
I think it is generally an error to override built-in functions without proper import
. It is quite safe to assume that Module.length()
is Base.length()
julia> type A end
julia> length(a::A) = 1
length (generic function with 1 method)
julia> length([1,2,3])
ERROR: MethodError: no method matching length(::Array{Int64,1})
you may have intended to import Base.length
Closest candidates are:
length(::A) at REPL[2]:1
Also, it may be a nice feature to highlight those built-in functions to alert users that those names are already taken. They should either import the functions or use other names.
from julia-sublime.
I agree, but we are highlighting length()
right now, but not SomeModule.length()
. Whether or not SomeModule
contains the method length
cannot be known by the syntax highlighter. I don't see how we can improve this further.
from julia-sublime.
That is why I said they are available everywhere.
julia> module A end
A
julia> A.length([1,2,3])
3
from julia-sublime.
Aha, ok! So, how do we get a list of these always-present-methods? To extract the methods from Base
I do names(Base)
. However,
julia> module A end
A
julia> names(A)
1-element Array{Symbol,1}:
:A
julia> names(A, true, true)
5-element Array{Symbol,1}:
Symbol("#eval")
:A
:Any
:Tuple
:eval
from julia-sublime.
I guess we should only scope the exported functions.
from julia-sublime.
So, no further changes?
from julia-sublime.
The only thing that I can think of now is the scope of A.length()
as the function A.length
is the same as Base.length
.
from julia-sublime.
This discussion has shown that we want to be ambitious. This commit goes all the ways. Base.abs
is highlighted as well as abs
, also Pkg.add
is highlighted. I do like python, I highlight both length
and length()
as support.function
, of course only the latter has meta.function-call
. Re-open if I missed anything.
from julia-sublime.
It would be nice to have a script to generate the the syntax file programmatically.
from julia-sublime.
I have included the code I used to fetch exported functions etc. in comments in the syntax file. See for example https://github.com/JuliaEditorSupport/Julia-sublime/blob/master/Julia.sublime-syntax#L31. Is this what you mean?
from julia-sublime.
I meant a script to load the .sublime-syntax
and replace those lines directly. I thought about using YAML.jl, but all the comments may be lost.
from julia-sublime.
Cool idea! In the current state this might add more complexity than needed though. I'd prefer to keep it simple. However, if we get more and more generated regexes, going this route would be nice. At some stage one might even want to have auto completion for built-in functions and packages, with built in documentation for function call parameters etc. Something IDE-like. Perhaps as a separate package though, not everyone wants this from a syntax highlighting package. Maybe such IDE packages already exist, maybe one can build on sublime code intel or similar
from julia-sublime.
Related Issues (20)
- Syntax hangs HOT 3
- Bug: trying to open julia/base/reducedim.jl fails HOT 3
- Syntax highlighting completely broken on ST4 HOT 16
- Definition / goto is broken for function definitions prefixed with package name HOT 3
- Syntax highlighting bug HOT 1
- Unicode Completion in Search Bar HOT 18
- Unicode expansion for other file types HOT 2
- Can not work in Markdown code block HOT 3
- Scope and syntax highlighting issue in the sequence scope
- Fix order of match blocks for macro rule HOT 4
- Docstrings are treated as regular strings if they are indented HOT 4
- Multi-line Comments HOT 4
- Recognizing keyword argument in f(x; kwd) HOT 11
- Package Control.sublime-package installation - I am lost... HOT 1
- Syntax highlighting for function name starting with `struct` broken
- v 4133 and unicode tab completion HOT 3
- Syntax highlighting inside quote block
- Error loading syntax file
- Correct syntax highlighting for "import Foo as Bar"
- Error loading syntax file "Package/Julia/Julia.sublime-syntax" HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from julia-sublime.