Skip to content

Commit

Permalink
Docgen updates
Browse files Browse the repository at this point in the history
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 b20d870
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 66 deletions.
Binary file modified persistence.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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, "|");
}
Expand Down
56 changes: 29 additions & 27 deletions src/main/java/com/laytonsmith/tools/SyntaxHighlighters.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/laytonsmith/tools/docgen/DocGenTemplates.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() + "]";
}
};
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
41 changes: 21 additions & 20 deletions src/main/resources/docs/Beginner's_Guide
Original file line number Diff line number Diff line change
Expand Up @@ -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...
%%

Expand All @@ -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
Expand All @@ -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
%%

Expand All @@ -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
Expand All @@ -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');
%%

Expand 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
<<<
Expand All @@ -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
%%

Expand All @@ -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');
Expand All @@ -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);
%%

Expand All @@ -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);
%%

Expand All @@ -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');
%%

Expand All @@ -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'){
Expand All @@ -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.
<<<
Expand All @@ -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
%%
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/docs/Developer_Guide
Original file line number Diff line number Diff line change
Expand Up @@ -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} ====
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/docs/SyntaxHighlighting
Original file line number Diff line number Diff line change
Expand Up @@ -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.)

Loading

0 comments on commit b20d870

Please sign in to comment.