Root node problems

Issue #146 resolved
Jesper Öqvist created an issue

I was writing a small grammar for JSON and ran into this problem:

  [jastadd] generating node types and weaving aspects
  [jastadd] Error: No root node available

Here is my grammar:

abstract JsonValue;

abstract JsonLiteral : JsonValue;

JsonFalse : JsonLiteral;

JsonTrue : JsonLiteral;

JsonNull : JsonLiteral;

JsonObject : JsonValue ::= Member:JsonMember*;

JsonArray : JsonValue ::= Value:JsonValue*;

JsonNumber : JsonValue ::= <Value>;

JsonString : JsonValue ::= <Value>;

JsonMember ::= <Name> Value:JsonValue;

The strange thing is that if JsonLiteral doesn't inherit from JsonValue then I don't get the "No root node available" error. Why? Also, what is a root node and why is it needed?

Comments (3)

  1. Jesper Öqvist reporter

    The root node seems to only be used for collection attributes, and it is the node where the collecting should start. It seems unnecessary to require a root node even when not using collection attributes.

    JastAdd could generate an error for collection attributes that don't have a root node instead of always complaining if there is no default root node available. Currently, collection attributes can specify an explicit root node in their declaration, so even when using collection attributes it's not necessarily a problem that the default root node is unknown.

  2. Jesper Öqvist reporter

    The reason there is no root nodes in the above grammar when JsonLiteral is a subtype of JsonValue is because JsonLiteral can then be a child of JsonArray or JsonMember.

  3. Jesper Öqvist reporter

    The question of whether or not root nodes should be required in all grammars is a different issue.

  4. Log in to comment