hpp-0.3.1.0: A Haskell pre-processor

Safe HaskellSafe
LanguageHaskell2010

Hpp.Tokens

Description

Tokenization breaks a String into pieces of whitespace, constants, symbols, and identifiers.

Synopsis

Documentation

data Token Source #

Tokenization is words except the white space is tagged rather than discarded.

Constructors

Important String

Identifiers, symbols, and constants

Other String

White space, etc.

Instances

Eq Token Source # 

Methods

(==) :: Token -> Token -> Bool #

(/=) :: Token -> Token -> Bool #

Ord Token Source # 

Methods

compare :: Token -> Token -> Ordering #

(<) :: Token -> Token -> Bool #

(<=) :: Token -> Token -> Bool #

(>) :: Token -> Token -> Bool #

(>=) :: Token -> Token -> Bool #

max :: Token -> Token -> Token #

min :: Token -> Token -> Token #

Show Token Source # 

Methods

showsPrec :: Int -> Token -> ShowS #

show :: Token -> String #

showList :: [Token] -> ShowS #

detok :: Token -> String Source #

Extract the contents of a Token.

isImportant :: Token -> Bool Source #

True if the given Token is Important; False otherwise.

notImportant :: Token -> Bool Source #

True if the given Token is not Important; False otherwise.

importants :: [Token] -> [String] Source #

Return the contents of only Important (non-space) tokens.

trimUnimportant :: [Token] -> [Token] Source #

Trim Other Tokens from both ends of a list of Tokens.

newLine :: Token -> Bool Source #

Is a Token a newline character?

tokWords :: String -> [Token] Source #

Break a String into space and non-whitespace runs.

skipLiteral :: ((String -> String) -> String -> r) -> String -> r Source #

If you encounter a string literal, call this helper with a double-barreled continuation and the rest of your input. The continuation will expect the remainder of the string literal as the first argument, and the remaining input as the second argument.

splits :: (Char -> Bool) -> String -> [String] Source #

splits isDelimiter str tokenizes str using isDelimiter as a delimiter predicate. Leading whitespace is also stripped from tokens.

validIdentifierChar :: Char -> Bool Source #

Predicate on space characters based on something approximating valid identifier syntax. This is used to break apart non-space characters.

fixExponents :: [Token] -> [Token] Source #

Something like 12E+FOO is a single pre-processor token, so FOO should not be macro expanded.

tokenize :: String -> [Token] Source #

Break an input String into a sequence of Tokens. Warning: This may not exactly correspond to your target language's definition of a valid identifier!

detokenize :: [Token] -> String Source #

Collapse a sequence of Tokens back into a String. detokenize . tokenize == id.