nitra icon indicating copy to clipboard operation
nitra copied to clipboard

Mapping not possible with syntax rules defined in other assembly

Open ssrmm opened this issue 8 years ago • 5 comments

Syntax (defined in first assembly):

namespace Syntax
{
  syntax module Test
  {
    using Nitra.Core;

    [StartRule]
    syntax Foo = "foo";
  }
}

AST and mapping (defined in second assembly):

using Nitra;
using Nitra.Declarations;

namespace Ast
{
  ast Foo {}
}
using Nitra;
using Nitra.Runtime;
using Nitra.Declarations;

namespace Mapping
{
  map syntax Syntax.Test.Foo -> Ast.Foo {}
}

When compiling, this produces the error message error : AST mapping is not allowed here

This seems to be caused here: ruleSymbol is of type Nitra.Typing.ExternalSimpleRuleSymbol (generated from ExportableSymbol macro at SimpleRuleSymbol), whereas it is of type Nitra.Typing.ParsedSimpleRuleSymbol when it is located in the same assembly.

Nitra.Typing.ExternalSimpleRuleSymbol does not implement it's own version of AddSyntaxMapping() and so the generic one of SyntaxRuleSymbol gets chosen and produces the error message.

ssrmm avatar Oct 13 '16 12:10 ssrmm

I'd like to try fixing this, but I think I need some help:

  • I seem unable to find out where ruleSymbol is declared.
  • I'm not sure what's the right thing to do here: make ruleSymbol be of type ExternalParsedSimpleRuleSymbol instad or make ExternalSimpleRuleSymbol overrride AddSyntaxMapping().

Any input would be appreciated.

ssrmm avatar Oct 13 '16 12:10 ssrmm

Unfortunately mapping cannot be placed in a external assembly. Mapping must be declared in assembly which contains grammar (syntax module).

VladD2 avatar Oct 20 '16 13:10 VladD2

OK, so this is rather a new feature then. Would still be cool if it could become available eventually.

I've done a lot of syntax-definitions beforehand, which is probably what most people would naturally do. The syntax can easily take a few minutes to compile. Not having to recompile it every time there is a change related to mapping/AST, could save a ton of time. And a few GB of ram as well... :smile:

ssrmm avatar Oct 20 '16 13:10 ssrmm

How much time does syntax compilation take anyway? My project takes nearly a minute at this point, so I'm thinking about breaking it up.

ionoy avatar Oct 20 '16 14:10 ionoy

I'm currently somewhere around 2:30 minutes for syntax only.

Breaking up the language in logical parts rather then syntax/semantic parts might be worth thinking about.

ssrmm avatar Oct 20 '16 14:10 ssrmm