Home | History | Annotate | Line # | Download | only in compiler
dtcompilerparser.l revision 1.1
      1 %{
      2 /******************************************************************************
      3  *
      4  * Module Name: dtcompilerparser.l - Flex input file for table compiler lexer
      5  *
      6  *****************************************************************************/
      7 
      8 /*
      9  * Copyright (C) 2000 - 2019, Intel Corp.
     10  * All rights reserved.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions, and the following disclaimer,
     17  *    without modification.
     18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  *    including a substantially similar Disclaimer requirement for further
     22  *    binary redistribution.
     23  * 3. Neither the names of the above-listed copyright holders nor the names
     24  *    of any contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * Alternatively, this software may be distributed under the terms of the
     28  * GNU General Public License ("GPL") version 2 as published by the Free
     29  * Software Foundation.
     30  *
     31  * NO WARRANTY
     32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  * POSSIBILITY OF SUCH DAMAGES.
     43  */
     44 
     45 #include "aslcompiler.h"
     46 #include "dtcompilerparser.y.h"
     47 
     48 YYSTYPE DtCompilerlval;
     49 
     50 #define _COMPONENT          ACPI_COMPILER
     51         ACPI_MODULE_NAME    ("dtcompilerscanner")
     52 
     53 /* handle locations */
     54 
     55 int DtCompilerParsercolumn = 1;
     56 int DtCompilerParserByteOffset = 0;
     57 
     58 #define YY_USER_ACTION \
     59             DtCompilerParserlloc.first_line = DtCompilerParserlloc.last_line = DtCompilerParserlineno; \
     60             DtCompilerParserlloc.first_column = DtCompilerParsercolumn; \
     61             DtCompilerParserlloc.first_byte_offset = DtCompilerParserByteOffset; \
     62             DtCompilerParserlloc.last_column = DtCompilerParsercolumn + DtCompilerParserleng-1; \
     63             DtCompilerParsercolumn += DtCompilerParserleng; \
     64             DtCompilerParserByteOffset += DtCompilerParserleng; \
     65             DbgPrint (ASL_PARSE_OUTPUT,\
     66                 "user action occurred. DtCompilerParserlloc.first_line: %u offset: %u\n",\
     67                 DtCompilerParserlloc.first_line, DtCompilerParserlloc.first_byte_offset);
     68 %}
     69 
     70 %option nounput noinput yylineno
     71 
     72     /* Indicates a state used for parsing multiline C comments */
     73 %x ML_COMMENT
     74 %x DATA_STATE
     75 
     76 WhiteSpace      [ \t\v\r]+
     77 NewLines        [\n]+
     78 
     79     /* Avoid ", \n, and [] as a part of label name. These are not valid characters of a label name */
     80 LabelName       [^ ":\n\[\]]([^":\n\[\]]*[^" :\n\[\]])?
     81 
     82     /* Avoid ", \n, \\, and [] as a part of data. These are not valid characters of data */
     83 Data            [^ \\":\n\[\]]([^":\n\[\]\\]*[^" :\n\[\]\\])?
     84 
     85 Text            [^ ":\n][^":\n]*
     86 Comment         \[[^\n\[\]]*\]
     87 CommentField    {LabelName}{WhiteSpace}*:{WhiteSpace}{Comment}?$
     88 
     89 
     90 %%
     91 
     92 <DATA_STATE>{WhiteSpace}"\\\n" {
     93         DbgPrint(ASL_PARSE_OUTPUT,"Continuation matched\n");
     94         return (DT_PARSEOP_LINE_CONTINUATION);
     95     }
     96 
     97 ":" {
     98         DbgPrint(ASL_PARSE_OUTPUT, ": Matched\n");
     99         BEGIN (DATA_STATE);
    100         return (':');
    101     }
    102 
    103 <INITIAL,DATA_STATE>{WhiteSpace} { DbgPrint(ASL_PARSE_OUTPUT,"Whitespace matched\n"); }
    104 
    105 <INITIAL,DATA_STATE>{Comment}    { DbgPrint(ASL_PARSE_OUTPUT,"Comment matched\n"); }
    106 
    107 "/*"                     { BEGIN (ML_COMMENT); }
    108 <ML_COMMENT>"*/"         { BEGIN (INITIAL); }
    109 <ML_COMMENT>"*/\n"       { BEGIN (INITIAL); }
    110 <ML_COMMENT>([^*]|\n)+|. /* Ignore */
    111 "//".*                   /* Ignore */
    112 
    113 
    114 <DATA_STATE>{Data} {
    115       char *s;
    116       int size = strlen (DtCompilerParsertext);
    117       s=UtLocalCacheCalloc (size + 1);
    118       AcpiUtSafeStrncpy (s, DtCompilerParsertext, size + 1);
    119       DtCompilerParserlval.s = s;
    120       DbgPrint (ASL_PARSE_OUTPUT, "Data: %s\n", s);
    121       return (DT_PARSEOP_DATA);
    122 }
    123 
    124 {CommentField}  /* ignore */
    125 
    126 {LabelName} {
    127     char *s;
    128     int size = strlen (DtCompilerParsertext);
    129     s=UtLocalCacheCalloc (size + 1);
    130     AcpiUtSafeStrncpy (s, DtCompilerParsertext, size + 1);
    131     DtCompilerParserlval.s = s;
    132     DbgPrint (ASL_PARSE_OUTPUT, "Label: %s\n", s);
    133     return (DT_PARSEOP_LABEL);
    134 }
    135 
    136 
    137 <DATA_STATE>\"{Text}?\" { // remove outer quotes from the string, they are unnecessary
    138     char *s;
    139     int size = strlen (DtCompilerParsertext);
    140     s=UtLocalCacheCalloc (size - 1);
    141     AcpiUtSafeStrncpy (s, DtCompilerParsertext + 1, size - 1);
    142     DtCompilerParserlval.s = s;
    143     DbgPrint (ASL_PARSE_OUTPUT, "String Data: %s\n", s);
    144     BEGIN (INITIAL);
    145     return (DT_PARSEOP_STRING_DATA);
    146 }
    147 
    148 
    149 <INITIAL,DATA_STATE>{NewLines} {
    150     DbgPrint(ASL_PARSE_OUTPUT,
    151         "Newline matched (data state). Current line number: %u\n",DtCompilerParserlineno);
    152     BEGIN (INITIAL); DtCompilerParsercolumn = 1;
    153 }
    154 
    155 
    156 %%
    157 
    158 
    159 /*
    160  * Local support functions
    161  */
    162 
    163 void
    164 DtCompilerInitLexer (
    165     FILE                *inFile)
    166 {
    167     yyin = inFile;
    168 }
    169 
    170 void
    171 DtCompilerTerminateLexer (
    172     void)
    173 {
    174     /*
    175      * Flex/Bison increments the lineno for the EOF so decrement by 1 to get
    176      * the correct number of lines.
    177      */
    178     AslGbl_CurrentLineNumber = DtCompilerParserlineno - 1;
    179     AslGbl_InputByteCount = DtCompilerParserByteOffset;
    180 }
    181