Author Topic: Any support for docker?  (Read 486 times)

pbrightly

  • Community Member
  • Posts: 60
  • Hero Points: 6
Any support for docker?
« on: May 27, 2023, 12:54:43 AM »
Any support for Docker planned in the future?  Or has anyone bothered to colorize Dockerfile syntax?
I could just do that myself, but I'm surprised if it hasn't been done by anyone.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6589
  • Hero Points: 511
Re: Any support for docker?
« Reply #1 on: May 27, 2023, 05:12:56 PM »
No color coding for it yet. You'll need to use some more advanced regex features to support "# escape=`". You won't be able to support the blank line requirement after preprocessing but I doubt that will be a big problem. Best to define embedded languages to handle this (one profile for backtick and the default profile uses backslash). Not a lot of good docs for token syntax. Otherwise, I would have done more work here. I don't know if strings are multi-line. Don't know if strings support escape. Don't know if there are other strings than double quotes. Don't know what the keywords are.

Add these profiles to your your user.cfg.xml
Code: [Select]
<colorcoding_profiles n="colorcoding_profiles.Docker" version="2">
<idchars v="a-zA-Z_$ 0-9"/>
<case_sensitive v="0"/>
<mn_flags v="dot_float digit_int digit_float"/>
<p n="comment,#">
<attrs color_to_eol="comment" line_continuation_char="\"/>
</p>
<p n='string,"'>
<attrs end='"'/>
</p>
<p n="comment,\#([ \t]*)escape=`">
<attrs end="^(#=\\#([ \\t]*)escape=)" flags="regex end_regex multiline dont_color_as_embedded_if_possible" embedded_lexer="Docker backtick">
</attrs>
</p>
<p n="comment,\#([ \t]*)escape=\\">
<attrs end="^(#=\\#([ \\t]*)escape=)" flags="regex end_regex multiline dont_color_as_embedded_if_possible" embedded_lexer="Docker">
</attrs>
</p>
</colorcoding_profiles>
<colorcoding_profiles n="colorcoding_profiles.Docker backtick" version="2">
<idchars v="a-zA-Z_$ 0-9"/>
<case_sensitive v="0"/>
<mn_flags v="dot_float digit_int digit_float"/>
<p n="comment,#">
<attrs color_to_eol="comment" line_continuation_char="`"/>
</p>
<p n='string,"'>
<attrs end='"'/>
</p>
<p n="string,\#([ \t]*)escape=`">
<attrs end="^(#=\\#([ \\t]*)escape=)" flags="regex end_regex multiline dont_color_as_embedded_if_possible" embedded_lexer="Docker backtick">
</attrs>
</p>
<p n="comment,\#([ \t]*)escape=\\">
<attrs end="^(#=\\#([ \\t]*)escape=)" flags="regex end_regex multiline dont_color_as_embedded_if_possible" embedded_lexer="Docker">
</attrs>
</p>
</colorcoding_profiles>

You will need to create a Docker language mode and reference the "Docker" color coding profile. You can do this in the options dialog.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6589
  • Hero Points: 511
Re: Any support for docker?
« Reply #2 on: May 27, 2023, 10:41:59 PM »
This is a little better. It's not very smart but it does look better. It assumes an upper case word at the start of a line is a keyword and colors anything that looks like a switch (-y or --what-ever) for a command.

