|
61 | 61 | * supported: |
62 | 62 | * </p> |
63 | 63 | * <ul> |
64 | | - * <li>{@code // @<type> <varName>}</li> |
65 | | - * <li>{@code // @<type>(<attr1>=<value1>, ..., <attrN>=<valueN>) <varName>} |
66 | | - * </li> |
67 | | - * <li>{@code // @<IOType> <type> <varName>}</li> |
68 | | - * <li>{@code // @<IOType>(<attr1>=<value1>, ..., <attrN>=<valueN>) <type> |
| 64 | + * <li>{@code #@<type> <varName>}</li> |
| 65 | + * <li>{@code #@<type>(<attr1>=<value1>, ..., <attrN>=<valueN>) <varName>}</li> |
| 66 | + * <li>{@code #@<IOType> <type> <varName>}</li> |
| 67 | + * <li>{@code #@<IOType>(<attr1>=<value1>, ..., <attrN>=<valueN>) <type> |
69 | 68 | * <varName>}</li> |
70 | 69 | * </ul> |
71 | 70 | * <p> |
72 | 71 | * Where: |
73 | 72 | * </p> |
74 | 73 | * <ul> |
75 | | - * <li>{@code //} = the comment style of the scripting language, so that the |
| 74 | + * <li>{@code #@} - signals a special script processing instruction, so that the |
76 | 75 | * parameter line is ignored by the script engine itself.</li> |
77 | | - * <li>{@code <IOType>} = one of {@code INPUT}, {@code OUTPUT}, or {@code BOTH}. |
| 76 | + * <li>{@code <IOType>} - one of {@code INPUT}, {@code OUTPUT}, or {@code BOTH}. |
78 | 77 | * </li> |
79 | | - * <li>{@code <varName>} = the name of the input or output variable.</li> |
80 | | - * <li>{@code <type>} = the Java {@link Class} of the variable.</li> |
81 | | - * <li>{@code <attr*>} = an attribute key.</li> |
82 | | - * <li>{@code <value*>} = an attribute value.</li> |
| 78 | + * <li>{@code <varName>} - the name of the input or output variable.</li> |
| 79 | + * <li>{@code <type>} - the Java {@link Class} of the variable.</li> |
| 80 | + * <li>{@code <attr*>} - an attribute key.</li> |
| 81 | + * <li>{@code <value*>} - an attribute value.</li> |
83 | 82 | * </ul> |
84 | 83 | * <p> |
85 | 84 | * See the @{@link Parameter} annotation for a list of valid attributes. |
|
88 | 87 | * Here are a few examples: |
89 | 88 | * </p> |
90 | 89 | * <ul> |
91 | | - * <li>{@code // @Dataset dataset}</li> |
92 | | - * <li>{@code // @double(type=OUTPUT) result}</li> |
93 | | - * <li>{@code // @BOTH ImageDisplay display}</li> |
94 | | - * <li>{@code // @INPUT(persist=false, visibility=INVISIBLE) boolean verbose} |
| 90 | + * <li>{@code #@Dataset dataset}</li> |
| 91 | + * <li>{@code #@double(type=OUTPUT) result}</li> |
| 92 | + * <li>{@code #@BOTH ImageDisplay display}</li> |
| 93 | + * <li>{@code #@INPUT(persist=false, visibility=INVISIBLE) boolean verbose} |
95 | 94 | * </li> |
96 | 95 | * </ul> |
97 | 96 | * <p> |
@@ -129,6 +128,14 @@ public void begin(final ScriptInfo scriptInfo) { |
129 | 128 |
|
130 | 129 | @Override |
131 | 130 | public void process(final String line) { |
| 131 | + // parse new-style parameters starting with @# anywhere in the script. |
| 132 | + if (line.matches("^#@.*")) { |
| 133 | + final int at = line.indexOf('@'); |
| 134 | + parseParam(line.substring(at + 1)); |
| 135 | + return; |
| 136 | + } |
| 137 | + |
| 138 | + // parse old-style parameters in the initial script header |
132 | 139 | if (header) { |
133 | 140 | // NB: Check if line contains an '@' with no prior alphameric |
134 | 141 | // characters. This assumes that only non-alphanumeric characters can |
@@ -170,10 +177,11 @@ private void parseParam(final String param, final Map<String, Object> attrs) { |
170 | 177 | final String[] tokens = param.trim().split("[ \t\n]+"); |
171 | 178 | if (tokens.length < 1) { warnInvalid(param); return; } |
172 | 179 | final String typeName, varName; |
173 | | - if (isIOType(tokens[0])) { |
| 180 | + final String maybeIOType = tokens[0].toUpperCase(); |
| 181 | + if (isIOType(maybeIOType)) { |
174 | 182 | // assume syntax: <IOType> <type> <varName> |
175 | 183 | if (tokens.length < 3) { warnInvalid(param); return; } |
176 | | - attrs.put("type", tokens[0]); |
| 184 | + attrs.put("type", maybeIOType); |
177 | 185 | typeName = tokens[1]; |
178 | 186 | varName = tokens[2]; |
179 | 187 | } |
@@ -205,7 +213,7 @@ private Map<String, Object> parseAttrs(final String attrs) { |
205 | 213 | } |
206 | 214 |
|
207 | 215 | private boolean isIOType(final String token) { |
208 | | - return convertService.convert(token, ItemIO.class) != null; |
| 216 | + return convertService.convert(token.toUpperCase(), ItemIO.class) != null; |
209 | 217 | } |
210 | 218 |
|
211 | 219 | private void warnInvalid(final String param) { |
|
0 commit comments