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