CPARSEC3 Parsec library provides functionality of parser-combinators.
- NOTE : Parsec library is UNDER CONSTRUCTION.
Generic Data Type is a parametric typed struct/union.
Generic Data Type is a similar concept as known as parameterized type, polymorphic type, template class (C++), and so on.
The below sections show Generic Data Types provided by CPARSEC3 Parsec library.
- Parsec(S, T)
-
A parser object that tries to take token(s) from a stream of type
Sand returns a corresponding value of typeTwhen it was applied to a stream successfully.
See alsoParsecT(S, T)trait.
- Token(S)
-
A token, which was taken from a stream of type
S.
See alsoStream(S)trait.
- Tokens(S)
-
A chunk of tokens, which was taken from a stream of type
S.
See alsoStream(S)trait.
Trait provides a set of functions against a particular concrete type.
Trait is a similar concept as known as type class (Haskell), trait (Rust), interface (Java), and so on.
To use Trait, calling to trait(M) creates a concrete trait object.
The below sections show Traits provided by CPARSEC3 Parsec library.
- NOTE : Not implemented yet.
/* String is an instance of Stream */
Stream(String) s = trait(Stream(String));
Maybe(Tuple(Token(String), String)) r = s.take1("abc");
assert(!r.none);
assert(g_eq(r.value.e1, 'a')); /* a token */
assert(g_eq(r.value.e2, "bc")); /* rest of the stream */- Stream(S)
-
Type of a trait that provides a set of functions to take token of
Token(S)type and/or chunk of tokens ofTokens(S)type from a stream ofStype. - trait(Stream(S))
-
Constructs a new trait of
Stream(S)type.
For example,trait(Stream(String))creates an object ofStream(String)type.
A Stream(S) trait provides the following member functions :
- bool empty(S s)
-
Returns
trueif the streamswas empty,falseotherwise. - Maybe(Tuple(Token(S), S)) take1(S s)
-
Try to take a token from the stream
s.- If the stream
swas empty, returnsmthat satisfies the following :m.none=true.
- Otherwise returns
mthat satisfies the following :m.none=false.m.value.e1is the 1st token ofToken(S)type.m.value.e2is the rest of the streams.
- If the stream
- Maybe(Tuple(Tokens(S), S)) takeN(int n, S s)
-
Try to take a chunk of tokens from the stream
s.- If n > 0 and the stream
swas empty, returnsmthat satisfies the following :m.none=true.
- If n > 0 and the stream
swas NOT empty, returnsmthat satisfies the following :m.none=false.m.value.e1is a chunk of tokens ofTokens(S)type, ofnlength at most.m.value.e2is the rest of the streams.
- If n ≤ 0, returns
mthat satisfies the following :m.none=falsem.value.e1is a chunk of tokens ofTokens(S)type, of 0 length.m.value.e2is the streams.
- If n > 0 and the stream