/* This file is part of mhmake. * * Copyright (C) 2001-2010 marha@sourceforge.net * * Mhmake is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Mhmake is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Mhmake. If not, see . */ /* $Rev$ */ /* -------------- declaration section -------------- */ %require "2.4.1" %defines %define parser_class_name "mhmakeparser" %define parser_base_class_name "mhmakefileparser" %define parser_class_constructor_init ": mhmakefileparser(CommandLineVariables)" %define parser_class_constructor_param "const map &CommandLineVariables" %error-verbose %code requires { #include "mhmakefileparser.h" } %code provides { const char Test[]="dit is een test"; } %{ #include "mhmakefileparser.h" #include "rule.h" #include "util.h" %} %locations %initial-action { // Initialize the initial location. @$.initialize(&m_ptheLexer->GetInputFilename()); }; %token END 0 "end of file" %token COMMAND %token COMMA %token STRING DOLLAREXPR EQUAL COLON DOUBLECOLON VARDEF VARVAL %token IMEQUAL PEQUAL OPTEQUAL PHONY AUTODEPS EXPORT NEWLINE INCLUDEMAK SPACE VPATH %type expression nonspaceexpression simpleexpression %type maybeemptyexpression %type expression_nocolorequal simpleexpression_nocolorequal nonspaceexpression_nocolorequal %type rulecolon %start file /* -------------- rules section -------------- */ /* Sample parser. Does count Chars in a line, and lines in file */ %% file : statements { if (m_pCurrentItems) { PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetQuotedFullFileName().c_str())); AddRule(); } } ; statements : | statements statement ; space : SPACE | space SPACE ; statement: NEWLINE | SPACE | includemak | ruledef | phonyrule | autodepsrule | varassignment | imvarassignment | pvarassignment | optvarassignment | exportrule | vpathrule | COMMAND { if (!m_pCurrentRule) { m_pCurrentRule=refptr(new rule(this)); } m_pCurrentRule->AddCommand($1); PRINTF(("Adding command : %s\n",$1.c_str())); } ; includemak: { if (m_pCurrentItems) { PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetQuotedFullFileName().c_str())); AddRule(); } } INCLUDEMAK ; ruledef: expression_nocolorequal rulecolon maybeemptyexpression { if (m_pCurrentItems) { PRINTF(("Adding rule : %s\n",(*m_pCurrentItems)[0]->GetQuotedFullFileName().c_str())); AddRule(); } m_pCurrentItems=new fileinfoarray; m_pCurrentDeps=new fileinfoarray; #ifdef _DEBUG if (!ExpandExpression($1).size()) { throw string("Empty left hand side in rule: ") + $1 + " : " + $3; } #endif SplitToItems(ExpandExpression($1),*m_pCurrentItems); SplitToItems(ExpandExpression($3),*m_pCurrentDeps); m_DoubleColonRule= ($2==1) ; PRINTF(("Defining rule %s : %s\n",$1.c_str(),$3.c_str())); PRINTF((" Expanded to %s : %s\n",ExpandExpression($1).c_str(),ExpandExpression($3).c_str())); } ; rulecolon: COLON {$$=0;} | DOUBLECOLON {$$=1;} ; phonyrule: PHONY COLON expression { vector Items; SplitToItems(ExpandExpression($3),Items); vector::iterator pIt=Items.begin(); while (pIt!=Items.end()) { (*pIt)->SetPhony(); pIt++; } PRINTF(("Defining phony rule : %s\n",$3.c_str())); PRINTF((" Expanded to : %s\n",ExpandExpression($3).c_str())); } NEWLINE ; autodepsrule: AUTODEPS COLON expression { vector Items; SplitToItems(ExpandExpression($3),Items); vector::iterator pIt=Items.begin(); while (pIt!=Items.end()) { (*pIt)->SetAutoDepsScan(this); pIt++; } PRINTF(("Defining autodeps rule : %s\n",$3.c_str())); PRINTF((" Expanded to : %s\n",ExpandExpression($3).c_str())); } NEWLINE ; exportrule: EXPORT space exportstrings NEWLINE ; exportstrings : exportstring | exportstring space exportstrings ; exportstring : STRING { SetExport($1,ExpandExpression(ExpandVar($1))); PRINTF(("Exporting %s : %s\n",$1.c_str(),ExpandExpression(ExpandVar($1)).c_str())); } ; vpathrule: VPATH space nonspaceexpression space expression NEWLINE { SetvPath(ExpandExpression($3),ExpandExpression($5)); PRINTF(("Setting vpath %s to %s\n",$3.c_str(),ExpandExpression($5).c_str())); } ; varassignment: VARDEF VARVAL { m_Variables[f_strip($1,NULL)]=$2; PRINTF(("Defining variable %s to %s\n",f_strip($1,NULL).c_str(), $2.c_str())); } | STRING EQUAL maybeemptyexpression { m_Variables[$1]=$3; PRINTF(("Setting variable %s to %s\n",$1.c_str(), $3.c_str())); } ; imvarassignment: STRING IMEQUAL maybeemptyexpression { m_Variables[$1]=ExpandExpression($3); PRINTF(("Setting variable %s to %s\n",$1.c_str(), m_Variables[$1].c_str())); } ; pvarassignment: STRING PEQUAL maybeemptyexpression { m_Variables[$1]=ExpandVar($1)+g_SpaceString+$3; PRINTF(("Adding to variable %s: %s\n",$1.c_str(), $3.c_str())); } ; optvarassignment: STRING OPTEQUAL maybeemptyexpression { if (!IsDefined($1)) { m_Variables[$1]=$3; PRINTF(("Setting variable %s to %s\n",$1.c_str(), $3.c_str())); } } ; maybeemptyexpression: NEWLINE {$$=g_EmptyString;} | expression NEWLINE | expression space NEWLINE ; expression: nonspaceexpression | expression space nonspaceexpression {$$=$1+g_SpaceString+$3;} ; expression_nocolorequal: nonspaceexpression_nocolorequal | expression_nocolorequal space nonspaceexpression_nocolorequal {$$=$1+g_SpaceString+$3;} ; nonspaceexpression: simpleexpression | nonspaceexpression simpleexpression {$$=$1+$2;} ; nonspaceexpression_nocolorequal: simpleexpression_nocolorequal | nonspaceexpression_nocolorequal simpleexpression_nocolorequal {$$=$1+$2;} ; simpleexpression: simpleexpression_nocolorequal | EQUAL | COLON | DOUBLECOLON | COMMA ; simpleexpression_nocolorequal: STRING | DOLLAREXPR ; %% /* -------------- body section -------------- */ void yy::mhmakeparser::error (const yy::mhmakeparser::location_type& l, const std::string& m) { cerr << l << " -> "<