File: pplusseries.c

package info (click to toggle)
yodl 4.05.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,724 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 163
file content (48 lines) | stat: -rw-r--r-- 1,573 bytes parent folder | download | duplicates (5)
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 "parser.ih"

/*
    Handles series of + characters. If the next token signifies a symbol the +
chars but one are inserted, and the symbol is handled by the symbol
pointer. This function is either p_default_symbol or p_parlist_symbol.

    p_default_symbol will handle the symbols: builtins are called, user
defined macros are expanded and inserted into the input media, other symbols
are inserted into the output media.

    p_parlist_symbol is probably obsolete, thus obsoleting the function
pointer here.

*/


bool p_plus_series(register Parser *pp,
                    void (*symbol)(Parser *, bool, SymbolType),
                    SymbolType mask)
{
    register Lexer *lp = &pp->d_lexer;
    size_t pluscount = 1;                     /* saw a +              */
    String plus;

    string_construct(&plus, 0);

    while (lexer_lex(lp) == TOKEN_PLUS)
        pluscount++;                            /* count 'em all        */

    if (pluscount > 1)                          /* got a + series       */
        string_fill(&plus, pluscount - 1, '+');   /* insert all but 1     */

    if (lexer_token(lp) == TOKEN_SYMBOL)        /* handle +MACRO, +BUILTIN  */
    {                                           /* or +xxx as +xxx          */
        (*pp->d_insert)(pp, string_str(&plus));
        (*symbol)(pp, true, mask);
    }
    else
    {
        lexer_unget_matched(lp);                 /* unget the last token */
        string_addchar(&plus, '+');
        (*pp->d_insert)(pp, string_str(&plus));
    }
    string_destruct(&plus);

    return true;
}