Skip to content

Commit a821e2b

Browse files
committed
Draft structure of doc generation #37
Signed-off-by: Mārtiņš Avots <martins.avots@splitcells.net>
1 parent 30a01bc commit a821e2b

6 files changed

Lines changed: 109 additions & 2 deletions

File tree

projects/net.splitcells.gel.editor/src/main/java/net/splitcells/gel/editor/Editor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,8 @@ public Editor addRecord(FunctionCallRecord argRecord) {
281281
public FunctionCallRecord functionCallRecord(Optional<Object> subject, FunctionCallDesc functionCall, String name, int variation) {
282282
return FunctionCallRecord.functionCallRecord(subject, functionCall, this, name, variation);
283283
}
284+
285+
public FunctionCallRecord functionCallRecord(Optional<Object> subject, FunctionCallDesc functionCall, String name, int variation, boolean isRecording) {
286+
return FunctionCallRecord.functionCallRecord(subject, functionCall, this, name, variation, isRecording);
287+
}
284288
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2021 Contributors To The `net.splitcells.*` Projects
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the Eclipse
10+
* Public License, v. 2.0 are satisfied: GNU General Public License v2.0 or later
11+
* which is available at https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12+
*
13+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
14+
* SPDX-FileCopyrightText: Contributors To The `net.splitcells.*` Projects
15+
*/
16+
package net.splitcells.gel.editor.geal;
17+
18+
import lombok.val;
19+
import net.splitcells.dem.lang.tree.Tree;
20+
import net.splitcells.dem.object.Discoverable;
21+
22+
import static net.splitcells.dem.lang.tree.TreeI.tree;
23+
import static net.splitcells.gel.editor.Editor.editor;
24+
import static net.splitcells.gel.editor.geal.runners.FunctionCallMetaExecutor.functionCallMetaExecutor;
25+
26+
public class FunctionCallDoc {
27+
private FunctionCallDoc() {
28+
29+
}
30+
31+
public static Tree generateDoc() {
32+
val editor = editor("Documentation Generation", Discoverable.EXPLICIT_NO_CONTEXT);
33+
val subject = functionCallMetaExecutor();
34+
val doc = tree("Geal Function Call Documentation");
35+
subject.parsers().forEach(p -> {
36+
System.out.println(p.document(editor));
37+
});
38+
return doc;
39+
}
40+
}

projects/net.splitcells.gel.editor/src/main/java/net/splitcells/gel/editor/geal/FunctionCallRecord.java

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@
5151
@Accessors(chain = true)
5252
public class FunctionCallRecord implements Closeable {
5353
public static FunctionCallRecord functionCallRecord(Optional<Object> argSubject, FunctionCallDesc argFunctionCall, Editor argContext, String argName, int argVariation) {
54-
return new FunctionCallRecord(argSubject, argFunctionCall, argContext, argName, argVariation);
54+
return new FunctionCallRecord(argSubject, argFunctionCall, argContext, argName, argVariation, false);
55+
}
56+
57+
public static FunctionCallRecord functionCallRecord(Optional<Object> argSubject, FunctionCallDesc argFunctionCall, Editor argContext, String argName, int argVariation, boolean argIsRecording) {
58+
return new FunctionCallRecord(argSubject, argFunctionCall, argContext, argName, argVariation, argIsRecording);
5559
}
5660

5761
@Getter private final String name;
@@ -68,13 +72,15 @@ public static FunctionCallRecord functionCallRecord(Optional<Object> argSubject,
6872
private final Editor context;
6973
private final FunctionCallDesc functionCall;
7074
private final Optional<Object> subject;
75+
boolean isRecording;
7176

72-
private FunctionCallRecord(Optional<Object> argSubject, FunctionCallDesc argFunctionCall, Editor argContext, String argName, int argVariation) {
77+
private FunctionCallRecord(Optional<Object> argSubject, FunctionCallDesc argFunctionCall, Editor argContext, String argName, int argVariation, boolean argIsRecording) {
7378
name = argName;
7479
variation = argVariation;
7580
context = argContext;
7681
functionCall = argFunctionCall;
7782
subject = argSubject;
83+
isRecording = argIsRecording;
7884
}
7985

8086
public FunctionCallRecord addDescription(String addition) {
@@ -83,6 +89,9 @@ public FunctionCallRecord addDescription(String addition) {
8389
}
8490

8591
public void requireArgumentCount(int requiredArgumentCount) {
92+
if (isRecording) {
93+
return;
94+
}
8695
if (functionCall.getArguments().size() != requiredArgumentCount) {
8796
throw execException(tree("The "
8897
+ name
@@ -96,6 +105,9 @@ public void requireArgumentCount(int requiredArgumentCount) {
96105
}
97106

98107
public void requireArgumentMinimalCount(int requiredMinimum) {
108+
if (isRecording) {
109+
return;
110+
}
99111
if (functionCall.getArguments().size() < requiredMinimum) {
100112
throw execException(tree("The "
101113
+ name
@@ -108,6 +120,9 @@ public void requireArgumentMinimalCount(int requiredMinimum) {
108120
}
109121

110122
public NameDesc parseArgumentAsType(int argument, String... validValues) {
123+
if (isRecording) {
124+
return null;
125+
}
111126
val argumentAsType = parseArgumentAsType(argument);
112127
val validValueList = listWithValuesOf(validValues);
113128
val anyMatch = validValueList.stream().anyMatch(v -> v.equals(argumentAsType.getValue()));
@@ -120,6 +135,9 @@ public NameDesc parseArgumentAsType(int argument, String... validValues) {
120135
}
121136

122137
public NameDesc parseArgumentAsType(int argument) {
138+
if (isRecording) {
139+
return null;
140+
}
123141
final var first = context.parse(functionCall.getArguments().get(argument));
124142
switch (first) {
125143
case Type n -> {
@@ -137,6 +155,9 @@ public NameDesc parseArgumentAsType(int argument) {
137155
}
138156

139157
public StringDesc parseArgumentAsStringDesc(int argument) {
158+
if (isRecording) {
159+
return null;
160+
}
140161
final var first = context.parse(functionCall.getArguments().get(argument));
141162
switch (first) {
142163
case String n -> {
@@ -154,6 +175,9 @@ public StringDesc parseArgumentAsStringDesc(int argument) {
154175
}
155176

156177
public void failBecauseOfInvalidType(int argument, NameDesc actualType, String... allowedTypes) {
178+
if (isRecording) {
179+
return;
180+
}
157181
final var allowedTypeList = Lists.list(allowedTypes).stream()
158182
.map(at -> "the " + at + " type")
159183
.reduce((a, b) -> a + " or " + b)
@@ -167,6 +191,9 @@ public void failBecauseOfInvalidType(int argument, NameDesc actualType, String..
167191
}
168192

169193
public Query parseQuerySubject() {
194+
if (isRecording) {
195+
return null;
196+
}
170197
if (subject.isEmpty()) {
171198
throw execException(tree("The "
172199
+ name
@@ -195,6 +222,9 @@ public Query parseQuerySubject() {
195222
}
196223

197224
public <T> T parseSubject(Class<? extends T> type) {
225+
if (isRecording) {
226+
return null;
227+
}
198228
if (subject.isEmpty()) {
199229
throw execException(tree("The function " + name + " requires a "
200230
+ type.getName()
@@ -213,16 +243,25 @@ public <T> T parseSubject(Class<? extends T> type) {
213243
}
214244

215245
public List<Attribute<? extends Object>> parseAttributeArguments(int from) {
246+
if (isRecording) {
247+
return null;
248+
}
216249
return functionCall.getArguments().streamIndexes()
217250
.filter(i -> i >= from)
218251
.mapToObj(this::parseAttributeArgument).collect(toList());
219252
}
220253

221254
public List<Attribute<? extends Object>> parseAttributeArguments() {
255+
if (isRecording) {
256+
return null;
257+
}
222258
return functionCall.getArguments().streamIndexes().mapToObj(this::parseAttributeArgument).collect(toList());
223259
}
224260

225261
public Attribute<? extends Object> parseAttributeArgument(int argument) {
262+
if (isRecording) {
263+
return null;
264+
}
226265
final var a = functionCall.getArguments().get(argument);
227266
final var parsed = context.parse(a);
228267
switch (parsed) {
@@ -241,6 +280,9 @@ public Attribute<? extends Object> parseAttributeArgument(int argument) {
241280
}
242281

243282
public <T> Attribute<T> parseAttributeArgument(Class<? extends T> type, int argument) {
283+
if (isRecording) {
284+
return null;
285+
}
244286
final Attribute<?> distanceAttribute = parseAttributeArgument(argument);
245287
if (!type.isAssignableFrom(distanceAttribute.type())) {
246288
throw execException(tree("The argument "
@@ -258,6 +300,9 @@ public <T> Attribute<T> parseAttributeArgument(Class<? extends T> type, int argu
258300
}
259301

260302
public <T> T parseArgument(Class<? extends T> type, int argument) {
303+
if (isRecording) {
304+
return null;
305+
}
261306
final var parsed = context.parse(functionCall.getArguments().get(argument));
262307
if (type.isInstance(parsed)) {
263308
return (T) parsed;
@@ -275,6 +320,9 @@ public <T> T parseArgument(Class<? extends T> type, int argument) {
275320
}
276321

277322
public void requireSubjectAbsence() {
323+
if (isRecording) {
324+
return;
325+
}
278326
if (subject.isPresent()) {
279327
throw execException(tree("The "
280328
+ name

projects/net.splitcells.gel.editor/src/main/java/net/splitcells/gel/editor/geal/runners/FunctionCallExecutor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package net.splitcells.gel.editor.geal.runners;
1717

18+
import net.splitcells.dem.data.Flow;
1819
import net.splitcells.gel.editor.Editor;
1920
import net.splitcells.gel.editor.geal.lang.FunctionCallDesc;
2021

@@ -23,4 +24,6 @@
2324
public interface FunctionCallExecutor {
2425

2526
FunctionCallRun execute(FunctionCallDesc functionCall, Optional<Object> subject, Editor context);
27+
28+
Flow<FunctionCallRunnerParser<?>> parsers();
2629
}

projects/net.splitcells.gel.editor/src/main/java/net/splitcells/gel/editor/geal/runners/FunctionCallMetaExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package net.splitcells.gel.editor.geal.runners;
1717

18+
import net.splitcells.dem.data.Flow;
1819
import net.splitcells.dem.data.set.list.List;
1920
import net.splitcells.dem.utils.ExecutionException;
2021
import net.splitcells.gel.editor.Editor;
@@ -87,4 +88,8 @@ public FunctionCallRun execute(FunctionCallDesc functionCall, Optional<Object> s
8788
return fittingRun.get();
8889
}
8990

91+
public Flow<FunctionCallRunnerParser<?>> parsers() {
92+
return executors.stream().flatMap(e -> e.parsers().stream());
93+
}
94+
9095
}

projects/net.splitcells.gel.editor/src/main/java/net/splitcells/gel/editor/geal/runners/FunctionCallRunnerParser.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package net.splitcells.gel.editor.geal.runners;
1717

1818
import lombok.val;
19+
import net.splitcells.dem.lang.tree.Tree;
1920
import net.splitcells.gel.editor.Editor;
2021
import net.splitcells.gel.editor.geal.FunctionCallRecord;
2122
import net.splitcells.gel.editor.geal.lang.FunctionCallDesc;
@@ -39,4 +40,10 @@ public T parse(Optional<Object> subject, Editor context, FunctionCallDesc functi
3940
return parser.apply(fcr);
4041
}
4142
}
43+
44+
public Tree document(Editor context) {
45+
try (val fcr = context.functionCallRecord(null, null, null, 1)) {
46+
return null;
47+
}
48+
}
4249
}

0 commit comments

Comments
 (0)