po: Update French translation.
[wine] / dlls / d3dcompiler_43 / hlsl.l
1 /*
2  * HLSL parser
3  *
4  * Copyright 2008 Stefan Dösinger
5  * Copyright 2012 Matteo Bruni for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 %{
23 #include "config.h"
24 #include "wine/port.h"
25 #include "wine/debug.h"
26
27 #define YY_NO_UNISTD_H
28 #include "d3dcompiler_private.h"
29 #include "hlsl.tab.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(hlsl_parser);
32 %}
33
34 %option noyywrap nounput noinput
35 %option prefix="hlsl_"
36
37 %x pp pp_line pp_pragma pp_ignore
38
39 RESERVED1               auto|case|catch|char|class|const_cast|default|delete|dynamic_cast|enum
40 RESERVED2               explicit|friend|goto|long|mutable|new|operator|private|protected|public
41 RESERVED3               reinterpret_cast|short|signed|sizeof|static_cast|template|this|throw|try
42 RESERVED4               typename|union|unsigned|using|virtual
43
44 WS                      [ \t]
45 NEWLINE                 (\n)|(\r\n)
46 STRING                  \"[^\"]*\"
47
48 ANY                     (.)
49
50 %%
51 {RESERVED1}             {
52                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
53                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
54                         }
55 {RESERVED2}             {
56                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
57                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
58                         }
59 {RESERVED3}             {
60                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
61                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
62                         }
63 {RESERVED4}             {
64                             hlsl_message("Line %u: Reserved keyword \"%s\" used.\n", hlsl_ctx.line_no, yytext);
65                             set_parse_status(&hlsl_ctx.status, PARSE_ERR);
66                         }
67
68 {WS}+                   {}
69 {NEWLINE}               {
70                             hlsl_ctx.line_no++;
71                         }
72
73 ^#                      {
74                             BEGIN pp;
75                         }
76
77 <pp>pragma{WS}+         {
78                             TRACE("Got a #pragma.\n");
79                             BEGIN pp_pragma;
80                         }
81 <pp_pragma>pack_matrix{WS}*\({WS}*row_major{WS}*\) {
82                             TRACE("#pragma setting row_major mode.\n");
83                             hlsl_ctx.matrix_majority = HLSL_ROW_MAJOR;
84                             BEGIN pp_ignore;
85                         }
86 <pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) {
87                             TRACE("#pragma setting column_major mode.\n");
88                             hlsl_ctx.matrix_majority = HLSL_COLUMN_MAJOR;
89                             BEGIN pp_ignore;
90                         }
91 <pp_pragma>{NEWLINE}    {
92                             FIXME("Unsupported preprocessor #pragma directive at line %u.\n", hlsl_ctx.line_no);
93                             BEGIN INITIAL;
94                         }
95 <pp_pragma>{ANY}        {}
96 <pp>[0-9]+              {
97                             TRACE("Preprocessor line info.\n");
98                             BEGIN pp_line;
99                             hlsl_lval.intval = (atoi(yytext));
100                             return PRE_LINE;
101                         }
102 <pp_line>{STRING}       {
103                             char *string = d3dcompiler_strdup(yytext + 1);
104
105                             BEGIN pp_ignore;
106                             string[strlen(string) - 1] = 0;
107                             hlsl_lval.name = string;
108                             return STRING;
109                         }
110 <pp_line>{WS}+          {}
111 <pp_line>{NEWLINE}      {
112                             FIXME("Malformed preprocessor line directive?\n");
113                             BEGIN INITIAL;
114                         }
115 <pp_ignore>{NEWLINE}    {
116                             BEGIN INITIAL;
117                         }
118 <pp_ignore>{ANY}        {}
119 <pp>{NEWLINE}           {
120                             FIXME("Unexpected preprocessor directive.\n");
121                             BEGIN INITIAL;
122                         }
123 <pp>{ANY}               {}
124
125 {ANY}                   {
126                             return yytext[0];
127                         }
128
129 %%
130
131 struct bwriter_shader *parse_hlsl(enum shader_type type, DWORD version, const char *entrypoint, char **messages);
132
133 struct bwriter_shader *parse_hlsl_shader(const char *text, enum shader_type type, DWORD version,
134         const char *entrypoint, char **messages)
135 {
136     struct bwriter_shader *ret = NULL;
137     YY_BUFFER_STATE buffer;
138
139     buffer = hlsl__scan_string(text);
140     hlsl__switch_to_buffer(buffer);
141
142     ret = parse_hlsl(type, version, entrypoint, messages);
143
144     hlsl__delete_buffer(buffer);
145     return ret;
146 }