haskell / alex

A lexical analyser generator for Haskell
https://hackage.haskell.org/package/alex
BSD 3-Clause "New" or "Revised" License
297 stars 82 forks source link

Implement %encoding directive #81

Closed hvr closed 8 years ago

hvr commented 8 years ago

This addresses the motivating use-case behind #66 by implementing a new directive which is inspired by the existing %wrapper directive. The encoding string is matched case insensitive. Supported examples:

%encoding "utf-8"
%encoding "iso-8859-1"
%encoding "UTF8"
%encoding "Latin1"

Moreover, some logic has been added to abort if the combination of CLI --latin1 flags and %encoding directives contradict each other. For instance, setting --latin1 on the command-line while requesting %encoding "utf8" in the Alex script causes Alex to abort with an error.