-
Notifications
You must be signed in to change notification settings - Fork 15
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 more syntaxes to language Julia #16
Add more syntaxes to language Julia #16
Conversation
@singularitti in version 0.7, there are now options for "ignore blocks", such as comments (both single and multiline) and strings! |
} | ||
], | ||
inlineOpenTokens: [], | ||
openTokens: [ | ||
"if", | ||
"struct", | ||
"abstract type", | ||
"primitive type", | ||
"begin", | ||
"let", | ||
"for", |
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.
@singularitti Also, if non-generator-like for
requires do
or another token, you could change this to:
"for", | |
"for(?=.*do)", |
This should now only match expressions like: for ... do
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.
Hi, I am trying to use this pattern "^\s*for"
(A for
with only blank characters before it) to replace "for"
, but it does not seem to succeed. The below generator expression
[getfield(x, :a) for x in object.b.c],
is still treated as a for
loop.
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.
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 familiar with Julia. Why the for
preceeded by @SoftScope shouldn't be matched? This might bring problems with the matching end
for it.
Check if this token works well enough for for
:
(?<=\\[[^\\]]*)for(?![^\\]]*\\]))
It uses negative lookahead and positive lookbehind to try and match those generators.
I don't know if it can handle nested or multiline generators.
Another option is adding [
and ]
as open and close tokens for an ignore block. This is not ideal, but would avoid ugly breakage for the rest of the 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.
Hi @polvalente, thank you for your reply. I am not an expert in regex, so I just wrote the simplest example. Yes, indeed, that will break the highlighting.
I cannot figure out a good regex to distinguish the for
loops and generator expressions. Because Julia is so flexible that it allows a lot of ways to write a for
loop. The only difference between them just seems to be for
loops have an end
. I will list some test examples below. I hope you can figure out a working way to distinguish them. Thank you!
Below are normal for
loops so should be paired with end
s.
# Those should be matched.
for i = 1:10
s += i
end
@softscope for i in 1:10
s += i
end
softscope(Main, :(for i = 1:10
s += i
end))
for i in 1:10; println(i); end
for i in [1, 2, 3]
println(i)
end
for i in collect(1:10)
println(i)
end
Below are generator expressions and are not paired with end
s:
# Those should not be matched.
sum(1/n^2 for n=1:1000)
map(tuple, (1/(i+j) for i=1:2, j=1:2), [1 3; 2 4])
[(i,j) for i=1:3 for j=1:i if i+j == 4]
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.
Oh wow. I think there is a problem with how I implemented ignore blocks. I'll refactor it in the coming weekend.
Basically, I didn't think to support nesting. As such, ((x) for)
will be passed to the coloring function as for)
(because the first closing paren will close the first open paren).
Luckily, I already have an idea on how to solve it (by using stacks).
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.
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.
Nevermind the weekend: #19
HAHA
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.
Cool! Cannot wait to have a try!
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 have tried this method. It seems that with the following test text:
sum(1/n^2 for n=1:1000) map(tuple, (1/(i+j) for i=1:2, j=1:2), [1 3; 2 4]) [(i,j) for i=1:3 for j=1:i if i+j == 4] for i = 1:10 s += i end @softscope for i in 1:10 s += i end softscope(Main, :(for i = 1:10 s += i end)) for i in 1:10; println(i); end for i in [1, 2, 3] println(i) end for i in collect(1:10) println(i) endThe
map(tuple, (1/(i+j) for i=1:2, j=1:2), [1 3; 2 4])
is not working because there is one)
before thefor
.
Hi, could you tell me how to use it? Thank you! |
There are some examples in other languages' specs. It's the |
Thank you. I am already using this syntax. |
test to see what would happen Co-Authored-By: Paulo Valente <[email protected]>
0.7.2 releases with the nested block improve. |
I found a very strange behavior: """
# module Test
# Examples
"""
module Test
function aa()
open(x, "") do io
end
end # function aa
end Specifically, once I type in the BeforeAfterHowever, if I remove the BeforeAfterI suppose that the |
Maybe there is an "off-by-one" error happening with the new ignore-blocks implementation. I might only be able to look into that in the weekend. If you'd like to give it a go, I suspect the problem is during the slicing to replace the text with spaces. |
Turns out the problem was the way the delimiter pairing was implemented in the new version. It broke when both the opening and closing delimiters were equal to each other. #20 attempts to fix this problem. |
The following example is broken after I sync PR #20 module XXXX
primitive type Float16 <: AbstractFloat 16 end
primitive type Float32 <: AbstractFloat 32 end
primitive type Float64 <: AbstractFloat 64 end
primitive type Bool <: Integer 8 end
primitive type Char <: AbstractChar 32 end
primitive type Int8 <: Signed 8 end
primitive type UInt8 <: Unsigned 8 end
primitive type Int16 <: Signed 16 end
primitive type UInt16 <: Unsigned 16 end
primitive type Int32 <: Signed 32 end
primitive type UInt32 <: Unsigned 32 end
primitive type Int64 <: Signed 64 end
primitive type UInt64 <: Unsigned 64 end
primitive type Int128 <: Signed 128 end
primitive type UInt128 <: Unsigned 128 end
abstract type Number end
abstract type Real <: Number end
struct Point end
struct Point <: AbstractPoint; x; y; end
end
openTokens: [
...,
"abstract\s+type",
"primitive\s+type",
...
], but it does not work. |
@noplay Maybe we could refactor the token matching spec to accept whole regexes and match each one individually, instead of building the regex from strings. I've encountered some problems in dealing with some of Elixir's syntax that have arisen from this too. |
as mentioned in #16 (comment)
We still have 1 bug to fix. |
@singularitti I know. I'm kinda overwhelmed with things at work, but I'll get to it as soon as possible. My mention to @noplay was intended as a long term bug fix, because there are some things that can't really be matched by regexes as of now. I already have some ideas, such as implementing an option to specify raw regexes instead of building an option regex from words. However, this will demand some work. Anyway, I'll try to fix this specific problem independently of this |
No hurry. I was just writing down a "TODO". Take your time! |
@singularitti and @noplay, just an update on this: I'll draft a proposal as an issue and link this PR there. |
Sorry to be unresponsive, I'm super busy. But fully support your
initiatives.
Le ven. 4 oct. 2019 à 04:22, Paulo Valente <[email protected]> a
écrit :
… @singularitti <https://github.com/singularitti> and @noplay
<https://github.com/noplay>, just an update on this:
Next week I'll be working on a proposal for a new matching system to avoid
some workarounds and problems we've been having. Hopefully, this will solve
the issues we have with the current framework.
I'll draft a proposal as an issue and link this PR there.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AACUKXLJXIXCMDURUGPFBXLQM2SF5ANCNFSM4ISYEOMQ>
.
|
No worries! I was pretty busy as well, but things have settled by now. I hope to have something to show by Friday! |
@singularitti @noplay #21 |
What is the status of this PR? Even with the outstanding bugs it seems to be an improvement. I support this being merged and will be happy to contribute to further Julia support. |
@xtalax you are right I will merge like this |
Hi @noplay. Thank you so much for such a good extension!
In my last issue (#15), I forgot to mention some other syntaxes that also require
end
s. I have added them here.One fix is that Julia accepts what in
'
and'
as a character, so there is no possibility for anend
inside''
. Besides, Julia does support multi-line comment, starting with#=
and ending with=#
. So I replaced'
with them.The only thing that I cannot handle is that Julia also supports Python-like generator expressions, which means you could write
for
without anend
:That breaks the highlighting. The
for
will match anotherend
. Is there a way to solve this problem?