picty / parsifal

Parsifal : an OCaml-based parsing engine
Other
61 stars 8 forks source link

Allow for more flexible enum patterns #11

Closed pictyeye closed 10 years ago

pictyeye commented 10 years ago

Two simple patterns should be recognized : the multiple pattern and the interval.

Exemple of multiple pattern from tar.ml

enum file_type (8, UnknownVal UnknownFileType) =
  | 0 | 0x30 -> NormalFile

Exemple of interval pattern from dvi.ml

| 250 .. 255 -> OP_Undefined, "Undefined opcode"

Other ideas would be to allow for non-constant constructors in enums, for example, in dvi.ml :

| 0 .. 127 as i -> OP_Char i, "Char"

but this would need changes in the internal enum representation and for now, the case has only been encountered in DVI file format.

pictyeye commented 10 years ago

The first patterns "| x | y ->" is easy to implement.

Concerning ranges, "| x .. y ->" can not directly be parsed by camlp4, so the pattern representing ranges will be "| x, y ->"

The last idea will be left as a possible future enhancement in another ticket.