nitra
nitra copied to clipboard
Mapping not possible with syntax rules defined in other assembly
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.
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 typeExternalParsedSimpleRuleSymbol
instad or makeExternalSimpleRuleSymbol
overrrideAddSyntaxMapping()
.
Any input would be appreciated.
Unfortunately mapping cannot be placed in a external assembly. Mapping must be declared in assembly which contains grammar (syntax module).
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:
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.
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.