Code: [Select]
<colorcoding_profiles n="colorcoding_profiles.Docker" version="2">
<idchars v="a-zA-Z_$ 0-9"/>
<case_sensitive v="1"/>
<mn_flags v="dot_float digit_int digit_float"/>
<p n="comment,#">
<attrs color_to_eol="comment" line_continuation_char="\"/>
</p>
<p n='string,"'>
<attrs end='"' line_continuation_char="\"/>
</p>
<p n="string,'">
<attrs end="'" line_continuation_char="\"/>
</p>
<p n="comment,\#([ \t]*)escape=`">
<attrs end="^(#=\\#([ \\t]*)escape=)" flags="regex end_regex multiline dont_color_as_embedded_if_possible" embedded_lexer="Docker backtick">
</attrs>
</p>
<p n="comment,\#([ \t]*)escape=\\">
<attrs end="^(#=\\#([ \\t]*)escape=)" flags="regex end_regex multiline dont_color_as_embedded_if_possible" embedded_lexer="Docker">
</attrs>
</p>
<!--p n="other,(#&lt;=^[ \t]*)[A-Z]#(#=$|[ \t])">
<attrs end="$" flags="end_regex regex" start_color="k" line_continuation_char='\'>
<iattrs type="lib" start="(#&lt;=(^|[ \t]))--[a-zA-Z0-9\-]#+" flags="regex"/>
<iattrs type="lib" start="(#&lt;=(^|[ \t]))-[a-zA-Z0-9]#+" flags="regex"/>
</attrs>
</p-->
<p n="k,(#&lt;=^[ \t]*)[A-Z]#(#=$|[ \t])">
<attrs flags="regex"/>
</p>
<p n="lib,(#&lt;=(^|[ \t]))--[a-zA-Z0-9\-]#+">
<attrs flags="regex"/>
</p>
<p n="lib,(#&lt;=(^|[ \t]))-[a-zA-Z0-9]#+">
<attrs flags="regex"/>
</p>
</colorcoding_profiles>
<colorcoding_profiles n="colorcoding_profiles.Docker backtick" version="2">
<idchars v="a-zA-Z_$ 0-9"/>
<case_sensitive v="1"/>
<mn_flags v="dot_float digit_int digit_float"/>
<p n="comment,#">
<attrs color_to_eol="comment" line_continuation_char="`"/>
</p>
<p n='string,"'>
<attrs end='"' line_continuation_char="`"/>
</p>
<p n="string,'">
<attrs end="'" line_continuation_char="`"/>
</p>
<p n="string,\#([ \t]*)escape=`">
<attrs end="^(#=\\#([ \\t]*)escape=)" flags="regex end_regex multiline dont_color_as_embedded_if_possible" embedded_lexer="Docker backtick">
</attrs>
</p>
<p n="comment,\#([ \t]*)escape=\\">
<attrs end="^(#=\\#([ \\t]*)escape=)" flags="regex end_regex multiline dont_color_as_embedded_if_possible" embedded_lexer="Docker">
</attrs>
</p>
<p n="k,(#&lt;=^[ \t]*)[A-Z]#(#=$|[ \t])">
<attrs flags="regex"/>
</p>
<p n="lib,(#&lt;=(^|[ \t]))--[a-zA-Z0-9\-]#+">
<attrs flags="regex"/>
</p>
<p n="lib,(#&lt;=(^|[ \t]))-[a-zA-Z0-9]#+">
<attrs flags="regex"/>
</p>
</colorcoding_profiles>

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6589
  • Hero Points: 511
Re: Any support for docker?
« Reply #3 on: June 01, 2023, 11:02:42 PM »
We will add Dockerfile support for v28

pbrightly

  • Community Member
  • Posts: 60
  • Hero Points: 6
Re: Any support for docker?
« Reply #4 on: June 01, 2023, 11:39:13 PM »
Thanks, Clark!  I had already added a Docker language mode just to add a few keywords and get "something". But I had trouble getting comments working in the UI (seemed ignored).

I've added all the following keywords to to your config and it looks really nice.

<p n="k,ARG"/>
<p n="k,CMD"/>
<p n="k,COPY"/>
<p n="k,ENV"/>
<p n="k,EXPOSE"/>
<p n="k,FROM"/>
<p n="k,LABEL"/>
<p n="k,RUN"/>
<p n="k,WORKDIR"/>


What would be spectacular is if I could get bash coloring for anything under RUN or ENV keywords.  But this is excellent as is, just giving me comments and keywords at least. :)

pbrightly

  • Community Member
  • Posts: 60
  • Hero Points: 6
Re: Any support for docker?
« Reply #5 on: June 01, 2023, 11:43:26 PM »
Attached image shows bash under ENV and RUN sections (and the color I get now):

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6589
  • Hero Points: 511
Re: Any support for docker?
« Reply #6 on: June 02, 2023, 01:10:32 PM »
Is the text after RUN always bash syntax or can this vary based on some default shell. Is it way different on Windows?.

pbrightly

  • Community Member
  • Posts: 60
  • Hero Points: 6
Re: Any support for docker?
« Reply #7 on: June 02, 2023, 03:14:02 PM »
Excellent question. :) I'm an odd case, so though I spend my life running a Windows laptop, I spend most of my time doing things in Ubuntu (WSL & about 54 servers). SlickEdit (my Windows apps) and WSL-Ubuntu share a file system. (I use WSL1 for this reason.)
And, I don't care if Windows commands can be run.  But I'm new to this as well, so...guess I should read up.

This is an excellent description of the format of the Dockerfile: https://docs.docker.com/engine/reference/builder/#format

And reading down... yep, I see Windows examples, complete with discussion of customizing escape character '\' to something else. :( Guess that kills my wish for bash color.  Maybe not?  I'd be totally OK to colorize RUN and CMD instructions as bash, but there's probably a bunch of Windows out there.