1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 %{ 17 #include <iostream> 18 #include <cerrno> 19 #include <climits> 20 #include <cstdlib> 21 #include <string> 22 23 #include "parser.hpp" 24 #include "scanner.h" 25 #include "location.hh" 26 27 static OHOS::location loc; 28 #define YY_USER_ACTION \ 29 do { \ 30 loc.columns(yyleng); \ 31 } while (0); 32 33 #undef yywrap 34 #define yywrap() 1 35 %} 36 %option c++ 37 %option noyywrap debug 38 %option yyclass="Scanner" 39 %option prefix="OHOS" 40 41 %x COMMENT 42 43 /* basic char */ 44 digit ([0-9]) 45 alpha ([A-Za-z_]) 46 id_all (({alpha}|{digit}|-)*) 47 blanks ([ \t]*) 48 49 /* regular word */ 50 number ({digit}+([.]{digit}+)?) 51 identifier ({alpha}{id_all}) 52 53 /* selector */ 54 type_selector (#{identifier}) 55 mode_selector (&:(free|full)) 56 57 /* attribute */ 58 layout_attribute (left|top|width|height) 59 align_attribute (horizon-align|vertical-align) 60 other_attribute (z-index|position) 61 62 /* value */ 63 number_value ({number}(%)?) 64 h_align_value (left|middle|right) 65 v_align_value (top|middle|bottom) 66 position_value (relative|fixed|static) 67 68 /* export for parser.y */ 69 selector ({type_selector}|{mode_selector}) 70 attribute (({layout_attribute}|{align_attribute}|{other_attribute}):) 71 value ((initial|{number_value}|{h_align_value}|{v_align_value}|{position_value});) 72 73 %% 74 75 %{ 76 loc.step(); // for C++ 77 %} 78 79 "//" { 80 BEGIN COMMENT; 81 } 82 83 "{" { 84 return OHOS::Parser::make_CHAR_L_BRACE(loc); 85 } 86 87 "}" { 88 return OHOS::Parser::make_CHAR_R_BRACE(loc); 89 } 90 91 {selector} { 92 #ifdef LEXER_DEBUG 93 printf("selector: %s\n", yytext); 94 #endif 95 return OHOS::Parser::make_SELECTOR(yytext, loc); 96 } 97 98 {attribute} { 99 #ifdef LEXER_DEBUG 100 printf("attribute: %s\n", yytext); 101 #endif 102 return OHOS::Parser::make_ATTRIBUTE(yytext, loc); 103 } 104 105 {value} { 106 #ifdef LEXER_DEBUG 107 printf("value: %s\n", yytext); 108 #endif 109 return OHOS::Parser::make_VALUE(yytext, loc); 110 } 111 112 "\n" { 113 } 114 115 . { 116 if (yytext[0] != ' ') { 117 #ifdef LEXER_DEBUG 118 printf("ignore '%s'\n", yytext); 119 #endif 120 } 121 } 122 123 <COMMENT>\n { 124 BEGIN INITIAL; 125 } 126 127 <COMMENT>. { 128 } 129 130 <<EOF>> { 131 return OHOS::Parser::make_END(loc); 132 } 133 134 %% 135