forked from ion-fusion/fusion-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleSyntaxValue.java
More file actions
124 lines (102 loc) · 3.17 KB
/
Copy pathSimpleSyntaxValue.java
File metadata and controls
124 lines (102 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright Ion Fusion contributors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package dev.ionfusion.fusion;
import static dev.ionfusion.runtime._private.util.Empties.EMPTY_OBJECT_ARRAY;
import com.amazon.ion.IonException;
import com.amazon.ion.IonWriter;
import dev.ionfusion.runtime.base.FusionException;
import dev.ionfusion.runtime.base.ResourcePosition;
import java.io.IOException;
/**
* Implementation of most {@link SyntaxValue}s, which consist of a simple
* wrapped datum.
*/
class SimpleSyntaxValue
extends SyntaxValue
{
final BaseValue myDatum;
/**
* @param pos can be null.
* @param properties must not be null.
* @param datum must not be null and must not be a {@link SyntaxValue}.
*/
SimpleSyntaxValue(ResourcePosition pos, Object[] properties, BaseValue datum)
{
super(pos, properties);
assert ! (datum instanceof SyntaxValue);
myDatum = datum;
}
/**
* @param pos may be null.
* @param datum must not be null and must not be a {@link SyntaxValue}.
*/
SimpleSyntaxValue(ResourcePosition pos, BaseValue datum)
{
this(pos, EMPTY_OBJECT_ARRAY, datum);
}
/**
* @param pos may be null.
* @param datum must not be null and must not be a {@link SyntaxValue}.
*/
static SyntaxValue makeOriginalSyntax(Evaluator eval,
ResourcePosition pos,
BaseValue datum)
{
return new SimpleSyntaxValue(pos, ORIGINAL_STX_PROPS, datum);
}
/**
* @param pos may be null.
* @param datum must not be null and must not be a {@link SyntaxValue}.
*/
static SyntaxValue makeSyntax(Evaluator eval,
ResourcePosition pos,
BaseValue datum)
{
return new SimpleSyntaxValue(pos, datum);
}
/**
* @param pos may be null.
* @param datum must be a Fusion value but not a {@link SyntaxValue}.
*/
static SyntaxValue makeSyntax(Evaluator eval,
ResourcePosition pos,
Object datum)
{
return new SimpleSyntaxValue(pos, (BaseValue) datum);
}
//========================================================================
@Override
Object visit(Visitor v) throws FusionException
{
return v.accept(this);
}
@Override
SyntaxValue copyReplacingProperties(Object[] properties)
{
return new SimpleSyntaxValue(getLocation(), properties, myDatum);
}
@Override
Object unwrap(Evaluator eval)
throws FusionException
{
return myDatum;
}
@Override
Object syntaxToDatum(Evaluator eval)
throws FusionException
{
return myDatum;
}
@Override
void ionize(Evaluator eval, IonWriter writer)
throws IOException, IonException, FusionException
{
myDatum.ionize(eval, writer);
}
@Override
final void write(Evaluator eval, Appendable out)
throws IOException, FusionException
{
myDatum.write(eval, out);
}
}