Parse character representation in Jison/Javascript

I'm coding a C++ grammar in Jison and I've managed to correctly detect character literals with this regex:

\'([^\\\']|\\.)\'  return 'CHAR_LIT'

and then add it to the AST like this:

    {$$ = new yy.Ast('CHAR_LIT', [$1])}

However, with the input string literal '\n' the value of $1 evaluates to its string representation "'\\n'" rather than its actual character value "\n", which is what I want.

Is there any way to tell Jison that I want the character value rather than its representation? Otherwise, what is the best way in Javascript to parse a string with a character representation into its corresponding character value, for instance parse "\\t" into "\t"?



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.