haskellator-0.1.0.0: SI-Units supporting calculator
Safe HaskellSafe-Inferred
LanguageHaskell2010

Math.Haskellator.Internal.Lexer

Description

Tokenizes an input stream to a list of Tokens

Arithmetic examples:

>>> scan "1+2"
Right [Number 1.0,Operator "+",Number 2.0]
>>> scan "(3/2+(1.5*2)) + 4.95"
Right [OpenParen,Number 3.0,Operator "/",Number 2.0,Operator "+",OpenParen,Number 1.5,Operator "*",Number 2.0,CloseParen,CloseParen,Operator "+",Number 4.95]
>>> scan "9001*29.12"
Right [Number 9001.0,Operator "*",Number 29.12]

Examples with units:

>>> scan "2km [m]"
Right [Number 2.0,Identifier "km",OpenBracket,Identifier "m",CloseBracket]

Examples with variables:

>>> scan "a = 3, b = 2 -> a + b"
Right [Identifier "a",Equal,Number 3.0,Comma,Identifier "b",Equal,Number 2.0,Arrow,Identifier "a",Operator "+",Identifier "b"]
Synopsis

Documentation

data Token Source #

Constructors

Number Double

A number (integers are also represented as floats)

Operator String

An operator

OpenParen

Open parenthesis "("

CloseParen

Close parenthesis ")"

OpenBracket

Open bracket "["

CloseBracket

Close bracket "]"

Identifier String

Identifier (e.g. variable and function name) or unit

Arrow

Arrow "->"

Equal

Single equal sign "="

Comma

Comma ","

Instances

Instances details
Show Token Source # 
Instance details

Defined in Math.Haskellator.Internal.Lexer

Methods

showsPrec :: Int -> Token -> ShowS #

show :: Token -> String #

showList :: [Token] -> ShowS #

Eq Token Source # 
Instance details

Defined in Math.Haskellator.Internal.Lexer

Methods

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

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

type Tokens = [Token] Source #

A simple alias for the Token stream

scan Source #

Arguments

:: String

The input stream

-> Either Error Tokens

Error message or the list of tokens

Tokenizes an input stream to a list of Tokens