Questions tagged [alex]

A lexical analyser generator for Haskell

Alex is a tool for generating lexical analysers in Haskell, given a description of the tokens to be recognised in the form of regular expressions. It is similar to the tool lex or flex for C/C++. Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing.

Note: Alex is part of the Haskell Platform, thus when you install the platform you will automatically have a working Alex. The Haskell Platform is a single, standard Haskell development environment for everyone. It offers a set of blessed libraries and tools, to save you the task of picking and choosing which core Haskell libraries to use.

61 questions
1
vote
1 answer

Alex requies the result token type to be some function that takes a AlexPosn

I'm trying to write a lexer that lexes c-style comments and nothing else(for now). { module Lexer where import Prelude hiding (head, take, tail) import Data.ByteString.Lazy } %wrapper "monad-bytestring" @not_bc_end = ~\* | \* ~\/ tl :- <0> …
Poscat
  • 565
  • 3
  • 15
1
vote
1 answer

Haskell source generated by happy has error "parse error on input 'data'"

I'm trying out the happy parser generator of Haskell. After generating the module in happy.hs (no problem while generating!), I run the command ghc happy.hs, and I get the error: Line 297: parse error on input 'data'. Does anyone have solutions? Or…
1
vote
0 answers

Alex monad wrapper difference between ; and skip

Using the monadwrapper in alex, it seems you can skip using either ; or the {skip} action. They generate different code, but I can't seem to find the difference. Why is this obvious question not addressed in the documentation?
cxandru
  • 158
  • 8
1
vote
1 answer

Amazon Echo Account Linking - how to identify echo device when generating and saving token?

I have a pre-existing web app with user accounts. I want to extend functionality with Amazon's echo. When the user enables the skill in their Echo/Alexa dashboard, it will redirect them to the login page of my app with Authorization URL…
dman
  • 10,406
  • 18
  • 102
  • 201
1
vote
1 answer

Happy & Alex - Preventing the lookahead from affecting parser-lexer communication

I am currently writing the parser for a compiler of a toy language using Happy & Alex. Since some form of optional layout is required I have to change Alex's state before matching the block non-terminal. Unfortunately it seems that the lookahead…
1
vote
0 answers

Haskell - Alex lexer - handle whitespace and newlines as state

I'm writing a parser for a language in Haskell with Alex + Happy. What I want to do is: in Alex, skip whitespaces and newlines, but keep them as state, and then emit tokens which contain the newlines and the indent before the token. I guess I could…
theduke
  • 3,027
  • 4
  • 29
  • 28
1
vote
1 answer

Alex wrappers.hs no instance of Applicative

I am trying to compile a lex.x with ghc 7.10.2 and alex 3.1.4, but it is giving the below error. I checked Lex.hs and indeed there is no applicative instance for 'Alex' there. Note: This error started coming after I moved from wrapper 'monad' to…
dfordivam
  • 169
  • 1
  • 6
1
vote
1 answer

How to specify tab width for Alex lexer?

Alex documentation (Chapter 5) says: You might want Alex to keep track of the line and column number in the input text, or you might wish to do it yourself (perhaps you use a different tab width from the standard 8-columns, for example) But…
danbst
  • 3,363
  • 18
  • 38
1
vote
1 answer

Alex, Happy, Cabal, and Re-preprocessing

I am using Alex 3.0.5, Happy 1.18.10, Cabal 1.16.0.2 I have a small compiler project that is built using Cabal. I am exposing the compiler's internals as a library, so I have in the exposed modules section, MyLangLex and MyLangPar. If I delete the…
Jonathan Gallagher
  • 2,115
  • 2
  • 17
  • 31
1
vote
1 answer

Use Alex macros from another file

Is there any way to have an Alex macro defined in one source file and used in other source files? In my case, I have definitions for $LowerCaseLetter and $UpperCaseLetter (these are all letters except e and O, since they have special roles in my…
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
1
vote
1 answer

Why does the lexer rule for strings takes precedence over all my other rules?

Using the Alex lexer I am creating a lexer to tokenize email "From headers." Here is an example header: From: "John Doe" "John Doe" is called the "display name" and let's assume that it can consist of any ASCII characters. Likewise…
Roger Costello
  • 3,007
  • 1
  • 22
  • 43
1
vote
1 answer

How to tokenize a string with an embedded string?

I am learning how to use the Haskell lexical analyzer tool called Alex1. I am trying to implement a lexical analyzer for this string (an email "From:" header): From: "John Doe" I want to break it up into this list of tokens: [ …
Roger Costello
  • 3,007
  • 1
  • 22
  • 43
0
votes
2 answers

Haskell data type pattern matching in Alex

Suppose I have a data type in Haskell like this: data Token = THEN AlexPosn | ELSE AlexPosn from Alex, I get that: data AlexPosn = AlexPn !Int !Int !Int deriving (Eq,Show) I am able to do pattern matching like this: eat_token ::…
Alberto_Saavedra
  • 389
  • 1
  • 2
  • 12
0
votes
0 answers

GetWeeklySchedule directive not being sent by Amazon

I have my own nodejs alexa interface with AWS/skill and I've made a thermostat. I can't figure out how to get alexa to send the GetWeeklySchedule directive. This is working and I get back setpoint, currrent temperature, and Controlled BY Schedule in…
John Smith
  • 3,493
  • 3
  • 25
  • 52
0
votes
0 answers

What may cause alex package build failure?

So I was trying to set up a Haskell project (ghcup-hs to be precise) but all attempts at building it, be it just cabal run or using HLS in VSCode, fail at alex package. In the terminal, it says "Building", my computer gets hot and loud, and then I…
charrsky
  • 11
  • 2