s-cargot-0.1.6.0: A flexible, extensible s-expression library.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.SCargot.Common

Contents

- Numeric Literal Parsers
  - Numeric Literals for Arbitrary Bases
  - Source locations

Synopsis

- parseR5RSIdent :: Parser Text
- parseR6RSIdent :: Parser Text
- parseR7RSIdent :: Parser Text
- parseXIDIdentStrict :: Parser Text
- parseXIDIdentGeneral :: Parser Text
- parseHaskellIdent :: Parser Text
- parseHaskellVariable :: Parser Text
- parseHaskellConstructor :: Parser Text
- signed :: Num a => Parser a -> Parser a
- prefixedNumber :: Parser Integer
- signedPrefixedNumber :: Parser Integer
- binNumber :: Parser Integer
- signedBinNumber :: Parser Integer
- octNumber :: Parser Integer
- signedOctNumber :: Parser Integer
- decNumber :: Parser Integer
- signedDecNumber :: Parser Integer
- dozNumber :: Parser Integer
- signedDozNumber :: Parser Integer
- hexNumber :: Parser Integer
- signedHexNumber :: Parser Integer
- commonLispNumberAnyBase :: Parser Integer
- gnuM4NumberAnyBase :: Parser Integer
- data Location = Span !SourcePos !SourcePos
- data Located a = At !Location a
- located :: Parser a -> Parser (Located a)
- dLocation :: Location

# Documentation

This module contains a selection of parsers for different kinds of identifiers and literals, from which more elaborate parsers can be assembled. These can afford the user a quick way of building parsers for different atom types.

parseR5RSIdent :: Parser Text Source #

Parse an identifier according to the R5RS Scheme standard. This will not normalize case, even though the R5RS standard specifies that all identifiers be normalized to lower case first.

An R5RS identifier is, broadly speaking, alphabetic or numeric and may include various symbols, but no escapes.

parseR6RSIdent :: Parser Text Source #

Parse an identifier according to the R6RS Scheme standard. An R6RS identifier may include inline hexadecimal escape sequences so that, for example, `foo` is equivalent to `f\x6f;o`, and is more liberal than R5RS as to which Unicode characters it may accept.

parseR7RSIdent :: Parser Text Source #

Parse an identifier according to the R7RS Scheme standard. An R7RS identifier, in addition to a typical identifier format, can also be a chunk of text surrounded by vertical bars that can contain spaces and other characters. Unlike R6RS, it does not allow escapes to be included in identifiers unless those identifiers are surrounded by vertical bars.

parseXIDIdentStrict :: Parser Text Source #

Parse an identifier of unicode characters of the form `XID_Start XID_Continue*`, which corresponds strongly to the identifiers found in most C-like languages. Note that the `XID_Start` category does not include the underscore, so `__foo` is not a valid XID identifier. To parse identifiers that may include leading underscores, use `parseXIDIdentGeneral`.

parseXIDIdentGeneral :: Parser Text Source #

Parse an identifier of unicode characters of the form `(XID_Start | '_') XID_Continue*`, which corresponds strongly to the identifiers found in most C-like languages. Unlike `parseXIDIdentStrict`, this will also accept an underscore as leading character, which corresponds more closely to programming languages like C and Java, but deviates somewhat from the <http://unicode.org/reports/tr31/ Unicode Identifier and Pattern Syntax standard>.

parseHaskellIdent :: Parser Text Source #

Parse a Haskell identifer: a sequence of alphanumeric characters, underscores, or a single quote. This matches both variable and constructor names.

parseHaskellVariable :: Parser Text Source #

Parse a Haskell variable identifier: a sequence of alphanumeric characters, underscores, or single quote that begins with a lower-case letter.

parseHaskellConstructor :: Parser Text Source #

Parse a Haskell constructor: a sequence of alphanumeric characters, underscores, or single quote that begins with an upper-case letter.

# Numeric Literal Parsers

signed :: Num a => Parser a -> Parser a Source #

Given a parser for some kind of numeric literal, this will attempt to parse a leading `+` or a leading `-` followed by the numeric literal, and if a `-` is found, negate that literal.

prefixedNumber :: Parser Integer Source #

