Skip to content

Commit 661b3b5

Browse files
committed
Merge branch 'topic/lkql_jit/add_create_from_template' into 'master'
Enhance the "create_from_template" documentation and update generated LKQL user manual See merge request eng/libadalang/langkit-query-language!430
2 parents ab24408 + 6810c5e commit 661b3b5

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lkql_jit/language/src/main/java/com/adacore/lkql_jit/built_ins/methods/RewritingContextMethods.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,20 @@ public Object executeGeneric(VirtualFrame frame, RewritingContext ctx, Object ob
187187

188188
@BuiltInMethod(
189189
name = "create_from_template",
190-
doc = "Create a new node from the provided template, filling '{}' with provided" +
191-
" argument, and parsing the template with the specified grammar rule"
190+
doc = """
191+
Create a new node from the provided template, filling '{}' with provided
192+
argument, and parsing the template with the specified grammar rule. Example:
193+
194+
.. code-block:: lkql
195+
196+
# Create a new BinOp node with OpAdd as operator, representing the addition of the value
197+
# expressed by `my_other_node`, and "42".
198+
ctx.create_from_template(
199+
"{} + 42",
200+
"expr_rule",
201+
[my_other_node]
202+
)
203+
"""
192204
)
193205
public abstract static class CreateFromTemplateExpr extends BaseRewritingContextExpr {
194206

user_manual/generated/std.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,22 @@ Methods for `RewritingContext`
415415

416416
Insert `new_node` at the end of `list_node`
417417

418+
.. method:: RewritingContext.create_from_template(this, template, grammar_rule, arguments)
419+
420+
Create a new node from the provided template, filling '{}' with provided
421+
argument, and parsing the template with the specified grammar rule. Example:
422+
423+
.. code-block:: lkql
424+
425+
# Create a new BinOp node with OpAdd as operator, representing the addition of the value
426+
# expressed by `my_other_node`, and "42".
427+
ctx.create_from_template(
428+
"{} + 42",
429+
"expr_rule",
430+
[my_other_node]
431+
)
432+
433+
418434
.. method:: RewritingContext.doc(this)
419435

420436
Given any object, return the documentation associated with it

0 commit comments

Comments
 (0)