-
Notifications
You must be signed in to change notification settings - Fork 3
/
cppdemo.cpp
48 lines (40 loc) · 1.1 KB
/
cppdemo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "termpose.cpp"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
using namespace termpose;
struct Product{
string name;
float cost;
string description;
Product(string name, float cost, string description):
name(name), cost(cost), description(description)
{}
};
string textData = "\
products\n\
hammer cost:5 description\"\n\
premium hammer. great for smashing\n\
\"bee's knee\" cost:9.50 description\"\n\
supposedly really good thing\n\
twine cost:0 description\"\n\
make a text adventure\n";
int main(int argc, char const *argv[]){
//first, we parse the termpose data into a tree structure.
Term data = Term::parse(textData);
cout<< data.prettyPrint() <<endl;
{
using namespace termpose::parsingDSL;
vector<Product> products = taggedSequence("products",
combineCheck(
[](string name, float cost, string description){
return Product(name, cost, description); },
stringCheck(),
ensureTag("cost", floatCheck()),
ensureTag("description", stringCheck()) )
)->check(data);
cout<< products[1].description <<endl;
}
return 0;
}