summaryrefslogtreecommitdiff
path: root/src/genjsbind-lexer.l
blob: dcd47d54557a451f9f0dffc41810cfa73111c337 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
%{

/* lexer for the binding generation config file 
 *
 * This file is part of nsgenjsbind.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
 */

#include <stdbool.h>
#include <stdio.h>
#include <string.h>

#include "genjsbind-parser.h"

#define YY_USER_ACTION yylloc->first_line = yylloc->last_line; \
    yylloc->first_column = yylloc->last_column + 1; \
    yylloc->last_column += yyleng;

%}

/* lexer options */
%option never-interactive
%option yylineno
%option bison-bridge
%option bison-locations
%option nodefault
%option warn
%option prefix="genjsbind_"
%option nounput
%option noinput
%option noyywrap

/* other Unicode “space separator” */
USP (\xe1\x9a\x80)|(\xe1\xa0\x8e)|(\xe2\x80[\x80-\x8a])|(\xe2\x80\xaf)|(\xe2\x81\x9f)|(\xe3\x80\x80)

/* non breaking space \u00A0 */
NBSP (\xc2\xa0)

/* Line separator \u2028 */
LS (\xe2\x80\xa8)

/* paragraph separator \u2029 */
PS (\xe2\x80\xa9)

whitespace              ([ \t\v\f]|{NBSP}|{USP})

lineend                 ([\n\r]|{LS}|{PS})

multicomment            \/\*(([^*])|(\*[^/]))*\*\/

quotedstring            [^\"\\\n\r]

identifier              [A-Z_a-z][0-9A-Z_a-z]*

other                   [^\t\n\r 0-9A-Z_a-z]

cblockopen              \[\[\[

cblockclose             \]\]\]

%x                      cblock

%%

{whitespace}            ++yylloc->last_column;/* nothing */

{lineend}               if (yytext[0] != '\r') {
                            /* update position counts */
                            ++yylloc->last_line;
                            yylloc->last_column = 0;
                        }

 /* terminals */

webidlfile              return TOK_IDLFILE;

hdrcomment              return TOK_HDR_COMMENT;

preamble                return TOK_PREAMBLE;

binding                 return TOK_BINDING;

interface               return TOK_INTERFACE;

type                    return TOK_TYPE;

private                 return TOK_PRIVATE;

{cblockopen}            BEGIN(cblock);

{identifier}        {
                        /* A leading "_" is used to escape an identifier from 
                         *   looking like a reserved word terminal.
                         */
                        yylval->text = (yytext[0] == '_') ? strdup(yytext + 1) : strdup(yytext);
                        return TOK_IDENTIFIER;
                    }

\"{quotedstring}*\"     yylval->text = strndup(yytext + 1, yyleng - 2 ); return TOK_STRING_LITERAL;

{multicomment}          /* nothing */

{other}                 return (int) yytext[0];

.                       /* nothing */

<cblock>[^\]]*          yylval->text = strdup(yytext); return TOK_CCODE_LITERAL;
<cblock>{cblockclose}   BEGIN(INITIAL);
<cblock>\]+             yylval->text = strdup(yytext); return TOK_CCODE_LITERAL;

%%