LTP GCOV extension - code coverage report
Current view: directory - src/libexpr - lexer.l
Test: app.info
Date: 2008-11-20 Instrumented lines: 95
Code covered: 96.8 % Executed lines: 92

       1                 : %option reentrant bison-bridge bison-locations
       2                 : %option noyywrap
       3                 : %option never-interactive
       4                 : 
       5                 : 
       6                 : %x STRING
       7                 : %x IND_STRING
       8                 : 
       9                 : 
      10                 : %{
      11                 : #include "aterm.hh"
      12                 : #include "nixexpr.hh"
      13                 : #include "nixexpr-ast.hh"
      14                 : #define BISON_HEADER_HACK
      15                 : #include "parser-tab.hh"
      16                 : 
      17                 : using namespace nix;
      18                 : 
      19                 : namespace nix {
      20                 : 
      21                 :     
      22             185 : static void initLoc(YYLTYPE * loc)
      23                 : {
      24             185 :     loc->first_line = 1;
      25             185 :     loc->first_column = 1;
      26             185 : }
      27                 : 
      28                 :     
      29           34820 : static void adjustLoc(YYLTYPE * loc, const char * s, size_t len)
      30                 : {
      31          192536 :     while (len--) {
      32          122896 :        switch (*s++) {
      33                 :        case '\r':
      34               6 :            if (*s == '\n') /* cr/lf */
      35               3 :                s++;
      36                 :            /* fall through */
      37                 :        case '\n': 
      38            4015 :            ++loc->first_line;
      39            4015 :            loc->first_column = 1;
      40            4015 :            break;
      41                 :        default:
      42          118881 :            ++loc->first_column;
      43                 :        }
      44                 :     }
      45           34820 : }
      46                 : 
      47                 : 
      48            1956 : static Expr unescapeStr(const char * s)
      49                 : {
      50            1956 :     string t;
      51                 :     char c;
      52           42030 :     while ((c = *s++)) {
      53           38118 :         if (c == '\\') {
      54               9 :             assert(*s);
      55               9 :             c = *s++;
      56               9 :             if (c == 'n') t += '\n';
      57               7 :             else if (c == 'r') t += '\r';
      58               5 :             else if (c == 't') t += '\t';
      59               4 :             else t += c;
      60                 :         }
      61           38109 :         else if (c == '\r') {
      62                 :             /* Normalise CR and CR/LF into LF. */
      63               2 :             t += '\n';
      64               2 :             if (*s == '\n') s++; /* cr/lf */
      65                 :         }
      66           38107 :         else t += c;
      67                 :     }
      68            1956 :     return makeStr(toATerm(t), ATempty);
      69                 : }
      70                 : 
      71                 :  
      72                 : }
      73                 : 
      74                 : #define YY_USER_INIT initLoc(yylloc)
      75                 : #define YY_USER_ACTION adjustLoc(yylloc, yytext, yyleng);
      76                 : 
      77                 : %}
      78                 : 
      79                 : 
      80                 : ID          [a-zA-Z\_][a-zA-Z0-9\_\']*
      81                 : INT         [0-9]+
      82                 : PATH        [a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+
      83                 : URI         [a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\']+
      84                 : 
      85                 : 
      86                 : %%
      87                 : 
      88                 : 
      89             190 : if          { return IF; }
      90             190 : then        { return THEN; }
      91             190 : else        { return ELSE; }
      92             230 : assert      { return ASSERT; }
      93             206 : with        { return WITH; }
      94             150 : let         { return LET; }
      95              56 : in          { return IN; }
      96             141 : rec         { return REC; }
      97             175 : inherit     { return INHERIT; }
      98              33 : \.\.\.      { return ELLIPSIS; }
      99             135 : 
     100              98 : \=\=        { return EQ; }
     101             106 : \!\=        { return NEQ; }
     102             122 : \&\&        { return AND; }
     103              12 : \|\|        { return OR; }
     104             130 : \-\>        { return IMPL; }
     105              43 : \/\/        { return UPDATE; }
     106              47 : \+\+        { return CONCAT; }
     107              41 : 
     108            5881 : {ID}        { yylval->t = toATerm(yytext); return ID; /* !!! alloc */ }
     109            6037 : {INT}       { int n = atoi(yytext); /* !!! overflow */
     110             195 :               yylval->t = ATmake("<int>", n);
     111             390 :               return INT;
     112                 :             }
     113                 : 
     114            1955 : \"          { BEGIN(STRING); return '"'; }
     115            1955 : <STRING>([^\$\"\\]|\$[^\{\"]|\\.)+ {
     116                 : /* !!! Not quite right: we want a follow restriction on "$", it
     117                 :    shouldn't be followed by a "{".  Right now "$\"" will be consumed
     118            1953 :    as part of a string, rather than a "$" followed by the string
     119                 :    terminator.  Disallow "$\"" for now. */
     120            1953 :               yylval->t = unescapeStr(yytext); /* !!! alloc */ 
     121            1953 :               return STR;
     122                 :             }
     123              25 : <STRING>\$\{  { BEGIN(INITIAL); return DOLLAR_CURLY; }
     124            1955 : <STRING>\"  { BEGIN(INITIAL); return '"'; }
     125              25 : <STRING>.   return yytext[0]; /* just in case: shouldn't be reached */
     126            1955 : 
     127              15 : \'\'(\ *\n)?     { BEGIN(IND_STRING); return IND_STRING_OPEN; }
     128                 : <IND_STRING>([^\$\']|\$[^\{\']|\'[^\'\$])+ {
     129              48 :                    yylval->t = makeIndStr(toATerm(yytext));
     130              33 :                    return IND_STR;
     131              33 :                  }
     132                 : <IND_STRING>\'\'\$ {
     133               1 :                    yylval->t = makeIndStr(toATerm("$"));
     134               2 :                    return IND_STR;
     135                 :                  }
     136                 : <IND_STRING>\'\'\' {
     137               1 :                    yylval->t = makeIndStr(toATerm("''"));
     138               2 :                    return IND_STR;
     139                 :                  }
     140                 : <IND_STRING>\'\'\\. {
     141               3 :                    yylval->t = unescapeStr(yytext + 2);
     142               6 :                    return IND_STR;
     143                 :                  }
     144              14 : <IND_STRING>\$\{ { BEGIN(INITIAL); return DOLLAR_CURLY; }
     145              15 : <IND_STRING>\'\' { BEGIN(INITIAL); return IND_STRING_CLOSE; }
     146              14 : <IND_STRING>\'   {
     147              16 :                    yylval->t = makeIndStr(toATerm("'"));
     148               2 :                    return IND_STR;
     149                 :                  }
     150               0 : <IND_STRING>.    return yytext[0]; /* just in case: shouldn't be reached */
     151                 : 
     152             245 : {PATH}      { yylval->t = toATerm(yytext); return PATH; /* !!! alloc */ }
     153             253 : {URI}       { yylval->t = toATerm(yytext); return URI; /* !!! alloc */ }
     154                 : 
     155               8 : [ \t\r\n]+    /* eat up whitespace */
     156           12403 : \#[^\r\n]*    /* single-line comments */
     157           12543 : \/\*([^*]|\*[^\/])*\*\/  /* long comments */
     158             144 : 
     159            8750 : .           return yytext[0];
     160            8754 : 
     161                 : 
     162               0 : %%
     163               0 : 
     164                 : 
     165                 : namespace nix {
     166                 :     
     167                 : /* Horrible, disgusting hack: allow the parser to set the scanner
     168                 :    start condition back to STRING.  Necessary in interpolations like
     169                 :    "foo${expr}bar"; after the close brace we have to go back to the
     170                 :    STRING state. */
     171                 : void backToString(yyscan_t scanner)
     172              25 : {
     173                 :     struct yyguts_t * yyg = (struct yyguts_t *) scanner;
     174              25 :     BEGIN(STRING);
     175              25 : }
     176              25 : 
     177                 : void backToIndString(yyscan_t scanner)
     178              14 : {
     179                 :     struct yyguts_t * yyg = (struct yyguts_t *) scanner;
     180              14 :     BEGIN(IND_STRING);
     181              14 : }
     182              14 : 
     183                 : }

Generated by: LTP GCOV extension version 1.6