Parses a number, determining which numeric base to use by examining the literal's prefix: `0x` for a hexadecimal number, `0z` for a dozenal number, `0o` for an octal number, and `0b` for a binary number (as well as the upper-case versions of the same.) If the base is omitted entirely, then it is treated as a decimal number.

signedPrefixedNumber :: Parser Integer Source #

Parses a number in the same way as `prefixedNumber`, with an optional leading `+` or `-`.

binNumber :: Parser Integer Source #

A parser for non-signed binary numbers

signedBinNumber :: Parser Integer Source #

A parser for signed binary numbers, with an optional leading `+` or `-`.

octNumber :: Parser Integer Source #

A parser for non-signed octal numbers

signedOctNumber :: Parser Integer Source #

A parser for signed octal numbers, with an optional leading `+` or `-`.

decNumber :: Parser Integer Source #

A parser for non-signed decimal numbers

signedDecNumber :: Parser Integer Source #

A parser for signed decimal numbers, with an optional leading `+` or `-`.

dozNumber :: Parser Integer Source #

A parser for non-signed duodecimal (dozenal) numbers. This understands both the ASCII characters ``a`` and ``b`` and the Unicode characters `'x218a'` (↊) and `'x218b'` (↋) as digits with the decimal values `10` and `11` respectively.

signedDozNumber :: Parser Integer Source #

A parser for signed duodecimal (dozenal) numbers, with an optional leading `+` or `-`.

hexNumber :: Parser Integer Source #

A parser for non-signed hexadecimal numbers

signedHexNumber :: Parser Integer Source #

A parser for signed hexadecimal numbers, with an optional leading `+` or `-`.

## Numeric Literals for Arbitrary Bases

commonLispNumberAnyBase :: Parser Integer Source #

A parser for Common Lisp's arbitrary-base number syntax, of the form `#[base]r[number]`, where the base is given in decimal. Note that this syntax begins with a `#`, which means it might conflict with defined reader macros.

gnuM4NumberAnyBase :: Parser Integer Source #

A parser for GNU m4's arbitrary-base number syntax, of the form `0r[base]:[number]`, where the base is given in decimal.

## Source locations

data Location Source #

Constructors

Span !SourcePos !SourcePos |

#### Instances

Instances details

Show Location Source # |
Instance details Defined in Data.SCargot.Common Methods showsPrec :: Int -> Location -> ShowS Source # show :: Location -> String Source # showList :: [Location] -> ShowS Source #
Eq Location Source # |
Instance details Defined in Data.SCargot.Common Methods (==) :: Location -> Location -> Bool Source # (/=) :: Location -> Location -> Bool Source #
Ord Location Source # |
Instance details Defined in Data.SCargot.Common Methods compare :: Location -> Location -> Ordering Source # (<) :: Location -> Location -> Bool Source # (<=) :: Location -> Location -> Bool Source # (>) :: Location -> Location -> Bool Source # (>=) :: Location -> Location -> Bool Source # max :: Location -> Location -> Location Source # min :: Location -> Location -> Location Source #

data Located a Source #

Add support for source locations while parsing S-expressions, as described in this Reddit thread.

Constructors

At !Location a |

#### Instances

Instances details

IsString (Located HaskLikeAtom) Source # |
Instance details Defined in Data.SCargot.Language.HaskLike Methods fromString :: String -> Located HaskLikeAtom Source #
Show a => Show (Located a) Source # |
Instance details Defined in Data.SCargot.Common Methods showsPrec :: Int -> Located a -> ShowS Source # show :: Located a -> String Source # showList :: [Located a] -> ShowS Source #
Eq a => Eq (Located a) Source # |
Instance details Defined in Data.SCargot.Common Methods (==) :: Located a -> Located a -> Bool Source # (/=) :: Located a -> Located a -> Bool Source #
Ord a => Ord (Located a) Source # |

Instance details

Defined in Data.SCargot.Common

Methods

compare :: Located a -> Located a -> Ordering Source #

(<) :: Located a -> Located a -> Bool Source #

(<=) :: Located a -> Located a -> Bool Source #

(>) :: Located a -> Located a -> Bool Source #

(>=) :: Located a -> Located a -> Bool Source #

max :: Located a -> Located a -> Located a Source #

min :: Located a -> Located a -> Located a Source #

located :: Parser a -> Parser (Located a) Source #

Adds a source span to a parser.

dLocation :: Location Source #

A default location value