How to define escape sequence and character literal using Irony?

739 views Asked by At

I'm implementing a grammar that has some rules like this:

char-literal    ::= ' regular-char '  
    ∣    ' escape-sequence '  

escape-sequence ::= \ ( \ ∣  " ∣  ' ∣  n ∣  t ∣  b ∣  r ∣  space )  
    ∣    \ (0…9) (0…9) (0…9)  
    ∣    \x (0…9∣ A…F∣ a…f) (0…9∣ A…F∣ a…f) 

The point is that, I don't know how to define character literal using Irony. Any idea?

1

There are 1 answers

0
Erti-Chris Eelmaa On BEST ANSWER

You can take a look a Irony samples, they are included by default.

The C# Irony grammar has already an example:

StringLiteral CharLiteral = TerminalFactory.CreateCSharpChar("CharLiteral");

The implementation looks something like this:

public static StringLiteral CreateCSharpChar(string name) { StringLiteral term = new StringLiteral(name, "'", StringOptions.IsChar); return term; }