Created
December 21, 2020 06:48
-
-
Save dmjio/ecde57811cd8d254da2b725d9597ccb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
module Lexer98 ( scanTokens ) where | |
import Data.Text (Text) | |
import qualified Data.Text as Text | |
} | |
%wrapper "basic" | |
$special = [ \( \) \, \; \[ \] \` \{ \} ] | |
$return = \r | |
$linefeed = \n | |
$vertab = \v | |
$formfeed = \f | |
$space = \ | |
$tab = \t | |
$ascSmall = [a-z] | |
$small = [$ascSmall \_] | |
$ascLarge = [A-Z] | |
$large = [$ascLarge \_] | |
$ascDigit = [0..9] | |
$octit = [0..8] | |
$ascSymbol = [\!\#\$\%\&\*\+\.\/\<\=\>\?\@\\\^\|\-\~] | |
$symbol = $ascSymbol | |
$digit = $ascDigit | |
$hexit = [0-9a-fA-F] | |
@whitespace = $white | |
@newline = $return $linefeed | $return | $linefeed | $formfeed | |
@graphic = $small | $large | $symbol | $digit | $special | [\:\"\'] | |
@any = @graphic | $space | $tab | |
$dash = \- | |
@dashes = $dash $dash+ | |
@comment = @dashes .* $linefeed | |
@opencom = \{ \- | |
@closecom = \- \} | |
@reservedop = ".." | \: | "::" | \= | \\ | "<-" | "->" | \@ | \~ | "=>" | |
@decimal = $digit+ | |
@octal = $octit+ | |
@hexadecimal = $hexit+ | |
@integer = @decimal | \0 [oO] @octal | 0 [xX] @hexadecimal | |
@exponent = [eE] [\+\-] @decimal | |
@float = @decimal \. @decimal @exponent? | |
| @decimal @exponent | |
$charesc = [abfnrtv\\\"'&] | |
$cntrl = [A-Z@\[\\\]\^_] | |
@ascii = \^ $cntrl | |
| NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | |
| BS | HT | LF | VT | FF | CR | SO | SI | |
| DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | |
| CAN | EM | SUB | ESC | FS | GS | RS | US | |
| SP | DEL | |
@escape = $charesc | |
| @ascii | |
| @decimal | |
| o @octal | |
| x @hexadecimal | |
@gap = \\ $white+ \\ | |
@char = \' (@graphic (\'{0} | \\'{0}) | $space | (@escape \\{0} \&{0})) \' | |
@string = \" (@graphic (\"{0} | \\'{0}) | $space | @escape | @gap)* \" | |
@reservedid = case | class | data | default | deriving | do | |
| else | if | import | in | infix | infixr | |
| infixl | instance | let | module | newtype | |
| of | then | type | where | \_ | |
@varid = ($small ($small | $large | $digit | \')*) @reservedid{0} | |
@conid = $large ($small | $large | $digit | \`)* | |
@varsym = $symbol ($symbol | \:)* @reservedid{0} @dashes{0} | |
@consym = \: ($symbol | \:)* @reservedid{0} | |
@literal = @integer | @float | @char | @string | |
@tyvar = @varid | |
@tycon = @conid | |
@tycls = @conid | |
@modid = @conid | |
@qvarid = (modid \.)? varid | |
@qconid = (modid \.)? conid | |
@qtycon = (modid \.)? tycon | |
@qtycls = (modid \.)? tycls | |
@qvarsym = (modid \.)? varsym | |
@qconsym = (modid \.)? consym | |
haskell98 :- | |
$white; | |
{ | |
main = pure () | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment