summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/token.cpp38
-rw-r--r--lib/token.h8
2 files changed, 39 insertions, 7 deletions
diff --git a/lib/token.cpp b/lib/token.cpp index 88cc4da..945be5e 100644 --- a/lib/token.cpp +++ b/lib/token.cpp
@@ -51,6 +51,7 @@ namespace verbly {
51 { 51 {
52 transform_.type_ = other.transform_.type_; 52 transform_.type_ = other.transform_.type_;
53 new(&transform_.strParam_) std::string(other.transform_.strParam_); 53 new(&transform_.strParam_) std::string(other.transform_.strParam_);
54 new(&transform_.strParam2_) std::string(other.transform_.strParam2_);
54 transform_.casingParam_ = other.transform_.casingParam_; 55 transform_.casingParam_ = other.transform_.casingParam_;
55 new(&transform_.inner_) std::unique_ptr<token>(new token(*other.transform_.inner_)); 56 new(&transform_.inner_) std::unique_ptr<token>(new token(*other.transform_.inner_));
56 57
@@ -86,6 +87,7 @@ namespace verbly {
86 std::list<token> tempUtterance; 87 std::list<token> tempUtterance;
87 transform_type tempTransformType; 88 transform_type tempTransformType;
88 std::string tempTransformStrParam; 89 std::string tempTransformStrParam;
90 std::string tempTransformStrParam2;
89 casing tempTransformCasingParam; 91 casing tempTransformCasingParam;
90 std::unique_ptr<token> tempTransformInner; 92 std::unique_ptr<token> tempTransformInner;
91 93
@@ -131,6 +133,7 @@ namespace verbly {
131 { 133 {
132 tempTransformType = first.transform_.type_; 134 tempTransformType = first.transform_.type_;
133 tempTransformStrParam = std::move(first.transform_.strParam_); 135 tempTransformStrParam = std::move(first.transform_.strParam_);
136 tempTransformStrParam2 = std::move(first.transform_.strParam2_);
134 tempTransformCasingParam = first.transform_.casingParam_; 137 tempTransformCasingParam = first.transform_.casingParam_;
135 tempTransformInner = std::move(first.transform_.inner_); 138 tempTransformInner = std::move(first.transform_.inner_);
136 139
@@ -184,6 +187,7 @@ namespace verbly {
184 { 187 {
185 first.transform_.type_ = second.transform_.type_; 188 first.transform_.type_ = second.transform_.type_;
186 new(&first.transform_.strParam_) std::string(std::move(second.transform_.strParam_)); 189 new(&first.transform_.strParam_) std::string(std::move(second.transform_.strParam_));
190 new(&first.transform_.strParam2_) std::string(std::move(second.transform_.strParam2_));
187 first.transform_.casingParam_ = second.transform_.casingParam_; 191 first.transform_.casingParam_ = second.transform_.casingParam_;
188 new(&first.transform_.inner_) std::unique_ptr<token>(std::move(second.transform_.inner_)); 192 new(&first.transform_.inner_) std::unique_ptr<token>(std::move(second.transform_.inner_));
189 193
@@ -237,6 +241,7 @@ namespace verbly {
237 { 241 {
238 second.transform_.type_ = tempTransformType; 242 second.transform_.type_ = tempTransformType;
239 new(&second.transform_.strParam_) std::string(std::move(tempTransformStrParam)); 243 new(&second.transform_.strParam_) std::string(std::move(tempTransformStrParam));
244 new(&second.transform_.strParam2_) std::string(std::move(tempTransformStrParam2));
240 second.transform_.casingParam_ = tempTransformCasingParam; 245 second.transform_.casingParam_ = tempTransformCasingParam;
241 new(&second.transform_.inner_) std::unique_ptr<token>(std::move(tempTransformInner)); 246 new(&second.transform_.inner_) std::unique_ptr<token>(std::move(tempTransformInner));
242 247
@@ -293,6 +298,7 @@ namespace verbly {
293 using ptr_type = std::unique_ptr<token>; 298 using ptr_type = std::unique_ptr<token>;
294 299
295 transform_.strParam_.~string_type(); 300 transform_.strParam_.~string_type();
301 transform_.strParam2_.~string_type();
296 transform_.inner_.~ptr_type(); 302 transform_.inner_.~ptr_type();
297 303
298 break; 304 break;
@@ -485,6 +491,16 @@ namespace verbly {
485 indefiniteArticle, 491 indefiniteArticle,
486 transform_.casingParam_); 492 transform_.casingParam_);
487 } 493 }
494
495 case transform_type::quote:
496 {
497 return transform_.strParam_ +
498 transform_.inner_->compileHelper(
499 separator,
500 indefiniteArticle,
501 capitalization) +
502 transform_.strParam2_;
503 }
488 } 504 }
489 } 505 }
490 } 506 }
@@ -654,17 +670,17 @@ namespace verbly {
654 670
655 token token::separator(std::string param, token inner) 671 token token::separator(std::string param, token inner)
656 { 672 {
657 return token(transform_type::separator, std::move(param), std::move(inner)); 673 return token(transform_type::separator, std::move(param), "", std::move(inner));
658 } 674 }
659 675
660 token token::punctuation(std::string param, token inner) 676 token token::punctuation(std::string param, token inner)
661 { 677 {
662 return token(transform_type::punctuation, std::move(param), std::move(inner)); 678 return token(transform_type::punctuation, std::move(param), "", std::move(inner));
663 } 679 }
664 680
665 token token::indefiniteArticle(token inner) 681 token token::indefiniteArticle(token inner)
666 { 682 {
667 return token(transform_type::indefinite_article, "", std::move(inner)); 683 return token(transform_type::indefinite_article, "", "", std::move(inner));
668 } 684 }
669 685
670 token token::capitalize(casing param, token inner) 686 token token::capitalize(casing param, token inner)
@@ -672,6 +688,15 @@ namespace verbly {
672 return token(transform_type::capitalize, param, std::move(inner)); 688 return token(transform_type::capitalize, param, std::move(inner));
673 } 689 }
674 690
691 token token::quote(std::string opening, std::string closing, token inner)
692 {
693 return token(
694 transform_type::quote,
695 std::move(opening),
696 std::move(closing),
697 std::move(inner));
698 }
699
675 token& token::getInnerToken() 700 token& token::getInnerToken()
676 { 701 {
677 if (type_ != type::transform) 702 if (type_ != type::transform)
@@ -694,12 +719,14 @@ namespace verbly {
694 719
695 token::token( 720 token::token(
696 transform_type type, 721 transform_type type,
697 std::string param, 722 std::string param1,
723 std::string param2,
698 token inner) : 724 token inner) :
699 type_(type::transform) 725 type_(type::transform)
700 { 726 {
701 transform_.type_ = type; 727 transform_.type_ = type;
702 new(&transform_.strParam_) std::string(std::move(param)); 728 new(&transform_.strParam_) std::string(std::move(param1));
729 new(&transform_.strParam2_) std::string(std::move(param2));
703 new(&transform_.inner_) std::unique_ptr<token>(new token(std::move(inner))); 730 new(&transform_.inner_) std::unique_ptr<token>(new token(std::move(inner)));
704 } 731 }
705 732
@@ -711,6 +738,7 @@ namespace verbly {
711 { 738 {
712 transform_.type_ = type; 739 transform_.type_ = type;
713 new(&transform_.strParam_) std::string(); 740 new(&transform_.strParam_) std::string();
741 new(&transform_.strParam2_) std::string();
714 transform_.casingParam_ = param; 742 transform_.casingParam_ = param;
715 new(&transform_.inner_) std::unique_ptr<token>(new token(std::move(inner))); 743 new(&transform_.inner_) std::unique_ptr<token>(new token(std::move(inner)));
716 } 744 }
diff --git a/lib/token.h b/lib/token.h index 0bbe79a..ae7bf96 100644 --- a/lib/token.h +++ b/lib/token.h
@@ -116,6 +116,7 @@ namespace verbly {
116 static token punctuation(std::string param, token inner); 116 static token punctuation(std::string param, token inner);
117 static token indefiniteArticle(token inner); 117 static token indefiniteArticle(token inner);
118 static token capitalize(casing param, token inner); 118 static token capitalize(casing param, token inner);
119 static token quote(std::string open, std::string close, token inner);
119 120
120 token& getInnerToken(); 121 token& getInnerToken();
121 const token& getInnerToken() const; 122 const token& getInnerToken() const;
@@ -131,12 +132,14 @@ namespace verbly {
131 separator, 132 separator,
132 punctuation, 133 punctuation,
133 indefinite_article, 134 indefinite_article,
134 capitalize 135 capitalize,
136 quote
135 }; 137 };
136 138
137 token( 139 token(
138 transform_type type, 140 transform_type type,
139 std::string param, 141 std::string param1,
142 std::string param2,
140 token inner); 143 token inner);
141 144
142 token( 145 token(
@@ -156,6 +159,7 @@ namespace verbly {
156 struct { 159 struct {
157 transform_type type_; 160 transform_type type_;
158 std::string strParam_; 161 std::string strParam_;
162 std::string strParam2_;
159 casing casingParam_; 163 casing casingParam_;
160 std::unique_ptr<token> inner_; 164 std::unique_ptr<token> inner_;
161 } transform_; 165 } transform_;