/******************************************************************************* * Copyright (c) 2009-2011 CWI * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * * Jurgen J. Vinju - Jurgen.Vinju@cwi.nl - CWI * * Arnold Lankamp - Arnold.Lankamp@cwi.nl *******************************************************************************/ package org.rascalmpl.test_compiled.parser; import java.io.IOException; import java.io.StringReader; import org.rascalmpl.parser.gtd.SGTDBF; import org.rascalmpl.parser.gtd.result.out.DefaultNodeFlattener; import org.rascalmpl.parser.gtd.stack.AbstractStackNode; import org.rascalmpl.parser.gtd.stack.CharStackNode; import org.rascalmpl.parser.gtd.stack.ListStackNode; import org.rascalmpl.parser.gtd.stack.NonTerminalStackNode; import org.rascalmpl.parser.uptr.UPTRNodeFactory; import org.rascalmpl.value.IConstructor; import org.rascalmpl.value.ISourceLocation; import org.rascalmpl.value.IValue; import org.rascalmpl.value.io.StandardTextReader; import org.rascalmpl.values.ValueFactoryFactory; import org.rascalmpl.values.uptr.ITree; import org.rascalmpl.values.uptr.RascalValueFactory; /* S ::= [a-z]* */ @SuppressWarnings({"unchecked", "cast"}) public class CharStarList extends SGTDBF<IConstructor, ITree, ISourceLocation> implements IParserTest{ private final static IConstructor SYMBOL_START_S = VF.constructor(RascalValueFactory.Symbol_Sort, VF.string("S")); private final static IConstructor SYMBOL_char_a_z = VF.constructor(RascalValueFactory.Symbol_CharClass, VF.list(VF.constructor(RascalValueFactory.CharRange_Range, VF.integer(97), VF.integer(122)))); private final static IConstructor SYMBOL_STAR_LIST_a_z = VF.constructor(RascalValueFactory.Symbol_IterStar, SYMBOL_char_a_z); private final static IConstructor PROD_S_STARLISTa_z = VF.constructor(RascalValueFactory.Production_Default, SYMBOL_START_S, VF.list(SYMBOL_STAR_LIST_a_z), VF.set()); private final static IConstructor PROD_STARLISTa_z = VF.constructor(RascalValueFactory.Production_Regular, SYMBOL_STAR_LIST_a_z); private final static AbstractStackNode<IConstructor> NONTERMINAL_START_S = new NonTerminalStackNode<IConstructor>(AbstractStackNode.START_SYMBOL_ID, 0, "S"); private final static AbstractStackNode<IConstructor> CHAR0 = new CharStackNode<IConstructor>(0, 0, new int[][]{{'a', 'z'}}); private final static AbstractStackNode<IConstructor> LIST1 = new ListStackNode<IConstructor>(1, 0, PROD_STARLISTa_z, CHAR0, false); private final static AbstractStackNode<IConstructor>[] S_EXPECT_1 = (AbstractStackNode<IConstructor>[]) new AbstractStackNode[1]; static{ S_EXPECT_1[0] = LIST1; S_EXPECT_1[0].setProduction(S_EXPECT_1); S_EXPECT_1[0].setAlternativeProduction(PROD_S_STARLISTa_z); } public CharStarList(){ super(); } public AbstractStackNode<IConstructor>[] S(){ return (AbstractStackNode<IConstructor>[]) new AbstractStackNode[]{S_EXPECT_1[0]}; } public ITree executeParser(){ return parse(NONTERMINAL_START_S, null, "abc".toCharArray(), new DefaultNodeFlattener<IConstructor, ITree, ISourceLocation>(), new UPTRNodeFactory(true)); } public IValue getExpectedResult() throws IOException{ String expectedInput = "appl(prod(sort(\"S\"),[\\iter-star(\\char-class([range(97,122)]))],{}),[appl(regular(\\iter-star(\\char-class([range(97,122)]))),[char(97),char(98),char(99)])])"; return new StandardTextReader().read(ValueFactoryFactory.getValueFactory(), RascalValueFactory.uptr, RascalValueFactory.Tree, new StringReader(expectedInput)); } public static void main(String[] args){ CharStarList csl = new CharStarList(); IConstructor result = csl.executeParser(); System.out.println(result); System.out.println("S([a-z]*([a-z](a),[a-z](b),[a-z](c))) <- good"); } }