ANTLR for C# and CLSCompliant attribute
Asked Answered
C

2

9

I'm using ANTLR V3 to produce C# code for DSL language.

The produced code contain the attribute CLSCompliant on both laxer and parser classes which cause a warning to be generated because my project is not CLS compliant.

  1. How can I make ANTLR produce code without the CLSCompliant attribute?
  2. Is it possible to change the string template of C# 3 grammar?
Carouse answered 21/12, 2011 at 13:16 Comment(0)
T
16

I guess you've figured out the easy workaround by now which consists in disabling the corresponding warning (and saves you from fiddling with the templates).

Simply add the following to your grammar file

@parser::header {#pragma warning disable 3021}
@lexer::header {#pragma warning disable 3021}

HTH Gabriel

Tetragram answered 3/1, 2012 at 18:56 Comment(1)
I believe @header {#pragma warning disable 3021} will add the pragma to both the parser and the lexer files, rather than needing two separate lines.Literatim
I
8

Instead of suppressing the warnings, it's correct to explicitly state that the assembly is not CLS compliant using an attribute in AssemblyInfo.cs:

[assembly: CLSCompliant(false)]

This will remove the warnings at compilation as well.

Implicit answered 29/1, 2018 at 15:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.