You can use lexeme with quotes, but trigger quotes in the parser
Lexer:
let constant = ("'" ([^ '\''])* "'") ... | constant { STRING(lexeme lexbuf) }
Parser:
%token <string> STRING ... constant: | STRING { ($1).Trim([|'''|]) }
Or , if you want to extract quotes from a string:
Lexer:
let name = alpha (alpha | digit | '_')* let identifier = name ('.' name)* ... | '\'' { QUOTE } | identifier { ID (lexeme lexbuf) } | _ { STRING (lexeme lexbuf) }
Identifier
will display characters from STRING, so your lexeme stream might look like: QUOTE ID STRING ID .. QUOTE, and you should handle this in the parser:
Parser:
constant: | QUOTE content QUOTE { String($2) } content: | ID content { $1+$2 } | STRING content { $1+$2 } | ID { $1 } | STRING { $1 }
source share