Jump to content
Muxe Inc Forums
Sign in to follow this  
dandv

Improved Syntax Highlight: Perl And Php

Recommended Posts

dandv    0

I've been programming in Perl for 8 years. Please find below the best Perl syntax highlight for NDN that I have come up with:

 

;════════════════════════════════════════════════════════════════════════════
; PERL Files: C-style numbers, float numbers, case-sensitive
;════════════════════════════════════════════════════════════════════════════
FILES *.PL; *.PM; *.T; *.pod
  GeneralFlags 81
  StringFlags 131
  MultilineComment 1
  CommentString #
  Comment __END__ _no_end_of_such_comment_
  Comment =head1 =cut
;  Comment =item =cut; doesn't work, apparently "=cut" never gets parsed again
  CommentStart =item
;  Comment =head2 =cut

  Keywords1 cmp,eq,gt,lt,ne
  Keywords1 x
  Keywords1 and,not,or,xor
  Keywords1 continue,redo,do,else,elsif,for,foreach,goto,if,last,next,return,unless,until,wh
ile
  Keywords1 package,sub
  Keywords1 require,use
  Keywords1 local,my,our,new,tie
  keywords1 BEGIN
  keywords1 CORE, SUPER, bless
  Keywords2 __LINE__, __FILE__, __DATA__, __PACKAGE__

  Keywords2 abs,atan2,cos,exp,int,log,rand,sin,sqrt,srand
  Keywords2 pop, push, shift, splice, unshift
  Keywords2 delete, each, exists, keys, values
  Keywords2 grep,join,map,reverse,sort
  Keywords2 defined,scalar,ref,undef,wantarray

  Keywords2 seek, sysread, sysseek, syswrite, tell, truncate, chdir, mkdir, opendir, readdir, stat

  Keywords2 binmode, close, eof, fileno, flock, open, rename, select, unlink, utime

  Keywords2 eval,exit,die,exec,system
  Keywords2 glob,

  Keywords2 read, readline, print, printf, warn

  Keywords2 alarm,sleep
  Keywords2 pos,quotemeta,split,
  Keywords2 chomp,chop,index,lc,length,sprintf,substr,uc
  Keywords2 localtime,gmtime,time
  Keywords2 pack,unpack,vec,chr,ord,hex,ord

  Keywords3 $_,@_,$!

  RegKeywords COLOR LightBlue \$[0-9]+
  RegKeywords COLOR LightBlue \\[0-9]+
  RegKeywords COLOR LightRed \\x[a-fA-F0-9]+
  RegKeywords COLOR Red \\x{[a-zA-Z0-9]+}
  RegKeywords COLOR Yellow (?<!\\)\$[A-Za-z0-9_]+
  RegKeywords COLOR LightBlue (?<!\\)\@([a-zA-Z][_a-zA-Z0-9]*|_[_a-zA-Z0-9]+)
  RegKeywords COLOR LightCyan (?<!\\)\%([a-zA-Z][_a-zA-Z0-9]*|_[_a-zA-Z0-9]+)
  RegKeywords COLOR Blue [_a-zA-Z0-9]+ *(?==>)
  RegKeywords COLOR LightBlue (?<={)[_a-zA-Z0-9]+(?=})

;  RegKeywords COLOR Cyan (?si:\=head2.*?\=cut)

; To play the macro: CTRL+J 1
  Macro 1
    Print '#!/usr/local/bin/perl -w'^M'use strict;'^M^M
  EndMacro
  Macro 2
    Print 'while (<>) {'^M^M'}'^M#5#5' '
  EndMacro
  Macro 3
    Print 'use Data::Dump qw(pp ddx);'^M'ddx '
  EndMacro
END

 

I also wrote a JavaScript parser for PHP, so I came up with a number of improvements to the NDN HGL for PHP:

 

;════════════════════════════════════════════════════════════════════════════
; PHP files: GENERALFLAGS = case sensitive + C numbers; Comments: #, //
;════════════════════════════════════════════════════════════════════════════
FILES *.PHP;*.ROS
  GeneralFLAGS 16
  STRINGFLAGS 7
  CommentString #, //
  MultiLineComment 1
  Comment /* */
  Keywords1 as,case,break,const,default,die,else,elseif,exit,for,foreach,continue,if,do,whil
e,function,global,require,require_once,return,switch,try,catch,throw
  Keywords1 xor,or,and
  Keywords1 abstract,class,extends,final,implements,interface, public,private,protected,static,new,instanceof,var
  Keywords1 array,string,list
  Keywords2 __construct
  Keywords2 array_key_exists,array_keys,array_merge,array_slice,array_pop,count,empty,in_arr
ay,is_array
  Keywords2 date
  Keywords2 define,function_exists
  Keywords2 echo,print,printf,print_r,sprintf,error_log,trigger_error
  Keywords2 fclose,file,file_exists,fopen,fwrite,is_readable,readfile,file_get_contents,file
_put_contents
  Keywords2 filetype,unlink
  Keywords2 dir,mkdir,rmdir,realpath
  Keywords2 basename,dirname
  Keywords2 isset,is_null,sizeof,unset
  Keywords2 mktime
  Keywords2 setcookie
  Keywords2 implode,explode,bin2hex,crc32,md5,rand
  Keywords2 str_pad,strlen,trim,strstr,strpos
  Keywords2 preg_match,preg_replace,quotemeta, str_replace
  Keywords2 error_reporting,set_error_handler
  Keywords2 var_dump

  Keywords2 ob_start,header,ob_end

  Keywords3 false,true,NULL,__FILE__,DIRECTORY_SEPARATOR,PATH_SEPARATOR
  Keywords3 self,this,parent

  RegKeywords COLOR Yellow \$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*
  Macro 1
    GoToX 0
    print '<?php'
    print ^M
    print ^M
    print ^M
    print '?>'
    MoveUp 2
  EndMacro

  Macro 2
    GoToX 0
    Print '/*******************************************************************************/'^M^S
    Print '/*---- ------------------------------------------------------------------------*/'^M^S
    Print '/*******************************************************************************/'^M^S
    Print ^E^E^D^D^D^D^D^D^D
    SwitchIns
  EndMacro
  Macro 3
    GoToX 0
    Print '/* --------------------------------------- */'^M^S
    Print '/*  */'^M^S
    Print '/* --------------------------------------- */'^M^S
    Print ^E^E^D^D^D
  EndMacro
END

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×