LCOV - code coverage report
Current view: top level - extra/webserver/pug - SPPugToken.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 79 79 100.0 %
Date: 2024-05-12 00:16:13 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2024 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #include "SPPugToken.h"
      24             : #include "SPPugExpression.h"
      25             : 
      26             : namespace STAPPLER_VERSIONIZED stappler::pug {
      27             : 
      28       79225 : Token::Token(Type t, const StringView &d) : type(t), data(d) { }
      29             : 
      30        5850 : Token::Token(Type t, const StringView &d, Expression *e)
      31        5850 : : type(t), data(d), expression(e) { }
      32             : 
      33       84550 : void Token::addChild(Token *tok) {
      34       84550 :         if (!child) {
      35       46625 :                 tail = child = tok;
      36             :         } else {
      37       37925 :                 tail->next = tok;
      38       37925 :                 tok->prev = tail;
      39       37925 :                 tail = tok;
      40             :         }
      41       84550 : }
      42             : 
      43             : /// Forward declaration
      44             : static void stl_print_token(const Lexer::OutStream &stream, const Token * t, uint16_t depth);
      45             : static void stl_print_token_tree(const Lexer::OutStream &stream, const Token * t, uint16_t depth);
      46             : 
      47             : /// Print contents of the token based on specified string
      48       15725 : static void stl_print_token(const Lexer::OutStream &stream, const Token * t, uint16_t depth) {
      49       15725 :         if (t) {
      50       80175 :                 for (int i = 0; i < depth; ++i) {
      51       64450 :                         stream << "  ";
      52             :                 }
      53             : 
      54       15725 :                 stream << "* " << toInt(t->type) << " ";
      55       15725 :                 switch (t->type) {
      56          75 :                 case Token::Root: stream << "<root>"; break;
      57        3100 :                 case Token::Line: stream << "<line>"; break;
      58             : 
      59        1650 :                 case Token::LineData: stream << "<line-data>"; break;
      60         550 :                 case Token::LinePiped: stream << "<line-piped>"; break;
      61         225 :                 case Token::LinePlainText: stream << "<line-plain-text>"; break;
      62         125 :                 case Token::LineComment: stream << "<line-comment>"; break;
      63          25 :                 case Token::LineDot: stream << "<line-dot>"; break;
      64          50 :                 case Token::LineOut: stream << "<line-out>"; break;
      65         400 :                 case Token::LineCode: stream << "<line-code>"; break;
      66          25 :                 case Token::LineCodeBlock: stream << "<line-code-block>"; break;
      67             : 
      68        1725 :                 case Token::PlainText: stream << "<plain-text>"; break;
      69         425 :                 case Token::Code: stream << "<code>"; break;
      70         475 :                 case Token::OutputEscaped: stream << "<out-escaped>"; break;
      71          75 :                 case Token::OutputUnescaped: stream << "<out-unescaped>"; break;
      72             : 
      73          75 :                 case Token::CommentTemplate: stream << "<comment-template>"; break;
      74          50 :                 case Token::CommentHtml: stream << "<comment-html>"; break;
      75        1650 :                 case Token::Tag: stream << "<tag>"; break;
      76             : 
      77         325 :                 case Token::TagClassNote: stream << "<tag-class-note>"; break;
      78         125 :                 case Token::TagIdNote: stream << "<tag-id-note>"; break;
      79         500 :                 case Token::TagAttrList: stream << "<tag-attr-list>"; break;
      80          50 :                 case Token::TagAttrExpr: stream << "<tag-attr-expr>"; break;
      81          25 :                 case Token::TagTrailingSlash: stream << "<tag-trailing-slash>"; break;
      82          50 :                 case Token::TagTrailingDot: stream << "<tag-trailing-dot>"; break;
      83         325 :                 case Token::TagTrailingEq: stream << "<tag-trailing-eq>"; break;
      84          25 :                 case Token::TagTrailingNEq: stream << "<tag-trailing-neq>"; break;
      85             : 
      86         700 :                 case Token::AttrPairEscaped: stream << "<attr-pair-escaped>"; break;
      87          50 :                 case Token::AttrPairUnescaped: stream << "<attr-pair-unescaped>"; break;
      88         750 :                 case Token::AttrName: stream << "<attr-name>"; break;
      89         700 :                 case Token::AttrValue: stream << "<attr-value>"; break;
      90             : 
      91          50 :                 case Token::ControlCase: stream << "<control-case>"; break;
      92         125 :                 case Token::ControlWhen: stream << "<control-when>"; break;
      93          50 :                 case Token::ControlDefault: stream << "<control-default>"; break;
      94             : 
      95          25 :                 case Token::ControlIf: stream << "<control-if>"; break;
      96          25 :                 case Token::ControlUnless: stream << "<control-unless>"; break;
      97          25 :                 case Token::ControlElseIf: stream << "<control-else-if>"; break;
      98          50 :                 case Token::ControlElse: stream << "<control-else>"; break;
      99          75 :                 case Token::ControlEach: stream << "<control-each>"; break;
     100          25 :                 case Token::ControlEachPair: stream << "<control-each-pair>"; break;
     101          25 :                 case Token::ControlWhile: stream << "<control-while>"; break;
     102          50 :                 case Token::ControlMixin: stream << "<control-mixin>"; break;
     103             : 
     104         125 :                 case Token::ControlEachVariable: stream << "<control-each-variable>"; break;
     105             : 
     106         550 :                 case Token::PipeMark: stream << "<pipe-mark>"; break;
     107          75 :                 case Token::Include: stream << "<include>"; break;
     108          25 :                 case Token::Doctype: stream << "<doctype>"; break;
     109          50 :                 case Token::MixinCall: stream << "<mixin-call>"; break;
     110          50 :                 case Token::MixinArgs: stream << "<mixin-args>"; break;
     111             :                 }
     112             : 
     113       15725 :                 if (t->expression) {
     114        2200 :                         stream << " expression: '" << t->data << "'";
     115             :                 } else {
     116       13525 :                         stream << " '" << t->data << "'";
     117             :                 }
     118       15725 :                 stream << "\n";
     119       15725 :                 if (t->expression) {
     120        2200 :                         t->expression->describe(stream, depth + 1);
     121             :                 }
     122       15725 :                 if (t->child) {
     123        8725 :                         stl_print_token_tree(stream, t->child, depth + 1);
     124             :                 }
     125             :         }
     126       15725 : }
     127             : 
     128             : /// Print contents of the token tree based on specified string
     129        8725 : static void stl_print_token_tree(const Lexer::OutStream &stream, const Token * t, uint16_t depth) {
     130       24375 :         while (t != NULL) {
     131       15650 :                 stl_print_token(stream, t, depth);
     132       15650 :                 t = t->next;
     133             :         }
     134        8725 : }
     135             : 
     136          75 : void Token::describe(const OutStream &stream) const {
     137          75 :         stl_print_token(stream, this, 0);
     138          75 : }
     139             : 
     140             : }

Generated by: LCOV version 1.14