本文整理汇总了Java中org.spoofax.interpreter.terms.IStrategoTerm类的典型用法代码示例。如果您正苦于以下问题:Java IStrategoTerm类的具体用法?Java IStrategoTerm怎么用?Java IStrategoTerm使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IStrategoTerm类属于org.spoofax.interpreter.terms包,在下文中一共展示了IStrategoTerm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTermIterative
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
/**
* Builds the AST for the specified term, iteratively.
*
* @param root
* The root term.
*/
private void buildTermIterative(final PsiBuilder builder, final IStrategoTerm root,
final ATermAstElementTypeProvider elementTypeProvider) {
final Stack<TermTask> tasks = new Stack<>();
tasks.push(new TermTask(root));
while(!tasks.empty()) {
final TermTask task = tasks.pop();
final IStrategoTerm term = task.term();
@Nullable PsiBuilder.Marker marker = task.marker();
if(marker == null) {
// Start
marker = buildTermStart(builder, term);
tasks.push(new TermTask(term, marker));
final IStrategoTerm[] subterms = term.getAllSubterms();
for(int i = subterms.length - 1; i >= 0; i--) {
tasks.push(new TermTask(subterms[i]));
}
} else {
// End
buildTermEnd(builder, term, marker, elementTypeProvider);
}
}
}
示例2: getElementType
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
@Override
public IElementType getElementType(final IStrategoTerm term) {
final ICategory category = getCategory(term);
IElementType elementType = null;
if (category instanceof TokenCategory) {
switch (category.name()) {
case "TK_IDENTIFIER":
elementType = this.tokenTypesManager.getIdentifierType();
break;
default:
break;
}
}
if (elementType == null)
elementType = this.tokenTypesManager.getElementType();
return elementType;
}
示例3: invoke
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm usedWordTerm, IStrategoTerm schemeNameTerm) {
if (usedWordTerm instanceof IStrategoString) {
if (schemeNameTerm instanceof IStrategoString) {
final String schemeName = Tools.asJavaString(schemeNameTerm);
final String usedWord = Tools.asJavaString(usedWordTerm);
final String regex = schemeName + "(_.+|[0-9]+'*|'+[0-9]*)";
if (usedWord.matches(regex)) {
return usedWordTerm;
}
}
}
return null;
}
示例4: invoke
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
@Override
public IStrategoTerm invoke(Context context, IStrategoTerm current) {
if (!(current instanceof IStrategoString)) {
return null;
}
final IContext mbContext = (IContext) context.contextObject();
final Injector injector = mbContext.injector();
final IResourceService resources = injector.getInstance(IResourceService.class);
final FileObject fileObj = resources.resolve(Tools.asJavaString(current));
try {
fileObj.setExecutable(true, false);
} catch (FileSystemException e1) {
return null;
}
return current;
}
示例5: parse
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
@Override
public IStrategoTerm parse(Source src, @Nullable String overridingStartSymbol) {
if (parser == null) {
createParser();
}
String startSymbol = this.startSymbol;
if (overridingStartSymbol != null) {
startSymbol = overridingStartSymbol;
}
try {
final Disambiguator disambiguator = parser.getDisambiguator();
disambiguator.setFilterPriorities(false);
SGLRParseResult parseResult = parser.parse(IOUtils.toString(src.getInputStream(), Charset.defaultCharset()),
src.getPath(), startSymbol);
IStrategoTerm term = (IStrategoTerm) parseResult.output;
return term;
} catch (SGLRException | InterruptedException | IOException e) {
throw new IllegalStateException("File failed to parse", e);
}
}
示例6: fromStrategoTerm
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
public static INodeSource fromStrategoTerm(IStrategoTerm aterm) {
AbstractTermAttachment attachment = null;
ImploderAttachment imploderAttachment = null;
if (aterm.getAttachment(OriginAttachment.TYPE) != null) {
OriginAttachment originAttachment = aterm
.getAttachment(OriginAttachment.TYPE);
imploderAttachment = originAttachment.getOrigin().getAttachment(
ImploderAttachment.TYPE);
attachment = originAttachment;
} else if (aterm.getAttachment(ImploderAttachment.TYPE) != null) {
imploderAttachment = aterm.getAttachment(ImploderAttachment.TYPE);
attachment = imploderAttachment;
}
return imploderAttachment != null ? new NodeSource(imploderAttachment,
attachment) : null;
}
示例7: convert
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
public static ITTerm convert(IStrategoTerm t) {
if (t instanceof IStrategoAppl)
return convert((IStrategoAppl) t);
if (t instanceof IStrategoTuple)
return convert((IStrategoTuple) t);
if (t instanceof IStrategoList)
return convert((IStrategoList) t);
if (t instanceof IStrategoString)
return convert((IStrategoString) t);
if (t instanceof IStrategoInt)
return convert((IStrategoInt) t);
throw new UnsupportedOperationException("Unsupported aterm " + t);
}
示例8: matchAnyExplode
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
private Results matchAnyExplode(IContext env, IStrategoTerm t,
IStrategoAppl p) throws InterpreterException {
if(DebugUtil.isDebugging()) {
DebugUtil.debug(" pattern is Explode");
}
IStrategoAppl opPattern = Tools.applAt(p, 0);
IStrategoAppl argsPattern = Tools.applAt(p, 1);
IStrategoTerm op = getTermConstructor(env, t);
IStrategoTerm args = getTermArguments(env, t);
Results opResult = match(env, op, opPattern);
Results argsResult = match(env, args, argsPattern);
if (opResult == null || argsResult == null)
return null;
opResult.addAll(argsResult);
return opResult;
}
示例9: buildOp
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
private IStrategoTerm buildOp(String ctr, IContext env, IStrategoAppl t, ITermFactory factory)
throws InterpreterException {
IStrategoList children = (IStrategoList) t.getSubterm(1);
IStrategoConstructor ctor = factory.makeConstructor(ctr, children.size());
IStrategoTerm[] kids = new IStrategoTerm[children.size()];
for (int i = children.size() -1 ; i >= 0; i--) {
IStrategoTerm kid = buildTerm(env, (IStrategoAppl) children.getSubterm(i));
if (kid == null) {
return null;
}
kids[i] = kid;
}
return factory.makeAppl(ctor, kids);
}
示例10: parseFromString
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
protected IStrategoTerm parseFromString(PushbackStringIterator bis) throws ParseError {
parseSkip(bis);
final int ch = bis.read();
switch(ch) {
case '[': return parseAnno(bis, parseList(bis));
case '(': return parseAnno(bis, parseTuple(bis));
case '"': return parseAnno(bis, parseString(bis));
case '<': return parsePlaceholder(bis);
default:
bis.unread(ch);
if (Character.isLetter((char)ch)) {
return parseAnno(bis, parseAppl(bis));
}
else if (Character.isDigit((char)ch) || ch == '-')
return parseAnno(bis, parseNumber(bis));
}
throw new ParseError("Invalid term: '" + (char)ch + "'");
}
示例11: initializeParseTable
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
private ParseTable initializeParseTable(ITermFactory factory, IStrategoTerm pt) throws InvalidParseTableException {
long start = System.currentTimeMillis();
ParseTable parseTable = new ParseTable(pt, factory);
long elapsed = System.currentTimeMillis() - start;
if (SGLR.isLogging()) {
Tools.logger("Loading parse table took " + elapsed/1000.0f + "s");
Tools.logger("No. of states: ", parseTable.getStateCount());
Tools.logger("No. of productions: ", parseTable.getProductionCount());
Tools.logger("No. of action entries: ", parseTable.getActionCount());
Tools.logger("No. of gotos entries: ", parseTable.getGotoCount());
Tools.logger((parseTable.hasRejects() ? "Includes" : "Excludes"), " rejects");
Tools.logger((parseTable.hasPriorities() ? "Includes" : "Excludes"), " priorities");
Tools.logger((parseTable.hasPrefers() ? "Includes" : "Excludes"), " prefer actions");
Tools.logger((parseTable.hasAvoids() ? "Includes" : "Excludes"), " avoid actions");
}
return parseTable;
}
示例12: lookup
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
public IStrategoTerm lookup(String name) {
IStrategoTerm t = vars.get(name);
if (t == null && parent != null)
t = parent.lookup(name);
if(DebugUtil.isDebugging()) {
Context.debug(DebugUtil.buildIndent(DebugUtil.INDENT_STEP), "lookup : ", name, " = ", t);
VarScope vs = this;
while(vs != null) {
Context.debug(DebugUtil.buildIndent(DebugUtil.INDENT_STEP), vs);
vs = vs.parent;
}
}
return t;
}
示例13: endElement
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
@Override
public void endElement(String uri, String localName, String qName) {
Element element = stack.pop();
Element parent = stack.peek();
// Store text parsed before this end tag if either mixed content is allowed
// or text-only content is allowed and the element has no children.
if ((allowMixedContent || (allowTextContent && element.childs.isEmpty())) && textBuilder.length() > 0) {
IStrategoTerm contents = factory.makeString(textBuilder.toString());
IStrategoTerm textNode = factory.makeAppl(textCons, contents);
element.childs.add(textNode);
}
textBuilder.setLength(0);
parent.childs.add(elementToStrategoTerm(element));
}
示例14: toString
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
private String toString(IStrategoTerm term) {
if(term instanceof IStrategoString) {
final IStrategoString messageStringTerm = (IStrategoString) term;
return messageStringTerm.stringValue();
} else if(term instanceof IStrategoList) {
final StringBuilder sb = new StringBuilder();
boolean first = true;
for(IStrategoTerm subterm : term) {
if(!first) {
sb.append(' ');
}
sb.append(toString(subterm));
first = false;
}
return sb.toString();
} else {
return term.toString();
}
}
示例15: call
import org.spoofax.interpreter.terms.IStrategoTerm; //导入依赖的package包/类
@Override
public boolean call(IContext context, Strategy[] svars, IStrategoTerm[] tvars) {
IStrategoTerm current = context.current();
FileChannel c = JFFLibrary.fromTupleWrapped(current, 0, FileChannel.class);
ByteBuffer buf = JFFLibrary.fromTupleWrapped(current, 1, ByteBuffer.class);
if(c == null || buf == null)
return true;
try {
c.write(buf);
} catch(IOException e) {
return JFFLibrary.invokeExceptionHandler(context, e);
}
return true;
}