Add auto-completion for Go & Raku, function list for Raku

- added autoCompletion for Go and Raku to installer script.
- added function list for Raku as starting point, currently just an adapted copy of the perl functionlist.

Related to #15000 and #14966

Close #15128
This commit is contained in:
Christian Grasser 2024-05-11 23:56:04 +02:00 committed by Don Ho
parent 9d6e6d2e04
commit 973fb36044
5 changed files with 402 additions and 33 deletions

View File

@ -0,0 +1,304 @@
#!/usr/bin/env perl
# pltags - create a tags file for Perl code, for use by vi(m)
#
# Distributed with Vim <http://www.vim.org/>, latest version always available
# at <http://www.mscha.com/mscha.html?pltags#tools>
#
# Version 2.3, 28 February 2002
#
# Written by Michael Schaap <pltags@mscha.com>. Suggestions for improvement
# are very welcome!
#
# This script will not work with Perl 4 or below!
#
# Revision history:
# 1.0 1997? Original version, quickly hacked together
# 2.0 1999? Completely rewritten, better structured and documented,
# support for variables, packages, Exuberant Ctags extensions
# 2.1 Jun 2000 Fixed critical bug (typo in comment) ;-)
# Support multiple level packages (e.g. Archive::Zip::Member)
# 2.2 Jul 2001 'Glob' wildcards - especially useful under Windows
# (thanks to Serge Sivkov and Jason King)
# Bug fix: reset package name for each file
# 2.21 Jul 2001 Oops... bug in variable detection (/local../ -> /^local.../)
# 2.3 Feb 2002 Support variables declared with "our"
# (thanks to Lutz Mende)
# Complain about undeclared variables
use strict;
# Used modules
use Getopt::Long;
# Options with their defaults
my $do_subs = 1; # --subs, --nosubs include subs in tags file?
my $do_vars = 1; # --vars, --novars include variables in tags file?
my $do_pkgs = 1; # --pkgs, --nopkgs include packages in tags file?
my $do_exts = 1; # --extensions, --noextensions
# include Exuberant Ctags extensions
# Global variables
my $VERSION = "2.21"; # pltags version
my $status = 0; # GetOptions return value
my $file = ""; # File being processed
my @tags = (); # List of produced tags
my $is_pkg = 0; # Are we tagging a package?
my $has_subs = 0; # Has this file any subs yet?
my $package_name = ""; # Name of current package
my $var_continues = 0; # Variable declaration continues on last line
my $line = ""; # Current line in file
my $stmt = ""; # Current Perl statement
my @vars = (); # List of variables in declaration
my $var = ""; # Variable in declaration
my $tagline = ""; # Tag file line
# Create a tag file line and push it on the list of found tags
sub MakeTag($$$$$)
{
my ($tag, # Tag name
$type, # Type of tag
$is_static, # Is this a static tag?
$file, # File in which tag appears
$line) = @_; # Line in which tag appears
my $tagline = ""; # Created tag line
# Only process tag if not empty
if ($tag)
{
# Get rid of \n, and escape / and \ in line
chomp $line;
$line =~ s/\\/\\\\/g;
$line =~ s/\//\\\//g;
# Create a tag line
$tagline = "$tag\t$file\t/^$line\$/";
# If we're told to do so, add extensions
if ($do_exts)
{
$tagline .= ";\"\t$type"
. ($is_static ? "\tfile:" : "")
. ($package_name ? "\tclass:$package_name" : "");
}
# Push it on the stack
push (@tags, $tagline);
}
}
# Parse package name from statement
sub PackageName($)
{
my ($stmt) = @_; # Statement
# Look for the argument to "package". Return it if found, else return ""
if ($stmt =~ /^package\s+([\w:]+)/)
{
my $pkgname = $1;
# Remove any parent package name(s)
$pkgname =~ s/.*://;
return $pkgname;
}
else
{
return "";
}
}
# Parse sub name from statement
sub SubName($)
{
my ($stmt) = @_; # Statement
# Look for the argument to "sub". Return it if found, else return ""
if ($stmt =~ /^sub\s+([\w:]+)/)
{
my $subname = $1;
# Remove any parent package name(s)
$subname =~ s/.*://;
return $subname;
}
else
{
return "";
}
}
# Parse all variable names from statement
sub VarNames($)
{
my ($stmt) = @_;
# Remove my or local from statement, if present
$stmt =~ s/^(my|our|local)\s+//;
# Remove any assignment piece
$stmt =~ s/\s*=.*//;
# Now find all variable names, i.e. "words" preceded by $, @ or %
@vars = ($stmt =~ /[\$\@\%]([\w:]+)\b/g);
# Remove any parent package name(s)
map(s/.*://, @vars);
return (@vars);
}
sub functionNoParentheses {
return 1
}
############### Start ###############
print "\npltags $VERSION by Michael Schaap <mscha\@mscha.com>\n\n";
# Get options
$status = GetOptions("subs!" => \$do_subs,
"vars!" => \$do_vars,
"pkgs!" => \$do_pkgs,
"extensions!" => \$do_exts);
# Usage if error in options or no arguments given
unless ($status && @ARGV)
{
print "\n" unless ($status);
print " Usage: $0 [options] filename ...\n\n";
print " Where options can be:\n";
print " --subs (--nosubs) (don't) include sub declarations in tag file\n";
print " --vars (--novars) (don't) include variable declarations in tag file\n";
print " --pkgs (--nopkgs) (don't) include package declarations in tag file\n";
print " --extensions (--noextensions)\n";
print " (don't) include Exuberant Ctags / Vim style\n";
print " extensions in tag file\n\n";
print " Default options: ";
print ($do_subs ? "--subs " : "--nosubs ");
print ($do_vars ? "--vars " : "--novars ");
print ($do_pkgs ? "--pkgs " : "--nopkgs ");
print ($do_exts ? "--extensions\n\n" : "--noextensions\n\n");
print " Example: $0 *.pl *.pm ../shared/*.pm\n\n";
exit;
}
# Loop through files on command line - 'glob' any wildcards, since Windows
# doesn't do this for us
foreach $file (map { glob } @ARGV)
{
# Skip if this is not a file we can open. Also skip tags files and backup
# files
next unless ((-f $file) && (-r $file) && ($file !~ /tags$/)
&& ($file !~ /~$/));
print "Tagging file $file...\n";
$is_pkg = 0;
$package_name = "";
$has_subs = 0;
$var_continues = 0;
open (IN, $file) or die "Can't open file '$file': $!";
# Loop through file
foreach $line (<IN>)
{
# Statement is line with comments and whitespace trimmed
($stmt = $line) =~ s/#.*//;
$stmt =~ s/^\s*//;
$stmt =~ s/\s*$//;
# Nothing left? Never mind.
next unless ($stmt);
# This is a variable declaration if one was started on the previous
# line, or if this line starts with my or local
if ($var_continues or ($stmt =~/^my\b/)
or ($stmt =~/^our\b/) or ($stmt =~/^local\b/))
{
# The declaration continues if the line does not end with ;
$var_continues = ($stmt !~ /;$/);
# Loop through all variable names in the declaration
foreach $var (VarNames($stmt))
{
# Make a tag for this variable unless we're told not to. We
# assume that a variable is always static, unless it appears
# in a package before any sub. (Not necessarily true, but
# it's ok for most purposes and Vim works fine even if it is
# incorrect)
if ($do_vars)
{
MakeTag($var, "v", (!$is_pkg or $has_subs), $file, $line);
}
}
}
# This is a package declaration if the line starts with package
elsif ($stmt =~/^package\b/)
{
# Get name of the package
$package_name = PackageName($stmt);
if ($package_name)
{
# Remember that we're doing a package
$is_pkg = 1;
# Make a tag for this package unless we're told not to. A
# package is never static.
if ($do_pkgs)
{
MakeTag($package_name, "p", 0, $file, $line);
}
}
}
# This is a sub declaration if the line starts with sub
elsif ($stmt =~/^sub\b/)
{
# Remember that this file has subs
$has_subs = 1;
# Make a tag for this sub unless we're told not to. We assume
# that a sub is static, unless it appears in a package. (Not
# necessarily true, but it's ok for most purposes and Vim works
# fine even if it is incorrect)
if ($do_subs)
{
MakeTag(SubName($stmt), "s", (!$is_pkg), $file, $line);
}
}
}
close (IN);
}
# Do we have any tags? If so, write them to the tags file
if (@tags)
{
# Add some tag file extensions if we're told to
if ($do_exts)
{
push (@tags, "!_TAG_FILE_FORMAT\t2\t/extended format/");
push (@tags, "!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted/");
push (@tags, "!_TAG_PROGRAM_AUTHOR\tMichael Schaap\t/mscha\@mscha.com/");
push (@tags, "!_TAG_PROGRAM_NAME\tpltags\t//");
push (@tags, "!_TAG_PROGRAM_VERSION\t$VERSION\t/supports multiple tags and extended format/");
}
print "\nWriting tags file.\n";
open (OUT, ">tags") or die "Can't open tags file: $!";
foreach $tagline (sort @tags)
{
print OUT "$tagline\n";
}
close (OUT);
}
else
{
print "\nNo tags found.\n";
}

View File

@ -0,0 +1 @@
{"leaves":["MakeTag","PackageName","SubName","VarNames","functionNoParentheses"],"root":"unitTest"}

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- ==========================================================================\
|
| To learn how to make your own language parser, please check the following
| link:
| https://npp-user-manual.org/docs/function-list/
|
\=========================================================================== -->
<NotepadPlus>
<functionList>
<!-- ======================================================== [ Raku ] -->
<parser
displayName="Raku"
id ="raku_function"
commentExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`)
(?m-s:\x23.*$) # Single Line Comment
"
>
<function
mainExpr="(?x) # Utilize inline comments (see `RegEx - Pattern Modifiers`)
sub
\s+
[A-Za-z_]\w*
(\s*\([^()]*\))? # prototype or signature
(\s*\:\s*[^{]+)? # attributes
\s*\{ # start of class body
"
>
<functionName>
<nameExpr expr="(?:sub\s+)?\K[A-Za-z_]\w*" />
</functionName>
<className>
<nameExpr expr="[A-Za-z_]\w*(?=\s*:{2})" />
</className>
</function>
</parser>
</functionList>
</NotepadPlus>

View File

@ -17,12 +17,12 @@
SectionGroup "Auto-completion Files" autoCompletionComponent
SetOverwrite off
${MementoSection} "C" C
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\c.xml"
${MementoSectionEnd}
${MementoSection} "C++" C++
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\cpp.xml"
@ -32,27 +32,27 @@ SectionGroup "Auto-completion Files" autoCompletionComponent
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\java.xml"
${MementoSectionEnd}
${MementoSection} "C#" C#
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\cs.xml"
${MementoSectionEnd}
${MementoSection} "HTML" HTML
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\html.xml"
${MementoSectionEnd}
${MementoSection} "RC" RC
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\rc.xml"
${MementoSectionEnd}
${MementoSection} "SQL" SQL
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\sql.xml"
${MementoSectionEnd}
${MementoSection} "PHP" PHP
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\php.xml"
@ -72,7 +72,7 @@ SectionGroup "Auto-completion Files" autoCompletionComponent
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\perl.xml"
${MementoSectionEnd}
${MementoSection} "JavaScript" JavaScript
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\javascript.xml"
@ -82,37 +82,37 @@ SectionGroup "Auto-completion Files" autoCompletionComponent
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\python.xml"
${MementoSectionEnd}
${MementoSection} "ActionScript" ActionScript
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\actionscript.xml"
${MementoSectionEnd}
${MementoSection} "LISP" LISP
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\lisp.xml"
${MementoSectionEnd}
${MementoSection} "VHDL" VHDL
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\vhdl.xml"
${MementoSectionEnd}
${MementoSection} "TeX" TeX
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\tex.xml"
${MementoSectionEnd}
${MementoSection} "DocBook" DocBook
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\xml.xml"
${MementoSectionEnd}
${MementoSection} "NSIS" NSIS
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\nsis.xml"
${MementoSectionEnd}
${MementoSection} "CMAKE" CMAKE
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\cmake.xml"
@ -122,7 +122,7 @@ SectionGroup "Auto-completion Files" autoCompletionComponent
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\batch.xml"
${MementoSectionEnd}
${MementoSection} "CoffeeScript" CoffeeScript
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\coffee.xml"
@ -163,6 +163,15 @@ SectionGroup "Auto-completion Files" autoCompletionComponent
File ".\APIs\gdscript.xml"
${MementoSectionEnd}
${MementoSection} "Go" Go
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\go.xml"
${MementoSectionEnd}
${MementoSection} "Raku" Raku
SetOutPath "$INSTDIR\autoCompletion"
File ".\APIs\raku.xml"
${MementoSectionEnd}
SectionGroupEnd
@ -175,16 +184,16 @@ SectionGroup un.autoCompletionComponent
Section un.CSS
Delete "$INSTDIR\autoCompletion\css.xml"
SectionEnd
SectionEnd
Section un.HTML
Delete "$INSTDIR\autoCompletion\html.xml"
SectionEnd
Section un.SQL
Delete "$INSTDIR\autoCompletion\sql.xml"
SectionEnd
Section un.RC
Delete "$INSTDIR\autoCompletion\rc.xml"
SectionEnd
@ -200,19 +209,19 @@ SectionGroup un.autoCompletionComponent
Section un.C
Delete "$INSTDIR\autoCompletion\c.xml"
SectionEnd
Section un.C++
Delete "$INSTDIR\autoCompletion\cpp.xml"
SectionEnd
Section un.Java
Delete "$INSTDIR\autoCompletion\java.xml"
SectionEnd
Section un.C#
Delete "$INSTDIR\autoCompletion\cs.xml"
SectionEnd
Section un.JavaScript
Delete "$INSTDIR\autoCompletion\javascript.xml"
SectionEnd
@ -224,27 +233,27 @@ SectionGroup un.autoCompletionComponent
Section un.ActionScript
Delete "$INSTDIR\autoCompletion\actionscript.xml"
SectionEnd
Section un.LISP
Delete "$INSTDIR\autoCompletion\lisp.xml"
SectionEnd
Section un.VHDL
Delete "$INSTDIR\autoCompletion\vhdl.xml"
SectionEnd
SectionEnd
Section un.TeX
Delete "$INSTDIR\autoCompletion\tex.xml"
SectionEnd
Section un.DocBook
Delete "$INSTDIR\autoCompletion\xml.xml"
SectionEnd
Section un.NSIS
Delete "$INSTDIR\autoCompletion\nsis.xml"
SectionEnd
Section un.CMAKE
Delete "$INSTDIR\autoCompletion\cmake.xml"
SectionEnd
@ -252,7 +261,7 @@ SectionGroup un.autoCompletionComponent
Section un.BATCH
Delete "$INSTDIR\autoCompletion\batch.xml"
SectionEnd
Section un.CoffeeScript
Delete "$INSTDIR\autoCompletion\coffee.xml"
SectionEnd
@ -285,5 +294,12 @@ SectionGroup un.autoCompletionComponent
Delete "$INSTDIR\autoCompletion\gdscript.xml"
SectionEnd
Section un.Go
Delete "$INSTDIR\autoCompletion\go.xml"
SectionEnd
Section un.Raku
Delete "$INSTDIR\autoCompletion\raku.xml"
SectionEnd
SectionGroupEnd

View File

@ -193,6 +193,11 @@ SectionGroup "Function List Files" functionListComponent
File ".\functionList\gdscript.xml"
${MementoSectionEnd}
${MementoSection} "Raku" Raku_FL
SetOutPath "$INSTDIR\functionList"
File ".\functionList\raku.xml"
${MementoSectionEnd}
${MementoSection} "Hollywood" Hollywood_FL
SetOutPath "$INSTDIR\functionList"
File ".\functionList\hollywood.xml"
@ -356,7 +361,11 @@ SectionGroup un.functionListComponent
Section un.GDScript_FL
Delete "$INSTDIR\functionList\gdscript.xml"
SectionEnd
Section un.Raku_FL
Delete "$INSTDIR\functionList\raku.xml"
SectionEnd
Section un.Hollywood_FL
Delete "$INSTDIR\functionList\hollywood.xml"
SectionEnd