Home | Libraries | People | FAQ | More |
The kwd[]
and ikwd[]
provide a powerful and flexible mechanism for parsing keyword based input.
It works in conjuction with the / operator to create an effective keyword
parsing loop. The keyword parsing loop doesn't require the keywords to
appear in a defined order in the input but also provides the possibility
to check how many times a keyword appears in the input.
The kwd directive will parse the keywords respecting case sensitivity whereas the ikwd direcive is case insensitive. You can mix the kwd and ikwd directives inside a set of keywords, but be aware that this has a small overhead. It should be prefered not to mix the kwd and ikwd directives.
The kwd directive is very similar to the repeat directive in that it enables to enforce keyword occurence constraints but also provides very interesting speed improvement over the pure EBNF syntax or the Nabialek-Trick.
// forwards to <boost/spirit/repository/home/qi/directive/kwd.hpp> #include <boost/spirit/repository/include/qi_kwd.hpp>
Expression |
Semantics |
---|---|
|
Parse ( |
|
Parse ( |
|
Parse ( |
|
Parse ( |
For non case sensitive keywords use the ikwd directive.
Parameter |
Description |
---|---|
|
The parser for the opening (the prefix). |
|
The parser for the input sequence following the keyword part. |
|
Int representing the exact number of times the keyword must be repeated. |
|
Int representing the minimum number of times the keyword must be repeated. |
|
Int representing the maximum number of times the keyword must be repeated. |
All three parameters can be arbitrarily complex parsers themselves.
Expression |
Attribute |
---|---|
|
a: A --> kwd(k1)[a]: optional<A> or vector<A> a: Unused --> kwd(k1)[a]: Unused
|
|
a: A --> kwd(k1,n)[a]: optional<A> or vector<A> a: Unused --> kwd(k1,n)[a]: Unused
|
|
a: A --> kwd(k1,min, max)[a]: optional<A> or vector<A> a: Unused --> kwd(k1,min, max)[a]: Unused
|
|
a: A --> kwd(k1,min, inf)[a]: optional<A> or vector<A> a: Unused --> kwd(k1,min, inf)[a]: Unused
|
The overall complexity is defined by the complexity of its subject parser. The complexity of the keyword list construct
kwd
itself is O(N), where N is the number of repetitions executed.The complexity of the keyword list itself determined by the complexity of the internal TST contents :
O(log n+k)
Where k is the length of the string to be searched in a TST with n strings.
Please refer to keyword_list.