LinuxCommandLibrary

alex

Analyze text for sensitive data (secrets)

TLDR

Analyze text from stdin

$ echo [His network looks good] | alex --stdin
copy

Analyze all files in the current directory
$ alex
copy

Analyze a specific file
$ alex [path/to/file.md]
copy

Analyze all Markdown files except example.md
$ alex *.md ![example.md]
copy

SYNOPSIS

alex [-o FILE] [-g | -l | -t] [-v] [input.x]

PARAMETERS

-g, --ghc
    Output GHC-optimized Haskell wrapper code

-l, --lex
    Output traditional Unix lex-compatible code

-t, --table
    Output compact table-based code

-o FILE, --output=FILE
    Specify output file (default: input name with .hs extension)

-v, --verbose
    Enable verbose output during generation

-i, --info
    Dump internal representation information

--version
    Display Alex version

--numeric-versions
    Use numeric token codes instead of symbolic

-h, --help
    Show help message

DESCRIPTION

Alex is a tool for generating lexical analyzers in the Haskell programming language. It takes a description of a lexical analyzer in the form of a file containing regular expression rules and associated actions, and outputs a Haskell module implementing a function that performs the lexical analysis.

As a fast and efficient lexer generator, Alex supports multiple output formats, including standard Haskell code, GHC-specific optimizations, and even compatibility with traditional Unix lex tools. It uses a table-based approach for quick tokenization, handling input streams efficiently without backtracking by default, though custom handling is possible.

Users define tokens using regular expressions similar to lex/flex syntax, with semantic actions in Haskell code. Alex processes these into an optimized state machine. It's widely used in Haskell parser combinators like Parsec or with parser generators like Happy.

Installation typically via Cabal or Stack: cabal install alex. Ideal for compiler frontends, interpreters, and any Haskell project needing custom tokenization. Supports Unicode and handles large inputs effectively.

CAVEATS

Requires Haskell toolchain (GHC); not a core Linux utility. Input files must use .x extension convention. Generated code assumes strict evaluation unless customized.

BASIC USAGE

alex lexer.x generates Lexer.hs implementing alexScanTokens function.
Example rule: \d+ { \s -> read $! s }

INPUT FORMAT

Uses lex-like syntax: definitions section, rules section with regex { action }, and user code wrappers.

HISTORY

Developed by Duncan Coutts starting in 2003 as a Haskell-native alternative to lex/flex. Maintained by Well-Typed and the Haskell community; current versions (e.g., 3.2.x) support GHC 9+ and modern Haskell features.

SEE ALSO

happy(1), lex(1), flex(1), parsec(3)

Copied to clipboard