Update jflex to 1.8.2
[scilab.git] / scilab / modules / helptools / src / java / jflex / function.jflex
1 //CHECKSTYLE:OFF
2
3 package org.scilab.modules.helptools ;
4
5 import java.io.IOException;
6 import java.io.StringReader;
7
8 @javax.annotation.Generated("JFlex")
9 %%
10
11 %public
12 %class SynopsisLexer
13 %final
14 %unicode
15 %char
16 %type void
17
18 %{
19     private static String currentName;
20     private static StringBuilder htmlBuffer = new StringBuilder(512);
21     private static SynopsisLexer lexer = new SynopsisLexer();
22
23     private SynopsisLexer() { }
24
25     public static String convert(String name, String str) {
26         currentName = name;
27         try {
28             lexer.yyreset(new StringReader(str.trim()));
29             lexer.yybegin(YYINITIAL);
30             htmlBuffer.setLength(0);
31             lexer.yylex();
32             
33             return htmlBuffer.toString();
34         } catch (IOException e) {
35             return null;
36         }
37     }
38
39 %}
40
41 %eofval{
42   return;
43 %eofval}
44
45 /* main character classes */
46 white = [ \t]+
47 eol = ("\r" | "\n" | "\r\n"){white}*
48
49 id = ([a-zA-Z%_#!?][a-zA-Z0-9_#!$?]*)|("$"[a-zA-Z0-9_#!$?]+)
50
51 comments = "//"[^\r\n]*
52
53 nothing = [^a-zA-Z%_#!?/\n\r<>&\"\']+ | "/"
54
55 dquote = "\""
56 quote = "'"
57 lt = "<"
58 gt = ">"
59 amp = "&"
60
61 %%
62
63 <YYINITIAL> {
64
65   {comments}                     {
66                                    htmlBuffer.append("<span class=\"comment\">");
67                                    htmlBuffer.append(yytext());
68                                    htmlBuffer.append("</span>");
69                                  }
70
71   {id}                           {
72                                    String str = yytext();
73                                    if (str.equals(currentName)) {
74                                       htmlBuffer.append("<span class=\"functionid\">");
75                                    } else {
76                                       htmlBuffer.append("<span class=\"default\">");
77                                    }                            
78                                    htmlBuffer.append(str);
79                                    htmlBuffer.append("</span>");
80                                  }
81
82   {dquote}                       {
83                                    htmlBuffer.append("&#0034;");
84                                  }
85      
86   {quote}                        {
87                                    htmlBuffer.append("&#0039;");
88                                  }
89
90   {lt}                           {
91                                    htmlBuffer.append("&lt;");
92                                  }
93
94   {gt}                           {
95                                    htmlBuffer.append("&gt;");
96                                  }
97
98   {amp}                          {
99                                    htmlBuffer.append("&amp;");
100                                  }
101
102   {white}                        {
103                                    htmlBuffer.append(" ");
104                                  }
105
106   {eol}                          {
107                                    htmlBuffer.append("\n");
108                                  }
109
110   {nothing}                      {
111                                    htmlBuffer.append("<span class=\"default\">");
112                                    htmlBuffer.append(yytext());
113                                    htmlBuffer.append("</span>");
114                                  }
115 }