|
| 1 | +package org.rascalmpl.test.parser; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.StringReader; |
| 5 | + |
| 6 | +import org.rascalmpl.parser.gtd.SGTDBF; |
| 7 | +import org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener; |
| 8 | +import org.rascalmpl.parser.gtd.stack.AbstractStackNode; |
| 9 | +import org.rascalmpl.parser.gtd.stack.LiteralStackNode; |
| 10 | +import org.rascalmpl.parser.gtd.stack.NonTerminalStackNode; |
| 11 | +import org.rascalmpl.parser.gtd.stack.SequenceStackNode; |
| 12 | +import org.rascalmpl.parser.uptr.UPTRNodeFactory; |
| 13 | +import io.usethesource.vallang.IConstructor; |
| 14 | +import io.usethesource.vallang.ISourceLocation; |
| 15 | +import io.usethesource.vallang.IValue; |
| 16 | +import io.usethesource.vallang.io.StandardTextReader; |
| 17 | + |
| 18 | +import org.rascalmpl.values.RascalFunctionValueFactory; |
| 19 | +import org.rascalmpl.values.RascalValueFactory; |
| 20 | +import org.rascalmpl.values.ValueFactoryFactory; |
| 21 | +import org.rascalmpl.values.parsetrees.ITree; |
| 22 | +/* |
| 23 | +S ::= (A () B) |
| 24 | +A ::= a |
| 25 | +B ::= b |
| 26 | +*/ |
| 27 | +@SuppressWarnings({"unchecked", "cast"}) |
| 28 | +public class Sequence4 extends SGTDBF<IConstructor, ITree, ISourceLocation> implements IParserTest{ |
| 29 | + private final static IConstructor SYMBOL_START_S = VF.constructor(RascalValueFactory.Symbol_Sort, VF.string("S")); |
| 30 | + private final static IConstructor SYMBOL_SEQ = VF.constructor(RascalValueFactory.Symbol_Seq, VF.list()); |
| 31 | + |
| 32 | + private final static IConstructor PROD_S_SEQ_AB = VF.constructor(RascalValueFactory.Production_Default, SYMBOL_START_S, VF.list(SYMBOL_SEQ), VF.set()); |
| 33 | + private final static IConstructor PROD_SEQUENCE = VF.constructor(RascalValueFactory.Production_Default, SYMBOL_SEQ, VF.list(), VF.set()); |
| 34 | + |
| 35 | + private final static AbstractStackNode<IConstructor> NONTERMINAL_START_S = new NonTerminalStackNode<IConstructor>(AbstractStackNode.START_SYMBOL_ID, 0, "S"); |
| 36 | + private final static AbstractStackNode<IConstructor> SEQUENCE4 = new SequenceStackNode<IConstructor>(3, 0, PROD_SEQUENCE, new AbstractStackNode[]{}); |
| 37 | + |
| 38 | + private final static AbstractStackNode<IConstructor>[] S_EXPECT_1 = (AbstractStackNode<IConstructor>[]) new AbstractStackNode[1]; |
| 39 | + static{ |
| 40 | + S_EXPECT_1[0] = SEQUENCE4; |
| 41 | + S_EXPECT_1[0].setProduction(S_EXPECT_1); |
| 42 | + S_EXPECT_1[0].setAlternativeProduction(PROD_S_SEQ_AB); |
| 43 | + } |
| 44 | + |
| 45 | + public Sequence4(){ |
| 46 | + super(); |
| 47 | + } |
| 48 | + |
| 49 | + public AbstractStackNode<IConstructor>[] S(){ |
| 50 | + return (AbstractStackNode<IConstructor>[]) new AbstractStackNode[]{S_EXPECT_1[0]}; |
| 51 | + } |
| 52 | + |
| 53 | + public ITree executeParser(){ |
| 54 | + return parse(NONTERMINAL_START_S, null, "".toCharArray(), new DefaultNodeFlattener<IConstructor, ITree, ISourceLocation>(), new UPTRNodeFactory(true)); |
| 55 | + } |
| 56 | + |
| 57 | + public IValue getExpectedResult() throws IOException{ |
| 58 | + String expectedInput = "appl(prod(sort(\"S\"),[seq([])],{}),[appl(prod(seq([]),[],{}),[])])"; |
| 59 | + return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), RascalValueFactory.uptr, RascalValueFactory.Tree, new StringReader(expectedInput)); |
| 60 | + } |
| 61 | + |
| 62 | + public static void main(String[] args){ |
| 63 | + Sequence4 s4 = new Sequence4(); |
| 64 | + IConstructor result = s4.executeParser(); |
| 65 | + System.out.println(result); |
| 66 | + } |
| 67 | +} |
0 commit comments