The R Project SVN R-packages

Rev

Rev 6048 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5994 bibiko 1
%{
2
 
3
	/*
4
	 *  R.app : a Cocoa front end to: "R A Computer Language for Statistical Data Analysis"
5
	 *  
6
	 *  R.app Copyright notes:
7
	 *                     Copyright (C) 2004-5  The R Foundation
8
	 *                     written by Stefano M. Iacus and Simon Urbanek
9
	 *
10
	 *                  
11
	 *  R Copyright notes:
12
	 *                     Copyright (C) 1995-1996   Robert Gentleman and Ross Ihaka
13
	 *                     Copyright (C) 1998-2001   The R Development Core Team
14
	 *                     Copyright (C) 2002-2004   The R Foundation
15
	 *
16
	 *  This program is free software; you can redistribute it and/or modify
17
	 *  it under the terms of the GNU General Public License as published by
18
	 *  the Free Software Foundation; either version 2 of the License, or
19
	 *  (at your option) any later version.
20
	 *
21
	 *  This program is distributed in the hope that it will be useful,
22
	 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
	 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
	 *  GNU General Public License for more details.
25
	 *
26
	 *  A copy of the GNU General Public License is available via WWW at
27
	 *  http://www.gnu.org/copyleft/gpl.html.  You can also obtain it by
28
	 *  writing to the Free Software Foundation, Inc., 59 Temple Place,
29
	 *  Suite 330, Boston, MA  02111-1307  USA.
30
	 *
31
	 *  RScriptEditorTokens.l
32
	 *
33
	 *  Created by Hans-J. Bibiko on 09/01/2012.
34
	 *
35
	 *  Flex parser for syntax highlighting Rd code.
36
	 *
37
	 */
38
 
39
#import "RdScriptEditorTokens.h"
40
 
41
size_t utf8strlenRd(const char * _s);
7797 urbaneks 42
extern size_t yyuoffset, yyuleng;
5994 bibiko 43
 
44
//keep track of the current utf-8 character (not byte) offset and token length
45
#define YY_USER_ACTION { yyuoffset += yyuleng; yyuleng = utf8strlenRd(yytext); }
5995 bibiko 46
//ignore the output of unmatched characters
47
#define ECHO {}
5994 bibiko 48
%}
49
%option prefix="rd"
50
%option noyywrap
51
%option nounput
52
%option case-sensitive
53
 
54
 
5995 bibiko 55
s				[ \t\n\r]+
56
break			[^a-zA-Z_0-9À-゚]
5994 bibiko 57
 
6048 bibiko 58
section			\\(s(ynopsis|ource|ubsection|e(ction|ealso))|Rd(Opts|version)|n(ote|ame)|concept|title|Sexpr|d(ocType|e(scription|tails))|usage|e(ncoding|xamples)|value|keyword|format|a(uthor|lias|rguments)|references)
59
macrowarg		\\(s(trong|pecial|amp|Quote)|href|newcommand|c(ite|o(de|mmand))|t(estonly|abular)|i(tem(ize)?|f(else)?)|S(3method|4method)|o(ut|ption)|d(ont(show|test|run)|e(scribe|qn)|fn|Quote)|CRANpkg|url|p(kg|reformatted)|e(n(c|d|umerate|v)|qn|m(ph|ail))|v(erb|ar)|kbd|fi(le|gure)|link(S4class)?|acronym|renewcommand|method|b(old|egin))
6004 bibiko 60
macrowoarg		\\(R|cr|tab|item|dots|l(dots|eft)|right|ge)
61
macrogen		\\[a-zA-Z0-9_]+
5994 bibiko 62
 
5998 bibiko 63
%x verbatim
64
 
5995 bibiko 65
%%
5994 bibiko 66
 
