Permalink
Browse files

Docgen updates

Also fixed a bug in FullyQualifiedClassName that affected vim syntax highlighter
generation, and added unit tests for that.
  • Loading branch information...
LadyCailin committed Dec 19, 2018
1 parent cb84d45 commit b20d87081332d4ec9fa02d7092353d7f5067e186
BIN +188 KB (250%) persistence.db
Binary file not shown.
@@ -111,9 +111,13 @@ public boolean isTypeUnion() {

public String getSimpleName() {
List<String> parts = new ArrayList<>();
for(String t : fullyQualifiedName.split("|")) {
for(String t : fullyQualifiedName.split("\\|")) {
String[] sparts = t.split(Pattern.quote(PATH_SEPARATOR));
parts.add(sparts[sparts.length - 1]);
try {
parts.add(sparts[sparts.length - 1]);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ArrayIndexOutOfBoundsException("Could not properly get simple name for " + fullyQualifiedName);
}
}
return StringUtils.Join(parts, "|");
}
@@ -30,6 +30,34 @@

public class SyntaxHighlighters {

public static final String HELP_TEXT = "File for the following syntax highlighters are currently available:\n"
+ "\tNotepad++ - Use type \"npp\". You may also select a theme, either \"default\" or \"obsidian\"\n"
+ "\tTextWrangler - Use type \"textwrangler\". Only the default theme is available.\n"
+ "\t\tTo install: put the generated file in ~/Library/Application Support/TextWrangler/Language Modules/\n"
+ "\t\tNote that this output file can also be used for BBEdit.\n"
+ "\tGeSHi - Use type \"geshi\". Only the default theme is available.\n"
+ "\tViM - Use type \"vim\". Only the default theme is available.\n"
+ "\t\tTo install: put in ~/.vim/syntax/commandhelper.vim then edit\n"
+ "\t\t~/.vim/ftdetect/commandhelper.vim and add the line \n"
+ "\t\tau BufRead,BufNewFile *.ms set filetype=commandhelper\n"
+ "\t\tThen, if you're on linux and use cmdline mode, in ~/.vim/scripts.vim, add the following lines:\n"
+ "\t\t\tif did_filetype()\n"
+ "\t\t\t\tfinish\n"
+ "\t\t\tendif\n"
+ "\t\t\tif getline(1) =~# '^#!.*\\(/bin/env\\s\\+mscript\\|/bin/mscript\\)\\>'\n"
+ "\t\t\t\tsetfiletype commandhelper\n"
+ "\t\t\tendif"
+ "\t\t(Create directories and files as needed)\n"
+ "\tnano - Use type \"nano\". Only the default theme is available.\n"
+ "\tSublime Text - Use type \"sublime\". Only the default theme is available.\n"
+ "\t\tTo install: Place in Sublime Text's ./SublimeText/data/Packages/User folder.\n"
+ "\tSublime Text 3 - Use type \"sublime3\".\n"
+ "\tAtom - Use type \"atom\". Only the default theme is available.\n"
+ "\t\tTo install: Install package language-mscript from the Atom package manager."
+ "\n\n"
+ "Know how to write a syntax highlighter file for your favorite text editor? Let me know, and we\n"
+ "can work to get it included in CommandHelper!";

public static String generate(String type, String theme) {
Implementation.forceServerType(Implementation.Type.BUKKIT);
if("npp".equals(type) || "notepad++".equals(type)) {
@@ -70,33 +98,7 @@ public static String generate(String type, String theme) {
return template("/syntax-templates/sublime3/default.sublime-syntax");
}

return "File for the following syntax highlighters are currently available:\n"
+ "\tNotepad++ - Use type \"npp\". You may also select a theme, either \"default\" or \"obsidian\"\n"
+ "\tTextWrangler - Use type \"textwrangler\". Only the default theme is available.\n"
+ "\t\tTo install: put the generated file in ~/Library/Application Support/TextWrangler/Language Modules/\n"
+ "\t\tNote that this output file can also be used for BBEdit.\n"
+ "\tGeSHi - Use type \"geshi\". Only the default theme is available.\n"
+ "\tViM - Use type \"vim\". Only the default theme is available.\n"
+ "\t\tTo install: put in ~/.vim/syntax/commandhelper.vim then edit\n"
+ "\t\t~/.vim/ftdetect/commandhelper.vim and add the line \n"
+ "\t\tau BufRead,BufNewFile *.ms set filetype=commandhelper\n"
+ "\t\tThen, if you're on linux and use cmdline mode, in ~/.vim/scripts.vim, add the following lines:\n"
+ "\t\t\tif did_filetype()\n"
+ "\t\t\t\tfinish\n"
+ "\t\t\tendif\n"
+ "\t\t\tif getline(1) =~# '^#!.*\\(/bin/env\\s\\+mscript\\|/bin/mscript\\)\\>'\n"
+ "\t\t\t\tsetfiletype commandhelper\n"
+ "\t\t\tendif"
+ "\t\t(Create directories and files as needed)\n"
+ "\tnano - Use type \"nano\". Only the default theme is available.\n"
+ "\tSublime Text - Use type \"sublime\". Only the default theme is available.\n"
+ "\t\tTo install: Place in Sublime Text's ./SublimeText/data/Packages/User folder.\n"
+ "\tSublime Text 3 - Use type \"sublime3\".\n"
+ "\tAtom - Use type \"atom\". Only the default theme is available.\n"
+ "\t\tTo install: Install package language-mscript from the Atom package manager."
+ "\n\n"
+ "Know how to write a syntax highlighter file for your favorite text editor? Let me know, and we\n"
+ "can work to get it included in CommandHelper!";
return HELP_TEXT;
}

/**
@@ -2,6 +2,7 @@

import com.laytonsmith.PureUtilities.ArgumentParser;
import com.laytonsmith.PureUtilities.ClassLoading.ClassDiscovery;
import com.laytonsmith.PureUtilities.ClassLoading.ClassMirror.ClassMirror;
import com.laytonsmith.PureUtilities.Common.ArrayUtils;
import com.laytonsmith.PureUtilities.Common.HTMLUtils;
import com.laytonsmith.PureUtilities.Common.ReflectionUtils;
@@ -12,6 +13,7 @@
import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.annotations.datasource;
import com.laytonsmith.annotations.typeof;
import com.laytonsmith.core.MSVersion;
import com.laytonsmith.core.Main;
import com.laytonsmith.core.Optimizable;
import com.laytonsmith.core.Prefs;
@@ -453,7 +455,11 @@ public String generate(String... args) {

@Override
public String generate(String... args) {
Class c = ClassDiscovery.getDefaultInstance().forFuzzyName(args[0], args[1]).loadClass();
ClassMirror m = ClassDiscovery.getDefaultInstance().forFuzzyName(args[0], args[1]);
if(m == null) {
throw new NullPointerException("Could not find class " + args[0] + " " + args[1]);
}
Class c = m.loadClass();
return "[" + GITHUB_BASE_URL + "/" + c.getName().replace('.', '/') + ".java " + c.getSimpleName() + "]";
}
};
@@ -770,6 +776,8 @@ public String generate(String... args) throws GenerateException {
}
};

public static final Generator CURRENT_VERSION = (String... args) -> MSVersion.LATEST.toString();

/**
* Returns the standard {{unimplemented}} template
*/
@@ -927,7 +927,8 @@ public String generate(String... args) {
g.put("bodyEscaped", new Generator() {
@Override
public String generate(String... args) {
String s = b.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'").replaceAll("\r?\n", "\\\\n");
String s = b.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'")
.replaceAll("\r", "").replaceAll("\n", "\\\\n");
s = s.replaceAll("<script.*?</script>", "");
return s;
}
@@ -1378,7 +1379,7 @@ private void generateFunctionDocs(Function f, DocGen.DocInfo docs) {
+ " (Note this page is automatically generated from the documentation in the source code.)</p>";
page.append(bW);
String description = "";
writePage(f.getName(), page.toString(), "API/functions/" + f.getName(), Arrays.asList(new String[]{f.getName(),
writePage(f.getName(), page.toString(), "API/functions/" + f.getName() + ".html", Arrays.asList(new String[]{f.getName(),
f.getName() + " api", f.getName() + " example", f.getName() + " description"}), description);
}

@@ -5,11 +5,11 @@ for the master alias file, but in general will work for LocalPackages as well.
===General===

In general, an alias is specified as such:
%%CODE|
%%ALIAS|
/alias_command = /real_command
%%
and macros are specified as such:
%%CODE|
%%ALIAS|
/alias_command = /real1 \ /real2 \ /real3 \ etc...
%%

@@ -18,7 +18,7 @@ each other. The exception to this rule is that when using macros, each macro can
the previous line ends in a backslash. (Another exception is when you use the "multiline construct", which is covered
below.) Global aliases go in the aliases.msa file, located at the root of the CommandHelper folder, and everybody can
use them.
%%CODE|
%%ALIAS|
/alias_command = /real1 \
/real2 \
/real3
@@ -29,13 +29,13 @@ each other, so things like variable declarations and such won't carry over from
script, consider using multiline scripts and the {{function|run}} function. In general, you should use the best practice
method of writing scripts, even for simple scripts:

%%CODE|
%%ALIAS|
/alias = run('/real_command');
%%

This corresponds to the same simple script:

%%CODE|
%%ALIAS|
/alias = /real_command
%%

@@ -44,8 +44,8 @@ however, the less verbose method is acceptable. The rest of the examples in the
will generally conform to the best practice method.

In the config file, lines that begin with a <code>#</code> or <code>//</code> are comments, and are ignored by the
compiler. This is useful for
commenting complex scripts, to show what exactly they do. When the plugin starts, it attempts to compile all the
compiler. This is useful for commenting complex scripts, and being able to add freeform text within the code
to show what exactly they do. When the plugin starts, it attempts to compile all the
scripts. If the compilation fails, it will try to give you a useful error message to let you know where the error was in
your script. Commands on the right side must be commands that the player could have simply typed in themselves.
CommandHelper does no permission checking at all before running commands using run(), but simply runs commands as that
@@ -59,7 +59,7 @@ which will give you a line number and file to look at, and see what it is that y

A simple alias maps one command to another. For example, in the vanilla server, there is the command /save-all,
which for brevity sake, we may want to shorten to /save. The alias for this command would be:
%%CODE|
%%ALIAS|
/save = run('/save-all');
%%

@@ -70,7 +70,7 @@ symbol would cause a compile error otherwise.

Since complex alias scripts would be hard to read if they were only on one line, the multiline construct allows you to
put as many newlines in the middle of your alias definition as you want. To use the multiline construct, use the following syntax:
%%CODE|
%%ALIAS|
/cmd = >>>
#As many newlines as you want
<<<
@@ -94,11 +94,12 @@ compile time, but since these symbols are part of the lexer, they cannot be used

===Macros===

{{TakeNote|text=Macros are not recommended for use, see below for alternate syntax to do the same thing, see below}}
{{TakeNote|text=Macros are not recommended for use, as they become difficult to read if the command becomes more than,
just a few lines. See below for alternate syntax to do the same thing with a more programmatic approach.}}

Macros allow you to run several commands with only having typed in one command. One common use may be to create "kits"
for players to use, which spawn several items at once. Here is an example for that:
%%CODE|
%%ALIAS|
/kit gold = /give player() 284 64 \ /give player() 285 64 \ /give player() 286 64
%%

@@ -112,7 +113,7 @@ is fairly simple; all it does is give you the name of the player issuing the com
In general, macros are not recommended for use. Instead, use the multiline construct and multiple <code>run()</code>
calls. The same code from above can be written as such (using full strict syntax with operators):

%%CODE|
%%ALIAS|
/kit gold = >>>
run('/give '.player().' 284 64');
run('/give '.player().' 285 64');
@@ -127,7 +128,7 @@ The advantage of this is that the code is easier to read, and details like varia
Sometimes we want to use the input provided by the user to put into our aliased command. For instance, if we wanted to
shorten a /give command, we could do this:

%%CODE|
%%ALIAS|
/i $data $qty = run('/give' player() $data $qty);
%%

@@ -136,7 +137,7 @@ would be assigned 64. Note that all variables start with a dollar sign ($).

What if we want to provide a default value for a variable? We can do that too. Suppose the player by default would
want 64 of an item. We can do that with the following syntax:
%%CODE|
%%ALIAS|
/i $data [$qty=64] = run('/give' player() $data $qty);
%%

@@ -148,7 +149,7 @@ Only static values can be assigned as default. Function calls or other dynamic c
(with or without special symbols) may be assigned using <code>[$var='the-string']</code>. If literal portions of the alias
have special symbols in them, they may also be quoted, for instance:

%%CODE|
%%ALIAS|
'//alias-with-special-characters' = run('/command');
%%

@@ -157,7 +158,7 @@ have special symbols in them, they may also be quoted, for instance:
Final variables allow you to specify a variable number of arguments be assigned to one variable. There is a special
variable defined for this purpose, "$". This is particularly useful for writing some sort of message alias. Say we want
to create an alias for /tell.
%%CODE|
%%ALIAS|
/msg $player $ = >>>
// Only allow the player 'player' to receive messages
if($player == 'player'){
@@ -170,14 +171,14 @@ Note that a user's command is parsed into sections based on spaces but any argum
variables will be put in the final variable. Another common approach is to trigger an alias based on the first command
verb, and ignore the rest of the arguments, whether or not they provided them.

%%CODE|
%%ALIAS|
/command [$] = msg('Runs this command no matter what extra parameters were sent in');
%%

Another common use is to accept the entirety of the user's command into the $ var, and use the {{function|parse_args}}
function to use a more "standard" command line type argument.

%%CODE|
%%ALIAS|
/command [$] = >>>
@array = parse_args($); // Now the arguments will be separated into various parameters.
<<<
@@ -200,13 +201,13 @@ For a command to "match" an alias, the following factors are taken into consider
Non-optional variables must be present, but can be anything. Optional variables may be present, but extra arguments will
make the match fail. (Except in the case of a final variable being present.) Let's look at the following two command
signatures:
%%CODE|
%%ALIAS|
/cmd $var1 [$var2]
/cmd $var1 $var2
%%

Both of these signatures are ambiguous, because the command "/cmd one two" would match both signatures.
%%CODE|
%%ALIAS|
/cmd $var1
/cmd $var1 $var2
%%
@@ -114,7 +114,7 @@ many of these annotations, and where possible, will provide the same functionali
to be caught more quickly.

The annotations that are supported by either the compiler or runtime are listed below, but all of them must implement
%%GET_SIMPLE_CLASS|.*compiler|CompilerAwareAnnotation%% to be valid parameter annotations. Each annotation has it's own
GET_SIMPLE_CLASS|.*compiler|CompilerAwareAnnotation to be valid parameter annotations. Each annotation has it's own
documentation in the normal API.

==== @{NonNull} ====
@@ -12,5 +12,6 @@ This will print out the syntax file to the console. You can pipe the output to a

<code>java -jar CommandHelper.jar syntax npp obsidian > syntaxFile.xml</code>

This will save the file in the current directory. Follow the procedure for your specific text editor to update the syntax files using the freshly generated syntax file. (This varies depending on your text editor.)
This will save the file in the current directory. Follow the procedure for your specific text editor to update the
syntax files using the freshly generated syntax file. (This varies depending on your text editor.)

Oops, something went wrong.

0 comments on commit b20d870

Please sign in to comment.