.NET Framework Developer Center > .NET Development Forums > Microsoft SQL Server Modeling > Parsing Quoted text wich contains Quotes with escape sequence
Ask a questionAsk a question
 

AnswerParsing Quoted text wich contains Quotes with escape sequence

  • Thursday, October 22, 2009 6:09 AMMichael Ani Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    How to parse a quoted text that contains a quote with escape charactor.
    Eg.  "Quoted\"this\"text"
    I have seen lot of example for parsiing quoted identifier which can not conatain nested quotes.

    Thanks,
    Michael

Answers

All Replies

  • Thursday, October 22, 2009 1:40 PMjustncase80 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    It's built-in to some of the core grammars. Just add this to your language:

    final token String
               = Language.Grammar.TextLiteral;
  • Friday, October 23, 2009 5:30 AMMichael Ani Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    My specific requirement is to contain quote characters within a string. Using "TextLiiteral" is forcing the input stream to have "\" escape charactor before teh firs quote also.
    Input Stream example are : 23 23 "Test.SomeValue=\"3333\"" , 
                                             if(24 35 "Test.SomeValue=\"65500\"||Test.SomeValue=\"65007\"||Test.SomeValue=\"65857\"||)

    Finally I used following syntax to resolve this. I don't know it is correct or not. but is working for time being.

            token QuotedIdentifier ='"' i:(Text* (QuotedTextEscape|Text)* Text*) '"' =>i;
            token Text = ^('"' );
            token QuotedTextEscape = "\\\"" Text* "\\\""; 
  • Friday, October 23, 2009 2:35 PMjustncase80 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    That's sort of surprising... you might have something else going on such as a token conflict because I'm pretty sure TextLiteral should match things such as "Test\"3333\"".