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

Safe HaskellSafe
LanguageHaskell2010

Data.SCargot.Common

Contents

Synopsis

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.