5998 bibiko 67
\\(%)																			/* ignore escaped comment sign */
6004 bibiko 68
\\(\\)																			/* ignore escaped \ sign */
5995 bibiko 69
%[^\n\r]*(\n|\r)?						{ return RDPT_COMMENT; }				/* % Comments                     */
5998 bibiko 70
^#ifn?def/[ \t]							{ return RDPT_DIRECTIVE; }
6004 bibiko 71
^#endif/[ \t\n\r]						{ return RDPT_DIRECTIVE; }
5998 bibiko 72
\\verb/\{								{ BEGIN(verbatim); return RDPT_MACRO_ARG; }
73
<verbatim>[^\}]																	/* ignore everything inside \verb{} */
74
<verbatim>\\\}																	/* ignore everything inside \verb{} */
75
<verbatim>\\(%)																	/* ignore everything inside \verb{} */
76
<verbatim>%[^\n\r]*(\n|\r)?				{ return RDPT_COMMENT; }				/* % sign is valid inside \verb{}   */
77
<verbatim>\}							{ BEGIN(INITIAL); }						/* verbatim end */
5995 bibiko 78
{section}/\{							{ return RDPT_SECTION; }				/* section macros                 */
79
\\Sexpr/\[								{ return RDPT_SECTION; }				/* section macros                 */
80
{macrowarg}/\{							{ return RDPT_MACRO_ARG; }				/* macros with arguments          */
81
\\link/\[								{ return RDPT_MACRO_ARG; }				/* macros with arguments          */
5998 bibiko 82
{macrowoarg}/(\\|{s}|%|{break})			{ return RDPT_MACRO_ARG; }				/* macros without arguments       */
5995 bibiko 83
{macrogen}								{ return RDPT_MACRO_GEN; }				/* unknown macros                 */
6029 bibiko 84
.										{ return RDPT_OTHER; }
5994 bibiko 85
 
86
<<EOF>>   						{
87
	BEGIN(INITIAL);   /* make sure we return to initial state when finished! */
88
	yy_delete_buffer(YY_CURRENT_BUFFER);
89
	return 0;
90
}
91
%%
92
 
93
#define ONEMASK ((size_t)(-1) / 0xFF)
94
// adapted from http://www.daemonology.net/blog/2008-06-05-faster-utf8-strlen.html
95
size_t utf8strlenRd(const char * _s)
96
{
97
	const char * s;
98
	size_t count = 0;
99
	size_t u;
100
	unsigned char b;
101
 
102
	/* Handle any initial misaligned bytes. */
103
	for (s = _s; (uintptr_t)(s) & (sizeof(size_t) - 1); s++) {
104
		b = *s;
105
 
106
		/* Exit if we hit a zero byte. */
107
		if (b == '\0')
108
			goto done;
109
 
110
		/* Is this byte NOT the first byte of a character? */
111
		count += (b >> 7) & ((~b) >> 6);
112
	}
113
 
114
	/* Handle complete blocks. */
115
	for (; ; s += sizeof(size_t)) {
116
		/* Prefetch 256 bytes ahead. */
117
		__builtin_prefetch(&s[256], 0, 0);
118
 
119
		/* Grab 4 or 8 bytes of UTF-8 data. */
120
		u = *(size_t *)(s);
121
 
122
		/* Exit the loop if there are any zero bytes. */
123
		if ((u - ONEMASK) & (~u) & (ONEMASK * 0x80))
124
			break;
125
 
126
		/* Count bytes which are NOT the first byte of a character. */
127
		u = ((u & (ONEMASK * 0x80)) >> 7) & ((~u) >> 6);
128
		count += (u * ONEMASK) >> ((sizeof(size_t) - 1) * 8);
129
	}
130
 
131
	/* Take care of any left-over bytes. */
132
	for (; ; s++) {
133
		b = *s;
134
 
135
		/* Exit if we hit a zero byte. */
136
		if (b == '\0')
137
			break;
138
 
139
		/* Is this byte NOT the first byte of a character? */
140
		count += (b >> 7) & ((~b) >> 6);
141
	}
142
 
143
done:
144
	return ((s - _s) - count);
145
}
146
 
5995 bibiko 147
/*
148
 
149
section:
150
RdOpts
151
Rdversion
152
Sexpr
153
alias
154
arguments
155
author
156
concept
157
description
158
details
159
docType
160
encoding
161
examples
162
format
163
keyword
164
name
165
note
166
references
167
section
168
seealso
169
source
6048 bibiko 170
subsection
5995 bibiko 171
synopsis
172
title
173
usage
174
value
175
 
176
macros with argument:
5998 bibiko 177
CRANpkg
5995 bibiko 178
S3method
179
S4method
180
acronym
181
begin
182
bold
183
cite
184
code
185
command
186
dQuote
187
deqn
188
describe
189
dfn
190
dontrun
191
dontshow
192
donttest
193
email
194
emph
195
enc
196
end
197
enumerate
198
env
199
eqn
200
file
6000 bibiko 201
figure
5995 bibiko 202
href
203
if
204
ifelse
205
item
206
itemize
207
kbd
208
link
209
linkS4class
210
method
211
newcommand
212
option
213
out
214
pkg
215
preformatted
216
renewcommand
217
sQuote
218
samp
219
special
220
strong
221
tabular
222
testonly
223
url
224
var
225
verb
226
 
227
macro without argument:
228
R
229
cr
230
dots
231
ge
5998 bibiko 232
item
5995 bibiko 233
ldots
234
left
235
right
236
tab
237
*/