Menu

Unicon Vim syntax highlighter

2016-10-23
2018-03-21
  • Brian Tiffin

    Brian Tiffin - 2016-10-23

    Need testers, and opinions. Should Unicon use separate colours for extension, or fallback to the same colours that would be used if these elements were part of Icon? Should Graphics be separate? Etc. The palette is fairly limited by Vim themes and which syntax group names are recognized, but there is a little leeway if that is what people think should be done.

    " Vim syntax file
    " Language: Unicon
    " Maintainer:   Brian Tiffin (btiffin@gnu.org)
    " URL: https://sourceforge.net/projects/unicon
    " Last Change:  2016 Oct 22
    
    " quit when a syntax file was already loaded
    if exists("b:current_syntax")
      finish
    endif
    
    " Read the Icon syntax to start with
    runtime! syntax/icon.vim
    unlet b:current_syntax
    
    " Unicon function extensions
    syn keyword uniconFunction Abort Active Alert Any Arb Arbno array
    syn keyword uniconFunction Attrib Bak Bg Break Breakx chmod chown
    syn keyword uniconFunction chroot classname Clip Clone cofail Color
    syn keyword uniconFunction ColorValue condvar constructor CopyArea
    syn keyword uniconFunction Couple crypt ctime dbcolumns dbdriver
    syn keyword uniconFunction dbkeys dblimits dbproduct dbtables display
    syn keyword uniconFunction DrawArc DrawCircle DrawCube DrawCurve
    syn keyword uniconFunction DrawCylinder DrawDisk DrawImage DrawLine
    syn keyword uniconFunction DrawPoint DrawPolygon DrawRectangle
    syn keyword uniconFunction DrawSegment DrawSphere DrawString DrawTorus
    syn keyword uniconFunction EraseArea Event eventmask EvGet EvSend
    syn keyword uniconFunction exec Eye Fail fdup Fence fetch Fg fieldnames
    syn keyword uniconFunction filepair FillArc FillCircle FillPolygon
    syn keyword uniconFunction FillRectangle flock Font fork FreeColor
    syn keyword uniconFunction FreeSpace getegid geteuid getgid getgr
    syn keyword uniconFunction gethost getpgrp getpid getppid getpw
    syn keyword uniconFunction getrusage getserv GetSpace gettimeofday
    syn keyword uniconFunction getuid globalnames GotoRC GotoXY gtime
    syn keyword uniconFunction IdentityMatrix InPort Int86 ioctl istate
    syn keyword uniconFunction keyword kill Len link load localnames lock
    syn keyword uniconFunction Lower MatrixMode max membernames methodnames
    syn keyword uniconFunction methods min mkdir MultMatrix mutex name
    syn keyword uniconFunction NewColor Normals NotAny opencl oprec OutPort
    syn keyword uniconFunction PaletteChars PaletteColor PaletteKey
    syn keyword uniconFunction paranames parent Pattern Peek Pending pipe
    syn keyword uniconFunction Pixel PlayAudio Poke PopMatrix Pos proc
    syn keyword uniconFunction PushMatrix PushRotate PushScale PushTranslate
    syn keyword uniconFunction QueryPointer Raise ReadImage readlink ready
    syn keyword uniconFunction receive Refresh Rem rmdir Rotate Rpos Rtab
    syn keyword uniconFunction Scale select send setenv setgid setgrent
    syn keyword uniconFunction sethostent setpgrp setpwent setservent setuid
    syn keyword uniconFunction signal Span spawn sql stat staticnames
    syn keyword uniconFunction StopAudio structure Succeed Swi symlink
    syn keyword uniconFunction sys_errstr syswrite Tab Texcoord Texture
    syn keyword uniconFunction TextWidth Translate trap truncate trylock
    syn keyword uniconFunction umask Uncouple unlock utime wait
    syn keyword uniconFunction WAttrib WDefault WFlush WinAssociate
    syn keyword uniconFunction WinButton WinColorDialog WindowContents
    syn keyword uniconFunction WinEditRegion WinFontDialog WinMenuBar
    syn keyword uniconFunction WinOpenDialog WinPlayMedia WinSaveDialog
    syn keyword uniconFunction WinScrollBar WinSelectDialog WriteImage
    syn keyword uniconFunction WSection WSync
    
    " Unicon and Icon Graphic Keywords
    syn match uniconKeyword "&col"
    syn match uniconKeyword "&column"
    syn match uniconKeyword "&control"
    syn match uniconKeyword "&errno"
    syn match uniconKeyword "&eventcode"
    syn match uniconKeyword "&eventsource"
    syn match uniconKeyword "&eventvalue"
    syn match uniconKeyword "&interval"
    syn match uniconKeyword "&ldrag"
    syn match uniconKeyword "&lpress"
    syn match uniconKeyword "&lrelease"
    syn match uniconKeyword "&mdrag"
    syn match uniconKeyword "&meta"
    syn match uniconKeyword "&mpress"
    syn match uniconKeyword "&mrelease"
    syn match uniconKeyword "&pick"
    syn match uniconKeyword "&now"
    syn match uniconKeyword "&rdrag"
    syn match uniconKeyword "&resize"
    syn match uniconKeyword "&row"
    syn match uniconKeyword "&rpress"
    syn match uniconKeyword "&rrelease"
    syn match uniconKeyword "&shift"
    syn match uniconKeyword "&window"
    syn match uniconKeyword "&x"
    syn match uniconKeyword "&y"
    
    " New reserved words
    syn keyword uniconReserved critical import initially invocable method
    syn keyword uniconReserved package thread 
    
    " Storage class reserved words
    syn keyword uniconStorageClass  abstract class
    
    " Define the highlighting colour groups
    hi def link uniconStorageClass  StorageClass
    hi def link uniconFunction      Statement
    hi def link uniconReserved      Label
    hi def link uniconKeyword       Operator
    
    let b:current_syntax = "unicon"
    

    unicon.vim

    There are a couple of ways to get this to operate in Vim. First, put this file in ~/.vim/syntax/ as unicon.vim (or where ever your version of Vim likes to find local scripts).

    Then in ~/.vimrc add

    autocmd BufRead,BufNewFile *.icn            set filetype=unicon
    

    .vimrc update

    If you'd like .icn files to be Unicon extended and not just Icon files. Icon is still supported with this syntax file, as shipped with Vim. Or you can change the system wide filetypes.vim but that is less recommended, let Icon take that pride of place and avoid mucking around when Vim updates occur.

    Then start in on enjoying Unicon extension highlighting.

    If anyone thinks there should be a separation of colours, I have a small text file with all the extensions on separate lines (sans any mistakes I likely made going bleary eyed with the various details), and it'll be easier to recreate a properly sorted Vim keyword list from that source than to try and edit this particular file. Otherwise it should be good to go for testing, and the colours will match what you exepct from Icon highlighting. There will be mistakes.

    Have good, make better,
    Brian

     

    Last edit: Brian Tiffin 2016-10-24
  • Jafar

    Jafar - 2016-10-23

    I'm not a vim user, so I can't be of much help for the testing part... but my opinion for your questions:

    "Should Unicon use separate colours for extension, or fallback to the same colours that would be used if these elements were part of Icon?"

    Personally, I'd prefere to NOT use seperate colors for extensions. I care more about consitency of a color where all keywords for example are of the same color, regardless of whether some keywords are part of Icon or not.

    "Should Graphics be separate?"
    Not a bad idea. I believe all graphics functions start with an uppercase letter to distinguish them from non-graphics functions.

    Emacs/Vim/? syntax files should probably be offered on Unicon website or checked in to svn and documented to make it easy for end users to use/apply them.

    Cheers,
    Jafar

     
  • Brian Tiffin

    Brian Tiffin - 2016-10-23

    Personally, I'd prefere to NOT use seperate colors for extensions. I care more about consitency of a color where all keywords for example are of the same color, regardless of whether some keywords are part of Icon or not.

    I think the same, having experimented a little.

    "Should Graphics be separate?"
    Not a bad idea. I believe all graphics functions start with an uppercase letter to distinguish them from non-graphics functions.

    I'll separate them by syntax group, and then it'll be easy to change back and forth to separate colour or shared with all the other functions.

    Emacs/Vim/? syntax files should probably be offered on Unicon website or checked in to svn and documented to make it easy for end users to use/apply them.

    I'd love that. But I'd didn't want to pester for permissions. I'll prep a README this evening. Feel free to snag the existing copy if you want to check it in, or open up permissions and I'll make the check in. It already has the project space as the URL in the header comments. :-)

    On a side issue with that, if you think it is becoming worthy, I'd feel honoured if the UP docs were actually homed as part of the Unicon project space here on the forge. There is a lot that can be done with the webshell they provide, and it'll up the visibility/permanency a little bit. For the GnuCOBOL project we actually have a compiler built on the forge and host a few CGI samples there, along with all the documentation pages. I find it's a forge resource offering that goes under utilized.

    Have good, make well,
    Brian

     
  • Clinton Jeffery

    Clinton Jeffery - 2016-10-26

    Brian,

    Yes, let's move towards placing the UP docs up on source forge. I'll send you an e-mail with some
    of the particulars.

    Cheers,
    Clint

     
    • Brian Tiffin

      Brian Tiffin - 2016-10-26

      Clinton Jeffery wrote:

      Brian,

      Yes, let's move towards placing the UP docs up on source forge. I'll send you an e-mail with some
      of the particulars.

      Cheers,
      Clint

      Looking forward, Clint. Thanks.

      Have good,
      Brian

       

      Last edit: Brian Tiffin 2016-10-29
  • Brian Tiffin

    Brian Tiffin - 2016-11-26

    New cut of the Vim highlighter. Graphics, and a few of the old system specific (MS-DOS and Archimedes) get a separate colour (if applicible to the theme in use).

    " Vim syntax file
    " Language: Unicon
    " Maintainer:   Brian Tiffin (btiffin@gnu.org)
    " URL: https://sourceforge.net/projects/unicon
    " Last Change:  2016 Oct 22
    
    " quit when a syntax file was already loaded
    if exists("b:current_syntax")
      finish
    endif
    
    " Read the Icon syntax to start with
    runtime! syntax/icon.vim
    unlet b:current_syntax
    
    " Unicon function extensions
    syn keyword uniconFunction Abort Any Arb Arbno array
    syn keyword uniconFunction Break Breakx chmod chown
    syn keyword uniconFunction chroot classname cofail Color
    syn keyword uniconFunction condvar constructor 
    syn keyword uniconFunction crypt ctime dbcolumns dbdriver
    syn keyword uniconFunction dbkeys dblimits dbproduct dbtables display
    syn keyword uniconFunction eventmask EvGet EvSend
    syn keyword uniconFunction exec Fail fdup Fence fetch fieldnames
    syn keyword uniconFunction filepair
    syn keyword uniconFunction flock fork
    syn keyword uniconFunction getegid geteuid getgid getgr
    syn keyword uniconFunction gethost getpgrp getpid getppid getpw
    syn keyword uniconFunction getrusage getserv gettimeofday
    syn keyword uniconFunction getuid globalnames gtime
    syn keyword uniconFunction ioctl istate
    syn keyword uniconFunction keyword kill Len link load localnames lock
    syn keyword uniconFunction max membernames methodnames
    syn keyword uniconFunction methods min mkdir mutex name
    syn keyword uniconFunction NotAny Nspan opencl oprec
    syn keyword uniconFunction paranames parent pipe
    syn keyword uniconFunction Pos proc
    syn keyword uniconFunction readlink ready
    syn keyword uniconFunction receive Rem rmdir Rpos Rtab
    syn keyword uniconFunction select send setenv setgid setgrent
    syn keyword uniconFunction sethostent setpgrp setpwent setservent setuid
    syn keyword uniconFunction signal Span spawn sql stat staticnames
    syn keyword uniconFunction structure Succeed symlink
    syn keyword uniconFunction sys_errstr syswrite Tab
    syn keyword uniconFunction trap truncate trylock
    syn keyword uniconFunction umask unlock utime wait
    
    " Unicon graphics, audio and VOIP
    syn keyword uniconGraphics Active Alert
    syn keyword uniconGraphics Attrib Bg
    syn keyword uniconGraphics Clip Clone Color
    syn keyword uniconGraphics ColorValue CopyArea
    syn keyword uniconGraphics Couple 
    syn keyword uniconGraphics DrawArc DrawCircle DrawCube DrawCurve
    syn keyword uniconGraphics DrawCylinder DrawDisk DrawImage DrawLine
    syn keyword uniconGraphics DrawPoint DrawPolygon DrawRectangle
    syn keyword uniconGraphics DrawSegment DrawSphere DrawString DrawTorus
    syn keyword uniconGraphics EraseArea Event
    syn keyword uniconGraphics Eye Fg
    syn keyword uniconGraphics FillArc FillCircle FillPolygon
    syn keyword uniconGraphics FillRectangle Font FreeColor
    syn keyword uniconGraphics GotoRC GotoXY
    syn keyword uniconGraphics IdentityMatrix
    syn keyword uniconGraphics Lower MatrixMode
    syn keyword uniconGraphics MultMatrix
    syn keyword uniconGraphics NewColor Normals
    syn keyword uniconGraphics PaletteChars PaletteColor PaletteKey
    syn keyword uniconGraphics Pattern Pending
    syn keyword uniconGraphics Pixel PlayAudio PopMatrix
    syn keyword uniconGraphics PushMatrix PushRotate PushScale PushTranslate
    syn keyword uniconGraphics QueryPointer Raise ReadImage
    syn keyword uniconGraphics Refresh Rotate
    syn keyword uniconGraphics Scale
    syn keyword uniconGraphics StopAudio
    syn keyword uniconGraphics Texcoord Texture
    syn keyword uniconGraphics TextWidth Translate
    syn keyword uniconGraphics Uncouple
    syn keyword uniconGraphics VAttrib
    syn keyword uniconGraphics WAttrib WDefault WFlush
    syn keyword uniconGraphics WindowContents
    syn keyword uniconGraphics WriteImage WSection WSync
    
    " Unicon system specific
    syn keyword uniconSpecific FreeSpace GetSpace InPort Int86
    syn keyword uniconSpecific OutPort Peek Poke Swi
    syn keyword uniconSpecific WinAssociate WinButton WinColorDialog
    syn keyword uniconSpecific WinEditRegion WinFontDialog WinMenuBar
    syn keyword uniconSpecific WinOpenDialog WinPlayMedia WinSaveDialog
    syn keyword uniconSpecific WinScrollBar WinSelectDialog
    
    " Unicon and Icon Graphic Keywords
    syn match uniconKeyword "&col"
    syn match uniconKeyword "&column"
    syn match uniconKeyword "&control"
    syn match uniconKeyword "&errno"
    syn match uniconKeyword "&eventcode"
    syn match uniconKeyword "&eventsource"
    syn match uniconKeyword "&eventvalue"
    syn match uniconKeyword "&interval"
    syn match uniconKeyword "&ldrag"
    syn match uniconKeyword "&lpress"
    syn match uniconKeyword "&lrelease"
    syn match uniconKeyword "&mdrag"
    syn match uniconKeyword "&meta"
    syn match uniconKeyword "&mpress"
    syn match uniconKeyword "&mrelease"
    syn match uniconKeyword "&pick"
    syn match uniconKeyword "&now"
    syn match uniconKeyword "&rdrag"
    syn match uniconKeyword "&resize"
    syn match uniconKeyword "&row"
    syn match uniconKeyword "&rpress"
    syn match uniconKeyword "&rrelease"
    syn match uniconKeyword "&shift"
    syn match uniconKeyword "&window"
    syn match uniconKeyword "&x"
    syn match uniconKeyword "&y"
    
    " New reserved words
    syn keyword uniconReserved critical import initially invocable method
    syn keyword uniconReserved package thread
    
    " Storage class reserved words
    syn keyword uniconStorageClass  abstract class
    
    " Define the highlighting colour groups
    hi def link uniconStorageClass  StorageClass
    hi def link uniconFunction      Statement
    hi def link uniconGraphics      Special
    hi def link uniconSpecific      SpecialComment
    hi def link uniconReserved      Label
    hi def link uniconKeyword       Operator
    
    let b:current_syntax = "unicon"
    

    unicon.vim

    This syntax file will always be available for a quick download click in the UP docs, currently at

    http://btiffin.users.sourceforge.net/up/tools.html#vim

    Likely to move out of this personal forge space someday soon.

    Clint, Jafar, et al.

    Is Swi supported in Unicon? An Archimedes machine specific feature.

    I toggled back and forth with opencl, it's experimental at the moment, but these syntax files have a way of aging out at different rates than the languages they track. I left opencl in the main function list, assuming it'll be a mainstream feature by the time if/when this file ever gets included in the Vim release tree.

    Have good, make well,
    Brian

     

    Last edit: Brian Tiffin 2016-11-26
    • Jafar

      Jafar - 2016-11-26

      On Sat, Nov 26, 2016 at 1:06 AM, Brian Tiffin btiffin@users.sf.net wrote:

      I left opencl in the main function list, assuming it'll be a mainstream
      feature by the time if/when this file ever gets included in the Vim release
      tree.

      opencl() was nothing more than a quick experiment to get opencl info
      withing a unicon program. It was part of a quick funding proposal to have
      GPU compute in Unicon that didn't get approved. opencl support is something
      that we would like to see come to unicon someday, but I don't think that is
      gonna happen anytime soon.

      Cheers,
      Jafar

       
      • Brian Tiffin

        Brian Tiffin - 2016-11-26

        Thanks for the heads up, Jafar. Save a little typing. ;-)

        Although...it might be a nifty thing to poke around in. Start programming some GPU, for the learnin's.

        And for getting enough compute cycles to keep up with the time machine and avoid all those mistaken warp jumps; dinosaur poop is some sticky poop, takes days to scrape off the lander. Barely worth the trouble of travelling back, when the goal is just to give younger self a wedgie for a quick laugh. I always disliked older self, but I finally get the joke.

        Have good,
        Brian

         
  • Brian Tiffin

    Brian Tiffin - 2017-01-13

    Here is an unsophisticated Vim highlighter for ucode.

    Install in ~/.vim/syntax/ucode.vim

    Add the following line to your ~/.vimrc

    autocmd BufRead,BufNewFile *.u       set filetype=ucode
    

    ucode.vim

    " Vim syntax file
    " Language: Ucode
    " Maintainer:   Brian Tiffin (btiffin@gnu.org)
    " URL: https://sourceforge.net/projects/unicon
    " Last Change:  2017 Jan 13
    
    " quit when a syntax file was already loaded
    if exists("b:current_syntax")
      finish
    endif
    
    "integer number, or floating point number without a dot
    syn match ucodeNumber "\<\d\+\>"
    
    "floating point number, with dot, optional exponent
    syn match ucodeFloat  "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\>"
    
    "floating point number, starting with a dot, optional exponent
    syn match ucodeFloat  "\.\d\+\(e[-+]\=\d\+\)\=\>"
    
    "floating point number, without dot, with exponent
    syn match ucodeFloat  "\<\d\+e[-+]\=\d\+\>"
    
    " Define ucode opcodes
    syn keyword ucodeOpcode asgn bang bscan cat
    syn keyword ucodeOpcode compl create cset
    syn keyword ucodeOpcode diff div dup einit eqv
    syn keyword ucodeOpcode error escan field
    syn keyword ucodeOpcode init int inter invocable
    syn keyword ucodeOpcode keywd lconcat lexeq lexge
    syn keyword ucodeOpcode lexgt lexle lexlt lexne
    syn keyword ucodeOpcode limit llist
    syn keyword ucodeOpcode mark mark0 minus mod mult
    syn keyword ucodeOpcode neg neqv nonnull
    syn keyword ucodeOpcode noop null number numeq numge numgt
    syn keyword ucodeOpcode numle numlt numne
    syn keyword ucodeOpcode plus pnull pop power
    syn keyword ucodeOpcode push1 pushn1
    syn keyword ucodeOpcode random rasgn rcv rcvbk real
    syn keyword ucodeOpcode record refresh rswap
    syn keyword ucodeOpcode sdup sect size snd sndbk
    syn keyword ucodeOpcode str subsc swap
    syn keyword ucodeOpcode tabmat tally
    syn keyword ucodeOpcode unions unmark value var
    
    " Define ucode control flow
    syn keyword ucodeFlow any case ccase chfail coact cofail coret
    syn keyword ucodeFlow efail end endcase endevery endif endifelse
    syn keyword ucodeFlow endrepeat endsuspend enduntil endwhile
    syn keyword ucodeFlow eret esusp every if ifelse invoke goto
    syn keyword ucodeFlow lsusp pfail pret psusp
    syn keyword ucodeFlow repeat suspend synt toby
    syn keyword ucodeFlow until while
    
    " ucode declaratives
    syn keyword ucodeDeclare con declend end global impl
    syn keyword ucodeDeclare lab link local proc
    syn keyword ucodeDeclare uid version
    
    " ucode informational
    syn keyword ucodeInform colm filen line trace
    
    " Define the highlighting colour groups
    hi def link ucodeDeclare        Comment
    hi def link ucodeOpcode         Statement
    hi def link ucodeFlow           Function
    hi def link ucodeInform         SpecialComment
    hi def link ucodeNumber         Number
    hi def link ucodeFloat          Float
    
    let b:current_syntax = "ucode"
    

    Cheers,
    Brian

     

    Last edit: Brian Tiffin 2017-01-13
    • Jafar

      Jafar - 2018-03-20

      Brian,

      What is the state of the Vim Highlighter for Unicon? We have added unicon/config/editor to the sources fo save config files like these. Don Ward added unicon.el for emacs, do you think ucode.vim is in good shape to be added as well ?

       
      • Brian Tiffin

        Brian Tiffin - 2018-03-21

        Not bad, but it should get a few other eye balls before first commit. The files have not changed since I listed the sources above, and attached to those earlier discussion posts.

        Place these in

        ~/.vim/syntax/
        

        for testing/trials.

        I place the following in my ~/.vimrc startup file

        " Unicon - see ~/.vim/ftdetect/unicon.vim
        autocmd BufRead,BufNewFile *.icn     set filetype=unicon
        autocmd BufRead,BufNewFile *.u       set filetype=ucode
        autocmd BufRead,BufNewFile *.r       set filetype=c
        

        In short, I'd say releasable; but my standards are fairly low when it comes to edge cases and colour text issues inside the editor (smiley).

        On the other front, the Pygments teams seems to have stalled out on taking pull requests. Sourceforge still doesn't recognize Unicon code tags, but will, some later day. There is an update for Icon/Unicon/Ucode sitting in the pending queue at https://bitbucket.org/birkenfeld/pygments-main/pull-requests/ posted in August (then I stopped watching too closely). I'll admit to not being very agggressive in pestering. I'll post a few notes and bug people.

        Have good, make colours,
        Blue

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.