%{ /* * Copyright (C) 1999-2007 Lorenzo Bettini * * This program 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. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include "parsestruct.h" #include "outlangdefscanner.h" #include "outlangdefparserfun.h" #include "textstyles.h" #include "parserexception.h" #include "ioexception.h" using std::cerr; using std::string; using namespace srchilite; static void yyerror( const char *s ) ; static void yyerror( const string &s ) ; /// the buffer for storing errors static string errorBuffer; TextStylesPtr textstyles; string start_doc, end_doc; ColorMapPtr colorMap; CharTranslatorPtr charTranslator; const char *reference_vars[] = {"linenum", "infilename", "infile", "outfile", 0}; const char *anchor_vars[] = {"linenum", "infilename", "infile", 0}; /// used to record that the error is due to an included file not found static bool includedFileNotFound = false; %} %union { int tok ; /* command */ bool booloption ; const std::string * string ; /* string : id, ... */ int flag ; }; %token BEGIN_T END_T DOC_TEMPLATE_T NODOC_TEMPLATE_T STYLE_TEMPLATE_T STYLE_SEPARATOR_T %token BOLD_T ITALICS_T UNDERLINE_T COLOR_T BG_COLOR_T FIXED_T NOTFIXED_T %token COLORMAP_T DEFAULT_T ONESTYLE_T TRANSLATIONS_T EXTENSION_T ANCHOR_T %token REFERENCE_T INLINE_REFERENCE_T POSTLINE_REFERENCE_T POSTDOC_REFERENCE_T %token KEY STRINGDEF REGEXDEF LINE_PREFIX_T LINENUM_T WRONG_INCLUDE_FILE %% outputlang : outputlangdefs ; outputlangdefs : outputlangdefs outputlangdef | outputlangdef ; outputlangdef : DOC_TEMPLATE_T STRINGDEF STRINGDEF END_T { textstyles->docTemplate = DocTemplate(*2,ドル *3ドル); delete 2ドル; delete 3ドル; } | NODOC_TEMPLATE_T STRINGDEF STRINGDEF END_T { textstyles->noDocTemplate = DocTemplate(*2,ドル *3ドル); delete 2ドル; delete 3ドル; } | STYLE_TEMPLATE_T STRINGDEF { textstyles->starting_template = *2ドル; delete 2ドル; } | STYLE_SEPARATOR_T STRINGDEF { textstyles->style_separator = *2ドル; delete 2ドル; } | BOLD_T STRINGDEF { textstyles->bold = *2ドル; delete 2ドル; } | ITALICS_T STRINGDEF { textstyles->italics = *2ドル; delete 2ドル; } | UNDERLINE_T STRINGDEF { textstyles->underline = *2ドル; delete 2ドル; } | FIXED_T STRINGDEF { textstyles->fixed = *2ドル; delete 2ドル; } | NOTFIXED_T STRINGDEF { textstyles->notfixed = *2ドル; delete 2ドル; } | COLOR_T STRINGDEF { textstyles->color = *2ドル; delete 2ドル; } | BG_COLOR_T STRINGDEF { textstyles->bg_color = *2ドル; delete 2ドル; } | ONESTYLE_T STRINGDEF { textstyles->onestyle = *2ドル; delete 2ドル; } | EXTENSION_T STRINGDEF { textstyles->file_extension = *2ドル; delete 2ドル; } | ANCHOR_T STRINGDEF { textstyles->refstyle.anchor = TextStyle(*2,ドル anchor_vars); delete 2ドル; } | LINE_PREFIX_T STRINGDEF { textstyles->line_prefix = *2ドル; delete 2ドル; } | LINENUM_T STRINGDEF { textstyles->linenum = *2ドル; delete 2ドル; } | REFERENCE_T STRINGDEF { if (textstyles->refstyle.inline_reference.empty()) textstyles->refstyle.inline_reference = TextStyle(*2,ドル reference_vars); if (textstyles->refstyle.postline_reference.empty()) textstyles->refstyle.postline_reference = TextStyle(*2,ドル reference_vars); if (textstyles->refstyle.postdoc_reference.empty()) textstyles->refstyle.postdoc_reference = TextStyle(*2,ドル reference_vars); delete 2ドル; } | INLINE_REFERENCE_T STRINGDEF { textstyles->refstyle.inline_reference = TextStyle(*2,ドル reference_vars); delete 2ドル; } | POSTLINE_REFERENCE_T STRINGDEF { textstyles->refstyle.postline_reference = TextStyle(*2,ドル reference_vars); delete 2ドル; } | POSTDOC_REFERENCE_T STRINGDEF { textstyles->refstyle.postdoc_reference = TextStyle(*2,ドル reference_vars); delete 2ドル; } | colormap { textstyles->colorMap = colorMap; } | chartranslator { textstyles->charTranslator = charTranslator; } | WRONG_INCLUDE_FILE { // this token is used by the scanner to signal an error // in opening an include file includedFileNotFound = true; yyerror("cannot open include file " + *1ドル); delete 1ドル; YYERROR; } ; colormap : COLORMAP_T colormapentries END_T ; colormapentries : colormapentries colormapentry | colormapentry ; colormapentry : STRINGDEF STRINGDEF { (*colorMap)[*1ドル] = *2ドル; delete 1ドル; delete 2ドル; } | DEFAULT_T STRINGDEF { colorMap->setDefault(*2ドル); delete 2ドル; } ; chartranslator : TRANSLATIONS_T translations END_T ; translations : translations translation | translation ; translation : REGEXDEF REGEXDEF { charTranslator->set_translation(*1,ドル *2ドル); delete 1ドル; delete 2ドル; } %% extern int outlangdef_lex_destroy (void); void yyerror( const char *s ) { errorBuffer = s; } void yyerror( const string &s ) { yyerror(s.c_str()); } namespace srchilite { TextStylesPtr parse_outlang_def() { return parse_outlang_def("", "stdin"); } TextStylesPtr parse_outlang_def(const char *path, const char *name) { includedFileNotFound = false; outlang_parsestruct = ParseStructPtr(new ParseStruct(path, name)); textstyles = TextStylesPtr(new TextStyles); colorMap = ColorMapPtr(new ColorMap); charTranslator = CharTranslatorPtr(new CharTranslator); errorBuffer = ""; int result = 1; bool fileNotFound = false; try { if (strcmp(name, "stdin") != 0) open_outlang_file_to_scan(path, name); } catch (IOException &e) { errorBuffer = e.message; fileNotFound = true; } if (!fileNotFound) result = outlangdef_parse(); if (result != 0 && ! fileNotFound) { // make sure the input file is closed close_outlangdefinputfile(); // close it before clearing the scanner } // release scanner memory clear_outlangdefscanner (); if (result != 0 || errorBuffer.size()) { if (fileNotFound || includedFileNotFound) { throw ParserException(errorBuffer); } else { ParserException e(errorBuffer, outlang_parsestruct.get()); throw e; } } return textstyles; } }

AltStyle によって変換されたページ (->オリジナル) /