home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libstyle / css.lex < prev    next >
Encoding:
Text File  |  1998-04-08  |  10.1 KB  |  226 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. %{
  19.  
  20. /* For flex.  Requires support for 8-bit characters and case independence. */
  21.  
  22. #include "cssI.h"
  23. #include "csstab.h"
  24.  
  25. #undef YY_INPUT
  26. #define YY_INPUT(buf, result, max_size)  css_GetBuf(buf, &result, max_size)
  27.  
  28. #if !defined(__cplusplus) && !(__STDC__) && !defined(__TURBOC__)
  29. /* Stuff from stdlib.h -- needed by win16 */
  30. #define YY_MALLOC_DECL \
  31. extern void free (void *); \
  32. extern void *malloc (size_t size); \
  33. extern void *realloc (void *, size_t);
  34. #endif
  35.  
  36. static int input(void);
  37.  
  38. /* We never take input off of the command line. */
  39. #define YY_NEVER_INTERACTIVE 1
  40.  
  41. #ifdef CSS_PARSE_DEBUG
  42. #define RETURN(x) {printf("lex returns %d for '%s'\n",x,css_text);return(x);}
  43. #else
  44. #define RETURN(x) return(x)
  45. #endif
  46.  
  47. %}
  48.  
  49. unicode         \\[0-9a-f]{1,4}
  50. latin1          [í- ]
  51. escape          {unicode}|\\[ -~í- ]
  52. stringchar      {escape}|{latin1}|[ !#$%&(-~]
  53. nmstrt          [a-z]|{latin1}|{escape}
  54. nmchar          [-a-z0-9]|{latin1}|{escape}
  55. ident           {nmstrt}{nmchar}*
  56. name            {nmchar}+
  57. d               [0-9]
  58. notnm           [^-a-z0-9\\]|{latin1}
  59. w               [ \t\n]*
  60. num             {d}+|{d}*\.{d}+
  61. string          \"({stringchar}|\')*\"|\'({stringchar}|\")*\'
  62. hex             [0-9a-f]
  63. hex3            [0-9a-f]{3}
  64. hex6            [0-9a-f]{6}
  65.  
  66. %x css_comment
  67. %x css_ignore
  68. %x css_property
  69. %x css_value
  70. %x css_bg
  71. %x css_font
  72. %x css_line_height
  73. %x css_list_style
  74. %x css_border
  75. %x css_font_size
  76.  
  77. %s css_after_ident
  78.  
  79. %%
  80. %{
  81.  
  82.  
  83. /* CSS1 17 December 1996, with the following changes:
  84.  * 1.  Expand whitespace definition in the rules section.
  85.  * 2.  Change default rule action to be silent.
  86.  * 3.  Require class names to be an IDENT.
  87.  * 4.  Require id names to be an IDENT.
  88.  * 5.  Return '.' as a separate lexical token;
  89.  *     add DOT and DOT_AFTER_IDENT; remove CLASS and CLASS_AFTER_IDENT
  90.  * 6.  Return '#' as a separate lexical token;
  91.  *     remove HASH and HASH_AFTER_IDENT.
  92.  * 7.  Gut the use of AFTER_IDENT tokens for pseudoclasses and pseudoelements.
  93.  * 8.  Provide a definition for HEXCOLOR token.
  94.  *     move { and } out into state triggers
  95.  * 9.  Gave up on preserving any heritage and made use of exclusive states.
  96.  */
  97.  
  98. /* These state variables can be on the stack because their state is not
  99.  * useful across a token return.  They should always be set to 0 before
  100.  * starting a new input file.
  101.  */
  102. short int css_prior_state = 0;
  103. short int css_nest_count = 0;
  104.  
  105. %}
  106. \<\!\-\-                        {BEGIN(0); RETURN(CDO);}
  107. \-\-\>                          {BEGIN(0); RETURN(CDC);}
  108.  
  109. <css_after_ident>":"link        {BEGIN(0);RETURN(LINK_PSCLASS);}
  110. <css_after_ident>":"visited     {BEGIN(0);RETURN(VISITED_PSCLASS);}
  111. <css_after_ident>":"active      {BEGIN(0);RETURN(ACTIVE_PSCLASS);}
  112. <css_after_ident>"."            {BEGIN(0);RETURN(DOT_AFTER_IDENT);}
  113. {ident}                         {BEGIN(css_after_ident); RETURN(IDENT);}
  114.  
  115. ":"link                         {BEGIN(0);RETURN(LEADING_LINK_PSCLASS);}
  116. ":"visited                      {BEGIN(0);RETURN(LEADING_VISITED_PSCLASS);}
  117. ":"active                       {BEGIN(0);RETURN(LEADING_ACTIVE_PSCLASS);}
  118. ":"first-line                   {BEGIN(0);RETURN(FIRST_LINE);}
  119. ":"first-letter                 {BEGIN(0);RETURN(FIRST_LETTER);}
  120. "."                             {BEGIN(0);RETURN(DOT);}
  121. [,#;]                           {BEGIN(0);return (*css_text);}
  122. [ \t\f\v\r\n]+                  {BEGIN(0);}
  123.  
  124. @import                         {BEGIN(0); RETURN(IMPORT_SYM);}
  125. @fontdef                        {BEGIN(0); RETURN(FONTDEF);}
  126. url\({w}{string}{w}\)                             |
  127. url\({w}([^ \n\'\")]|\\\ |\\\'|\\\"|\\\))+{w}\)   {RETURN(URL);}
  128. {string}                        {RETURN(STRING);}
  129.  
  130. @{ident}             {BEGIN(css_ignore); css_nest_count=0;}
  131. <css_ignore>{string}     |
  132. <css_ignore>[^;{}]*      { /* unrecognized @rules are ignored. */}
  133. <css_ignore>";"          {if (0 == css_nest_count) BEGIN(0);}
  134. <css_ignore>"{"          {css_nest_count++;}
  135. <css_ignore>"}"          {if (0 >= --css_nest_count) BEGIN(0);}
  136.  
  137. <*>"/*"              {if (css_comment != YY_START) {
  138.                          /* Comments cannot be nested. */
  139.                          css_prior_state = YY_START;}
  140.                      BEGIN(css_comment);}
  141. <css_comment>[^*]*       |
  142. <css_comment>"*"+[^*/]*  {/* Comments function as whitespace. */}
  143. <css_comment>"*"+"/"     {BEGIN(css_prior_state);}
  144.  
  145. <css_property,css_value,css_bg,css_font,css_line_height,css_list_style,css_border,css_font_size>[ \t\f\v\r\n]+ {/* whitespace can separate tokens */}
  146. <css_property,css_value,css_bg,css_font,css_line_height,css_list_style,css_border,css_font_size>"}"   {BEGIN(0); return (*css_text);}
  147.  
  148. <css_value,css_bg,css_font,css_line_height,css_list_style,css_border,css_font_size>[;]     {BEGIN(css_property); return (*css_text);}
  149. <css_value,css_bg,css_font,css_line_height,css_list_style,css_border,css_font_size>"!"{w}important    {RETURN(IMPORTANT_SYM);}
  150.  
  151. "{"                           {BEGIN(css_property); return (*css_text);}
  152. <css_property>[:]                 {BEGIN(css_value); return (*css_text);}
  153. <css_property>[-/+;,#]            {return (*css_text);}
  154. <css_property>"background"        {BEGIN(css_bg); RETURN(BACKGROUND);}
  155. <css_property>font                {BEGIN(css_font); RETURN(FONT);}
  156. <css_property>list-style          {BEGIN(css_list_style); RETURN(LIST_STYLE);}
  157. <css_property>border              {BEGIN(css_border); RETURN(BORDER);}
  158. <css_property>font-size           {BEGIN(css_font_size); RETURN(FONT_SIZE_PROPERTY);}
  159. <css_property>{ident}             {RETURN(IDENT);}
  160.  
  161. <css_font>italic|oblique                        {RETURN(FONT_STYLE);}
  162. <css_font>small-caps                            {RETURN(FONT_VARIANT);}
  163. <css_font>bold|bolder|lighter                   {RETURN(FONT_WEIGHT);}
  164. <css_font>100|200|300|400|500|600|700|800|900   {RETURN(FONT_WEIGHT);}
  165. <css_font>normal                                {RETURN(FONT_NORMAL);}
  166. <css_font,css_font_size>xx-small|x-small|small|medium         {RETURN(FONT_SIZE);}
  167. <css_font,css_font_size>large|x-large|xx-large|larger|smaller {RETURN(FONT_SIZE);}
  168. <css_font,css_font_size,css_line_height>{num}"%"       {BEGIN(css_font); RETURN(PERCENTAGE);}
  169. <css_font,css_font_size>0                                  |
  170. <css_font,css_font_size,css_line_height>{num}pt/{notnm}    |
  171. <css_font,css_font_size,css_line_height>{num}mm/{notnm}    |  
  172. <css_font,css_font_size,css_line_height>{num}cm/{notnm}    |
  173. <css_font,css_font_size,css_line_height>{num}pc/{notnm}    |
  174. <css_font,css_font_size,css_line_height>{num}in/{notnm}    |
  175. <css_font,css_font_size,css_line_height>{num}px/{notnm}    {BEGIN(css_font); RETURN(LENGTH);}
  176. <css_font,css_font_size,css_line_height>{num}em/{notnm}    {BEGIN(css_font); RETURN(EMS);}
  177. <css_font,css_font_size,css_line_height>{num}ex/{notnm}    {BEGIN(css_font); RETURN(EXS);}
  178. <css_font>"/"                {BEGIN(css_line_height); return (*css_text);}
  179. <css_line_height>[-+]        {return (*css_text);}
  180. <css_line_height>{num}       {BEGIN(css_font); RETURN(NUMBER);}
  181. <css_line_height>normal      {BEGIN(css_font); RETURN(LINE_HEIGHT);}
  182. <css_font>{ident}            {RETURN(IDENT);}
  183. <css_font>{string}           {RETURN(STRING);}
  184. <css_font,css_font_size,css_list_style>[:,+] {return (*css_text);}
  185.  
  186. <css_list_style>disc|circle|square|decimal|lower-roman|upper-roman|lower-alpha|upper-alpha  {RETURN(LS_TYPE);}
  187. <css_list_style>none                        {RETURN(LS_NONE);}
  188. <css_list_style>inside|outside              {RETURN(LS_POSITION);}
  189.  
  190. <css_bg>transparent                         {RETURN(BG_COLOR);}
  191. <css_bg>none                                {RETURN(BG_IMAGE);}
  192. <css_bg>repeat|repeat-x|repeat-y|no-repeat  {RETURN(BG_REPEAT);}
  193. <css_bg>scroll|fixed                        {RETURN(BG_ATTACHMENT);}
  194. <css_bg>left|right|top|center|bottom        {RETURN(BG_POSITION);}
  195.  
  196. <css_value,css_bg,css_border>[-/+,#:]           {return (*css_text);}
  197. <css_value,css_bg>{ident}            {RETURN(IDENT);}
  198. <css_value>[)(]                      {RETURN(IDENT); /* quick b2 hack */}
  199. <css_value,css_bg>{string}           {RETURN(STRING);}
  200. <css_value,css_bg,css_border>"#"{hex3}          |
  201. <css_value,css_bg,css_border>"#"{hex6}          {RETURN(HEXCOLOR);}
  202. <css_value,css_bg,css_border>rgb\({w}{num}%?{w}\,{w}{num}%?{w}\,{w}{num}%?{w}\)  {RETURN(RGB);}
  203. <css_value,css_bg,css_list_style>url\({w}{string}{w}\)  |
  204. <css_value,css_bg,css_list_style>url\({w}([^ \n\'\")]|\\\ |\\\'|\\\"|\\\))+{w}\) {RETURN(URL);}
  205. <css_value,css_bg,css_border>{num}"%"           {RETURN(PERCENTAGE);}
  206. <css_value,css_bg,css_border>0                  |
  207. <css_value,css_bg,css_border>{num}pt/{notnm}    |
  208. <css_value,css_bg,css_border>{num}mm/{notnm}    |
  209. <css_value,css_bg,css_border>{num}cm/{notnm}    |
  210. <css_value,css_bg,css_border>{num}pc/{notnm}    |
  211. <css_value,css_bg,css_border>{num}in/{notnm}    |
  212. <css_value,css_bg,css_border>{num}px/{notnm}    {RETURN(LENGTH);}
  213. <css_value,css_bg,css_border>{num}em/{notnm}    {RETURN(EMS);}
  214. <css_value,css_bg,css_border>{num}ex/{notnm}    {RETURN(EXS);}
  215.  
  216. <css_value>{num}                 {RETURN(NUMBER);}
  217.  
  218. <css_border>none|dotted|dashed|solid|double     |
  219. <css_border>groove|ridge|inset|outset           {RETURN(BORDER_STYLE);}
  220. <css_border>thin|medium|thick                   {RETURN(BORDER_WIDTH);}
  221. <css_border>{ident}                             {RETURN(IDENT);}
  222.  
  223. <<EOF>>                   {BEGIN (0); yyterminate();}
  224. <*>.                      {RETURN(WILD);}
  225. %%
  226.