summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java121
-rw-r--r--src/core/src/tonkadur/fate/v1/parser/FateParser.g45
2 files changed, 124 insertions, 2 deletions
diff --git a/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java b/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java
new file mode 100644
index 0000000..60f5efb
--- /dev/null
+++ b/src/core/src/tonkadur/fate/v1/lang/computation/AmbiguousWord.java
@@ -0,0 +1,121 @@
+package tonkadur.fate.v1.lang.computation;
+
+import tonkadur.parser.Origin;
+
+import tonkadur.fate.v1.parser.ParserData;
+
+import tonkadur.fate.v1.lang.type.Type;
+
+import tonkadur.fate.v1.lang.meta.ComputationVisitor;
+import tonkadur.fate.v1.lang.meta.Computation;
+import tonkadur.fate.v1.lang.meta.VariableFromWord;
+
+public class AmbiguousWord extends Computation
+{
+ /***************************************************************************/
+ /**** MEMBERS **************************************************************/
+ /***************************************************************************/
+ protected final ParserData parser;
+ protected final String as_string;
+ protected Computation result;
+
+ protected void assert_is_resolved ()
+ {
+ if (result == null)
+ {
+ System.err.println("[F] Ambiguous word " + toString() + " at:");
+ System.err.println(get_origin().toString());
+
+ System.exit(-1);
+ }
+ }
+
+ /***************************************************************************/
+ /**** PUBLIC ***************************************************************/
+ /***************************************************************************/
+ /**** Constructors *********************************************************/
+ public AmbiguousWord
+ (
+ final ParserData parser,
+ final Origin origin,
+ final String as_string
+ )
+ {
+ super(origin, Type.ANY);
+
+ this.parser = parser;
+ this.as_string = as_string;
+ result = null;
+ }
+
+ /**** Accessors ************************************************************/
+ @Override
+ public void get_visited_by (final ComputationVisitor cv)
+ throws Throwable
+ {
+ assert_is_resolved();
+
+ result.get_visited_by(cv);
+ }
+
+ @Override
+ public Type get_type ()
+ {
+ if (result == null)
+ {
+ return Type.ANY;
+ }
+
+ return result.get_type();
+ }
+
+ @Override
+ public void expect_non_string ()
+ {
+ try
+ {
+ result = VariableFromWord.generate(parser, get_origin(), as_string);
+ }
+ catch (final Throwable t)
+ {
+ t.printStackTrace();
+
+ System.exit(-1);
+ }
+ }
+
+ @Override
+ public void expect_string ()
+ {
+ result = Constant.build_string(get_origin(), as_string);
+ }
+
+ public String get_value_as_string ()
+ {
+ return as_string;
+ }
+
+ /**** Misc. ****************************************************************/
+ @Override
+ public String toString ()
+ {
+ final StringBuilder sb = new StringBuilder();
+
+ sb.append("(AmbiguousWord \"");
+ sb.append(as_string);
+ sb.append("\"");
+
+ if (result == null)
+ {
+ sb.append(" (unresolved))");
+ }
+ else
+ {
+ sb.append(" resolved to ");
+ sb.append(result.toString());
+ sb.append(")");
+ }
+
+ return sb.toString();
+ }
+}
diff --git a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4 b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
index 9400c8b..8c5a052 100644
--- a/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
+++ b/src/core/src/tonkadur/fate/v1/parser/FateParser.g4
@@ -1520,7 +1520,7 @@ returns [Computation result]
{
// convert all computations to text.
// return text node.
- return
+ $result =
new Paragraph
(
$computation_list.result.get(0).get_origin(),
@@ -2063,8 +2063,9 @@ returns [Computation result]
WORD
{
$result =
- AmbiguousWord.build
+ new AmbiguousWord
(
+ PARSER,
PARSER.get_origin_at
(
($WORD.getLine()),