本文整理匯總了Java中com.github.fge.grappa.run.context.Context類的典型用法代碼示例。如果您正苦於以下問題:Java Context類的具體用法?Java Context怎麽用?Java Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Context類屬於com.github.fge.grappa.run.context包,在下文中一共展示了Context類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: C
import com.github.fge.grappa.run.context.Context; //導入依賴的package包/類
public Rule C()
{
return sequence(
'c',
push(pop()), // no effect
// FIXME: turning into a lambda throws IllegalAccessException...
new Action<Integer>()
{
@Override
public boolean run(final Context<Integer> context) {
return getContext() == context;
}
},
D(1)
);
}
示例2: pushToken
import com.github.fge.grappa.run.context.Context; //導入依賴的package包/類
public boolean pushToken(final TokenType tokenType)
{
final Context<Token.Builder> context = getContext();
final int startIndex = context.getMatchStartIndex();
final Position position
= context.getInputBuffer().getPosition(startIndex);
final Token.Builder token = Token.builder()
.setValueAndOriginalValue(match())
.setLine(position.getLine())
.setColumn(position.getColumn())
.setType(tokenType);
return push(token);
}
示例3: insertSetContextCalls
import com.github.fge.grappa.run.context.Context; //導入依賴的package包/類
protected static void insertSetContextCalls(final InstructionGroup group,
int localVarIx)
{
final InsnList instructions = group.getInstructions();
final CodeBlock block = CodeBlock.newCodeBlock();
for (final InstructionGraphNode node: group.getNodes()) {
if (!node.isCallOnContextAware())
continue;
final AbstractInsnNode insn = node.getInstruction();
if (node.getPredecessors().size() > 1) {
// store the target of the call in a new local variable
final AbstractInsnNode loadTarget = node.getPredecessors()
.get(0).getInstruction();
block.clear().dup().astore(++localVarIx);
instructions.insert(loadTarget, block.getInstructionList());
// immediately before the call get the target from the local var
// and set the context on it
instructions.insertBefore(insn, new VarInsnNode(ALOAD,
localVarIx));
} else {
// if we have only one predecessor the call does not take any
// parameters and we can skip the storing and loading of the
// invocation target
instructions.insertBefore(insn, new InsnNode(DUP));
}
block.clear()
.aload(1)
.invokeinterface(CodegenUtils.p(ContextAware.class),
"setContext", CodegenUtils.sig(void.class, Context.class));
instructions.insertBefore(insn, block.getInstructionList());
}
}
示例4: generateMethod
import com.github.fge.grappa.run.context.Context; //導入依賴的package包/類
@Override
protected void generateMethod(final InstructionGroup group,
final ClassWriter cw)
{
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "run",
CodegenUtils.sig(boolean.class, Context.class), null, null);
insertSetContextCalls(group, 1);
convertXLoads(group);
group.getInstructions().accept(mv);
mv.visitInsn(IRETURN);
mv.visitMaxs(0, 0); // trigger automatic computing
}
示例5: ParsingResult
import com.github.fge.grappa.run.context.Context; //導入依賴的package包/類
/**
* Creates a new ParsingResult.
*
* @param matched true if the rule matched the input
* @param valueStack the value stack of the parsing run
* @param context the parsing context
*/
public ParsingResult(final boolean matched,
@Nonnull final ValueStack<V> valueStack,
@Nonnull final Context<V> context)
{
Objects.requireNonNull(context);
this.matched = matched;
this.valueStack = Objects.requireNonNull(valueStack);
inputBuffer = context.getInputBuffer();
contextIndex = context.getCurrentIndex();
}
示例6: setContext
import com.github.fge.grappa.run.context.Context; //導入依賴的package包/類
/**
* ContextAware interface implementation.
*
* @param context the context
*/
@Override
public final void setContext(final Context<V> context)
{
this.context = Objects.requireNonNull(context, "context");
}
示例7: run
import com.github.fge.grappa.run.context.Context; //導入依賴的package包/類
/**
* Runs the parser action.
*
* @param context the current parsing context
* @return true if the parsing process is to proceed, false if the current
* rule is to fail
*/
boolean run(Context<V> context);
示例8: getContext
import com.github.fge.grappa.run.context.Context; //導入依賴的package包/類
/**
* The current context for use with action methods. Updated immediately
* before action calls.
*
* @return the current context
*/
public final Context<V> getContext()
{
return context;
}