1 package org.simantics.graph.compiler.internal.values;
3 import java.util.Collection;
5 import org.antlr.runtime.tree.Tree;
6 import org.simantics.databoard.binding.Binding;
7 import org.simantics.graph.compiler.internal.parsing.GraphParser;
8 import org.simantics.graph.compiler.internal.store.IPreValue;
9 import org.simantics.graph.compiler.internal.translation.DataValueTranslator;
10 import org.simantics.graph.query.Path;
11 import org.simantics.graph.query.Paths;
12 import org.simantics.ltk.ISource;
13 import org.simantics.ltk.Location;
14 import org.simantics.ltk.Problem;
15 import org.simantics.ltk.antlr.ANTLRUtils;
17 public class TreeValue implements IPreValue {
22 public TreeValue(ISource source, Tree tree) {
28 public Object toValue(Binding binding, Collection<Problem> problems) {
29 return new DataValueTranslator(source, problems).translate(tree, binding);
32 public Tree getTree() {
37 public Path getDefaultType(Paths paths) {
39 while(b.getType() == GraphParser.TUPLE && b.getChildCount() == 1)
43 case GraphParser.INT: return paths.Integer;
44 case GraphParser.FLOAT: return paths.Double;
45 case GraphParser.STRING: return paths.String;
46 case GraphParser.TRUE:
47 case GraphParser.FALSE: return paths.Boolean;
48 case GraphParser.VARIANT: return paths.Variant;
49 case GraphParser.ARRAY:
50 if(b.getChildCount() > 0) {
51 switch(b.getChild(0).getType()) {
53 case GraphParser.FLOAT:
54 for(int i=0;i<b.getChildCount();++i)
55 if(b.getChild(i).getType() == GraphParser.FLOAT)
56 return paths.DoubleArray;
57 return paths.IntegerArray;
58 case GraphParser.STRING:
59 return paths.StringArray;
60 case GraphParser.TRUE:
61 case GraphParser.FALSE:
62 return paths.BooleanArray;
70 public Location getLocation() {
71 return ANTLRUtils.location(source, tree);
75 public String toString() {
76 return tree.getText();