|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2009-2011 CWI |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * |
| 8 | + * Contributors: |
| 9 | +
|
| 10 | + * * Arnold Lankamp - [email protected] |
| 11 | +*******************************************************************************/ |
| 12 | +package org.rascalmpl.test.parser; |
| 13 | + |
| 14 | +import java.io.IOException; |
| 15 | +import java.io.StringReader; |
| 16 | + |
| 17 | +import org.rascalmpl.parser.gtd.SGTDBF; |
| 18 | +import org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener; |
| 19 | +import org.rascalmpl.parser.gtd.stack.AbstractStackNode; |
| 20 | +import org.rascalmpl.parser.gtd.stack.AlternativeStackNode; |
| 21 | +import org.rascalmpl.parser.gtd.stack.NonTerminalStackNode; |
| 22 | +import org.rascalmpl.parser.uptr.UPTRNodeFactory; |
| 23 | +import io.usethesource.vallang.IConstructor; |
| 24 | +import io.usethesource.vallang.ISourceLocation; |
| 25 | +import io.usethesource.vallang.IValue; |
| 26 | +import io.usethesource.vallang.io.StandardTextReader; |
| 27 | + |
| 28 | +import org.rascalmpl.values.RascalValueFactory; |
| 29 | +import org.rascalmpl.values.ValueFactoryFactory; |
| 30 | +import org.rascalmpl.values.parsetrees.ITree; |
| 31 | + |
| 32 | +@SuppressWarnings({"unchecked", "cast"}) |
| 33 | +public class Alternative2 extends SGTDBF<IConstructor, ITree, ISourceLocation> implements IParserTest{ |
| 34 | + private final static IConstructor SYMBOL_START_S = VF.constructor(RascalValueFactory.Symbol_Sort, VF.string("S")); |
| 35 | + private final static IConstructor SYMBOL_ALT = VF.constructor(RascalValueFactory.Symbol_Alt, VF.set()); |
| 36 | + |
| 37 | + private final static IConstructor PROD_S_ALT = VF.constructor(RascalValueFactory.Production_Default, SYMBOL_START_S, VF.list(SYMBOL_ALT), VF.set()); |
| 38 | + private final static IConstructor PROD_ALT = VF.constructor(RascalValueFactory.Production_Default, SYMBOL_ALT, VF.list(), VF.set()); |
| 39 | + |
| 40 | + private final static AbstractStackNode<IConstructor> NONTERMINAL_START_S = new NonTerminalStackNode<IConstructor>(AbstractStackNode.START_SYMBOL_ID, 0, "S"); |
| 41 | + private final static AbstractStackNode<IConstructor>[] S_EXPECT_1 = (AbstractStackNode<IConstructor>[]) new AbstractStackNode[1]; |
| 42 | + static{ |
| 43 | + S_EXPECT_1[0] = new AlternativeStackNode<IConstructor>(4, 0, PROD_ALT, (AbstractStackNode<IConstructor>[]) new AbstractStackNode[]{}); |
| 44 | + S_EXPECT_1[0].setProduction(S_EXPECT_1); |
| 45 | + S_EXPECT_1[0].setAlternativeProduction(PROD_S_ALT); |
| 46 | + } |
| 47 | + |
| 48 | + public Alternative2(){ |
| 49 | + super(); |
| 50 | + } |
| 51 | + |
| 52 | + public AbstractStackNode<IConstructor>[] S(){ |
| 53 | + return new AbstractStackNode[]{S_EXPECT_1[0]}; |
| 54 | + } |
| 55 | + |
| 56 | + public ITree executeParser(){ |
| 57 | + return parse(NONTERMINAL_START_S, null, "".toCharArray(), new DefaultNodeFlattener<IConstructor, ITree, ISourceLocation>(), new UPTRNodeFactory(true)); |
| 58 | + } |
| 59 | + |
| 60 | + public IValue getExpectedResult() throws IOException{ |
| 61 | + String expectedInput = "appl(prod(sort(\"S\"),[alt({})],{}),[appl(prod(alt({})),[])])"; |
| 62 | + return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), RascalValueFactory.uptr, RascalValueFactory.Tree, new StringReader(expectedInput)); |
| 63 | + } |
| 64 | + |
| 65 | + public static void main(String[] args){ |
| 66 | + Alternative2 a2 = new Alternative2(); |
| 67 | + IConstructor result = a2.executeParser(); |
| 68 | + System.out.println(result); |
| 69 | + } |
| 70 | +} |
0 commit comments