20 package net.sf.gridarta.textedit.textarea.tokenmarker;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.Iterator;
27 import java.util.regex.Pattern;
28 import javax.swing.text.Segment;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
44 private static final Map<String, Spec>
FIXED_SPECS =
new HashMap<>();
50 private static final Map<Pattern, Spec>
REGEX_SPECS =
new HashMap<>();
59 FIXED_SPECS.put(
"friendship",
new Spec(
Token.
KEYWORD1,
new Parameter(
"group",
Token.
KEYWORD2,
ParameterType.
STRING_INTEGER),
new Parameter(
"name",
Token.
KEYWORD2,
ParameterType.
STRING_INTEGER),
new Parameter(
"player",
Token.
KEYWORD2,
ParameterType.
INTEGER),
new Parameter(
"race",
Token.
KEYWORD2,
ParameterType.
STRING_INTEGER)));
79 final char[] array = line.array;
80 int offset = line.offset;
81 final int end = line.count + offset;
84 }
else if (array[offset] ==
'#') {
87 }
else if (array[offset] ==
' ') {
97 final Collection<Integer> segments =
new ArrayList<>();
99 while (offset < end) {
100 final int commandStart = offset;
101 while (offset < end && array[offset] !=
' ') {
104 segments.add(offset - commandStart);
106 final int spacesStart = offset;
107 while (offset < end && array[offset] ==
' ') {
110 segments.add(offset - spacesStart);
114 final Iterator<Integer> it = segments.iterator();
115 int offset2 = line.offset;
117 final int commandLength = it.next();
118 final String command =
new String(array, offset2, commandLength);
121 offset2 += commandLength;
123 final int spacesLength1 = it.next();
125 offset2 += spacesLength1;
127 while (it.hasNext()) {
128 final int parameterLength = it.next();
130 if (tmp.length == 2) {
131 final String parameterString = tmp[0];
132 final String valueString = tmp[1];
135 final boolean parameterValid = parameter != null;
144 offset2 += parameterLength;
146 final int spacesLength2 = it.next();
148 offset2 += spacesLength2;
163 final Spec fixedSpec = FIXED_SPECS.get(command);
164 if (fixedSpec != null) {
168 for (
final Map.Entry<Pattern,
Spec> entry : REGEX_SPECS.entrySet()) {
169 if (entry.getKey().matcher(command).matches()) {
170 return entry.getValue();
static final Map< Pattern, Spec > REGEX_SPECS
Commands having variable command names.
ParameterType getParameterType()
Returns the parameter type for the value of this parameter.
byte getId()
Returns the token id used to highlight this command.
Utility class for string manipulation.
static final Pattern PATTERN_EQUAL
The pattern that matches a single equal sign ("=").
static final byte COMMENT1
Comment 1 token id.
void addToken(final int length, final byte id)
Adds a token to the token list.
Pattern getPattern()
Returns the pattern matching valid parameter values.
byte getId()
Returns the token id used to highlight the parameter name.
Base package of all Gridarta classes.
Parameter getParameter(final String name)
Returns the parameter specification for a parameter name.
Describes a parameter type.
static final byte OPERATOR
Operator token id.
This package contains the other part of the script editor.
A TokenMarker for the message field of Daimonin AI objects.
static final byte NULL
Normal text token id.
static final byte KEYWORD2
Keyword 2 token id.
INTEGER
Integer parameter.
A token marker that splits lines of text into tokens.
static final byte KEYWORD1
Keyword 1 token id.
byte markTokensImpl(final byte token, @NotNull final Segment line)
static final byte INVALID
Invalid token id.
Describes a command (excluding the command name).
static final byte LABEL
Label token id.
static Spec getSpec(@NotNull final String command)
Returns the command specification from a command name.
STRING_INTEGER
String/Integer list parameter.
static final Map< String, Spec > FIXED_SPECS
Commands having a fixed command name.