本文整理了Java中org.parboiled.support.ValueStack
类的一些代码示例,展示了ValueStack
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ValueStack
类的具体详情如下:
包路径:org.parboiled.support.ValueStack
类名称:ValueStack
[英]A ValueStack is a stack implementation for parser values. The current state of the stack can be saved and restored with the methods #takeSnapshot() and #restoreSnapshot(Object) ()}, whose implementations should be super efficient since they are being used extensively during a parsing run. A ValueStack also serves as an Iterable over the current stack values (the values are being provided with the last value (on top of the stack) first).
[中]ValueStack是解析器值的堆栈实现。可以使用#takeSnapshot()和#restoreSnapshot(Object)()方法保存和恢复堆栈的当前状态,这些方法的实现应该非常高效,因为它们在解析运行期间被广泛使用。ValueStack还可以作为当前堆栈值的一个Iterable(首先提供最后一个值(在堆栈顶部)的值)。
代码示例来源:origin: immutables/immutables
@Override
public Object get(Context<Object> context) {
return context.getValueStack().pop();
}
代码示例来源:origin: immutables/immutables
@Override
public final boolean run(Context<Object> context) {
V value = extractor.get(context);
@SuppressWarnings("unchecked")
B builder = (B) context.getValueStack().peek();
specify(builder, value);
return true;
}
代码示例来源:origin: immutables/immutables
@Override
public final boolean run(Context<Object> context) {
B builder = builder();
context.getValueStack().push(builder);
return true;
}
代码示例来源:origin: org.geotools/gt-css
<T> List<T> popAll(Class... classes) {
ValueStack<Object> valueStack = getContext().getValueStack();
List<T> result = new ArrayList<T>();
while (!valueStack.isEmpty() && isInstance(classes, valueStack.peek())) {
result.add((T) valueStack.pop());
}
if (!valueStack.isEmpty() && valueStack.peek() == MARKER) {
valueStack.pop();
}
Collections.reverse(result);
return result;
}
代码示例来源:origin: AlexFalappa/nb-springboot
@Override
public boolean run(Context<CfgElement> context) {
final ValueStack<CfgElement> stack = context.getValueStack();
if (!context.hasError()) {
int size = stack.size();
switch (size) {
case 1:
CfgElement elemKey = stack.pop();
parsedProps.setProperty(unescape(elemKey.getText()), "");
cfgFile.getElements().add(new PairElement(elemKey));
break;
case 2:
// NOTE: stack popping order below is important!
final CfgElement elemValue = stack.pop();
elemKey = stack.pop();
parsedProps.setProperty(unescape(elemKey.getText()), unescape(elemValue.getText()));
cfgFile.getElements().add(new PairElement(elemKey, elemValue));
break;
default:
throw new IllegalStateException(String.format("Cannot manage %d values on the parsing stack", size));
}
} else {
stack.clear();
}
return true;
}
代码示例来源:origin: org.parboiled/parboiled-core
@SuppressWarnings({"ConstantConditions"})
public void createNode() {
if (!nodeSuppressed) {
node = new NodeImpl<V>(matcher, getSubNodes(), startIndex, currentIndex,
valueStack.isEmpty() ? null : valueStack.peek(), hasError);
if (parent != null) {
parent.subNodes = parent.subNodes.prepend(node);
}
}
}
代码示例来源:origin: com.github.edgarespina/handlebars
@Override
public boolean run(final Context<BaseTemplate> context) {
ValueStack<BaseTemplate> stack = context.getValueStack();
if (stack.size() > 1) {
BaseTemplate body = pop();
((Block) section.get()).inverse(body);
}
return addToline(section.get());
}
}
代码示例来源:origin: jtwig/jtwig-core
@Test
public void set() throws Exception {
ParsingResult<SetNode> result = parse(underTest.NodeRule(), "{% set a = 123 %}");
assertThat(result.matched, is(true));
assertThat(result.valueStack.isEmpty(), is(false));
}
}
代码示例来源:origin: org.parboiled/parboiled-core
/**
* Creates a new ParsingResult.
*
* @param matched true if the rule matched the input
* @param parseTreeRoot the parse tree root node
* @param valueStack the value stack of the parsing run
* @param parseErrors the list of parse errors
* @param inputBuffer the input buffer
*/
public ParsingResult(boolean matched, Node<V> parseTreeRoot, ValueStack<V> valueStack, List<ParseError> parseErrors,
InputBuffer inputBuffer) {
this.matched = matched;
this.parseTreeRoot = parseTreeRoot;
this.valueStack = checkArgNotNull(valueStack, "valueStack");
this.resultValue = valueStack.isEmpty() ? null : valueStack.peek();
this.parseErrors = checkArgNotNull(parseErrors, "parseErrors");
this.inputBuffer = checkArgNotNull(inputBuffer, "inputBuffer");
}
代码示例来源:origin: com.github.edgarespina/handlebars
@Override
public boolean run(final Context<BaseTemplate> context) {
ValueStack<BaseTemplate> stack = context.getValueStack();
if (stack.size() > 1) {
BaseTemplate body = pop();
((Block) section.get()).body(body);
}
return addToline(section.get());
}
}).label("block");
代码示例来源:origin: jtwig/jtwig-core
@Test
public void set() throws Exception {
ParsingResult<SetNode> result = parse(underTest.NodeRule(), "{% do 1 + 123 %}");
assertThat(result.matched, is(true));
assertThat(result.valueStack.isEmpty(), is(false));
}
代码示例来源:origin: immutables/immutables
@Override
public final T get(Context<Object> context) {
@SuppressWarnings("unchecked")
B builder = (B) context.getValueStack().pop();
return build(builder);
}
代码示例来源:origin: immutables/immutables
@Override
public final boolean run(Context<Object> context) {
Object value = get(context);
context.getValueStack().push(value);
return true;
}
}
代码示例来源:origin: org.pegdown/pegdown
boolean setListItemIndices() {
SuperNode listItem = (SuperNode) getContext().getValueStack().peek();
List<Node> children = listItem.getChildren();
listItem.setStartIndex(children.get(0).getStartIndex());
listItem.setEndIndex(children.get(children.size() - 1).getEndIndex());
return true;
}
代码示例来源:origin: io.smartcat/ranger
/**
* Creates CSV value.
*
* @return An CSV value.
*/
protected CsvReaderValue createCsvReaderValue() {
CSVParserSettings parserSettings = null;
switch (getContext().getValueStack().size()) {
case 1:
parserSettings = new CSVParserSettings((String) pop());
break;
case 2:
parserSettings = new CSVParserSettings((String) pop(1), (char) pop());
break;
case 8:
parserSettings = new CSVParserSettings((String) pop(7), (char) pop(6), (String) pop(5), (boolean) pop(4),
peek(3) instanceof NullValue ? null : (Character) pop(3), (char) pop(2), (boolean) pop(1),
peek() instanceof NullValue ? null : (String) pop());
break;
default:
throw new RuntimeException("Unsupported number of parameters, should not happen ever.");
}
return new CsvReaderValue(parserSettings);
}
代码示例来源:origin: org.geotools/gt-css
@Override
public boolean run(Context ctx) {
List contents = (List) pop();
Selector selector = (Selector) pop();
String comment = null;
if (!ctx.getValueStack().isEmpty() && peek() instanceof String) {
comment = (String) pop();
comment = comment.trim();
// get rid of the extra comments between rules
while (!ctx.getValueStack().isEmpty() && peek() instanceof String) {
pop();
}
}
final Stream stream = contents.stream();
Map<Boolean, List> splitContents =
(Map<Boolean, List>)
stream.collect(
Collectors.partitioningBy(
x -> x instanceof CssRule));
List<Property> properties = splitContents.get(Boolean.FALSE);
List<CssRule> subRules = splitContents.get(Boolean.TRUE);
final CssRule rule = new CssRule(selector, properties, comment);
rule.nestedRules = subRules;
push(rule);
return true;
}
});
代码示例来源:origin: org.pegdown/pegdown
Node parseListBlock(StringBuilderVar block) {
Context<Object> context = getContext();
Node innerRoot = parseInternal(block);
setContext(context); // we need to save and restore the context since we might be recursing
block.clearContents();
//debugMsg("parsed list block " + innerRoot.toString() + " adjusting indices by " + getContext().getValueStack().peek(), block.getString());
return withIndicesShifted(innerRoot, (Integer) context.getValueStack().pop());
}
代码示例来源:origin: org.geotools/gt-css
@Override
public boolean run(Context ctx) {
String match = match();
if (match.endsWith("k") || match.endsWith("M") || match.endsWith("G")) {
match = scaleValueToString(match);
}
ctx.getValueStack().push(new Value.Literal(match));
return true;
}
});
代码示例来源:origin: org.parboiled/parboiled-java
/**
* Returns the value the given number of elements below the top of the value stack without removing it.
*
* @param down the number of elements to skip (0 being equivalent to peek())
* @return the value
* @throws IllegalArgumentException if the stack does not contain enough elements to perform this operation
*/
public V peek(int down) {
check();
return context.getValueStack().peek(down);
}
代码示例来源:origin: smartcat-labs/ranger
/**
* Creates CSV value.
*
* @return An CSV value.
*/
protected CsvReaderValue createCsvReaderValue() {
CSVParserSettings parserSettings = null;
switch (getContext().getValueStack().size()) {
case 1:
parserSettings = new CSVParserSettings((String) pop());
break;
case 2:
parserSettings = new CSVParserSettings((String) pop(1), (char) pop());
break;
case 8:
parserSettings = new CSVParserSettings((String) pop(7), (char) pop(6), (String) pop(5), (boolean) pop(4),
peek(3) instanceof NullValue ? null : (Character) pop(3), (char) pop(2), (boolean) pop(1),
peek() instanceof NullValue ? null : (String) pop());
break;
default:
throw new RuntimeException("Unsupported number of parameters, should not happen ever.");
}
return new CsvReaderValue(parserSettings);
}
内容来源于网络,如有侵权,请联系作者删除!