sedlex icon indicating copy to clipboard operation
sedlex copied to clipboard

Support of `as`

Open chengtie opened this issue 4 years ago • 1 comments

I'm new to sedlex. I'm translating a lexer in ocamllex to sedlex. By ocamllex, I have e.g.,

rule token = parse
  | FLOAT as float "%"           { DOUBLE ((float_of_string float) /. 100. ) } 

Now, I need to use some string operations to achieve it:

let rec token buf =
  match%sedlex buf with
    | FLOAT, "%" ->  
      let x = Sedlexing.Utf8.lexeme buf in
      let x = String.sub x 0 (String.length x -1) in
      DOUBLE ((float_of_string x) /. 100. )

I'm wondering if we could simplify that, e.g., by using as like in ocamllex.

chengtie avatar Aug 12 '21 03:08 chengtie

Duplicate of #5

hhugo avatar Aug 12 '21 06:08 hhugo