forked from metaschema-framework/metaschema-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for named function refs for metaschema-framework#283
In order to implement functions that look up names, arity, and other details for Metapath functions, we must implement processing to support named function references found from the tokenizer and lexer.
- Loading branch information
1 parent
f0cae60
commit 3a4d334
Showing
6 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
core/src/main/java/gov/nist/secauto/metaschema/core/metapath/cst/NamedFunctionReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.core.metapath.cst; | ||
|
||
import gov.nist.secauto.metaschema.core.metapath.DynamicContext; | ||
import gov.nist.secauto.metaschema.core.metapath.function.IFunction; | ||
import gov.nist.secauto.metaschema.core.metapath.item.IItem; | ||
import gov.nist.secauto.metaschema.core.metapath.item.ISequence; | ||
import gov.nist.secauto.metaschema.core.qname.IEnhancedQName; | ||
import gov.nist.secauto.metaschema.core.util.CollectionUtil; | ||
|
||
import java.util.List; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** | ||
* The CST node for a Metapath | ||
* <a href="https://www.w3.org/TR/xpath-31/#id-named-function-ref">variable | ||
* reference</a>. | ||
*/ | ||
public class NamedFunctionReference implements IExpression { | ||
@NonNull | ||
private IEnhancedQName eqname; | ||
@NonNull | ||
private final int arity; | ||
|
||
/** | ||
* Construct a new Metapath variable reference CST node. | ||
* | ||
* @param name | ||
* the variable name | ||
*/ | ||
public NamedFunctionReference(@NonNull IEnhancedQName eqname, @NonNull int arity) { | ||
this.eqname = eqname; | ||
this.arity = arity; | ||
} | ||
|
||
/** | ||
* Get the variable name. | ||
* | ||
* @return the variable name | ||
*/ | ||
@NonNull | ||
public IEnhancedQName getName() { | ||
return eqname; | ||
} | ||
|
||
public int getArity() { | ||
return arity; | ||
} | ||
|
||
@Override | ||
public List<? extends IExpression> getChildren() { | ||
return CollectionUtil.emptyList(); | ||
} | ||
|
||
@SuppressWarnings("null") | ||
@Override | ||
public String toASTString() { | ||
return String.format("%s[name=%s, arity=%d]", getClass().getName(), eqname, arity); | ||
} | ||
|
||
@Override | ||
public <RESULT, CONTEXT> RESULT accept(IExpressionVisitor<RESULT, CONTEXT> visitor, CONTEXT context) { | ||
return visitor.visitNamedFunctionReference(this, context); | ||
} | ||
|
||
@Override | ||
public ISequence<? extends IItem> accept(DynamicContext dynamicContext, ISequence<?> focus) { | ||
IFunction function = dynamicContext.getFunction(eqname, arity); | ||
return ISequence.of(function); | ||
} | ||
} |