2012-02-27 53 views
0

我正在玩gb reasearch的ax解析器框架,並且遇到了gcc 4.6.2的問題。用VC++ 10編譯器就沒有問題。AX Parser Generator和mingw gcc 4.6 operator&

行:

auto space = axe::r_any(" \t"); 

// trailing spaces 
auto trailing_spaces = *space & (comma | endl); 

錯誤:

D:\Projekte\axeparser-build-desktop-Qt_4_8_0__Qt480mingw__Debug\..\axeparser\main.cpp:19: error: conversion from 'axe::r_and_t<axe::r_many_t<axe::r_pred_t<axe::is_any_t<const char*> >&, axe::r_empty_t>, axe::r_or_t<axe::r_char_t<char>&, axe::r_char_t<char>&> >' to non-scalar type 'axe::r_and_t<axe::r_many_t<axe::r_pred_t<axe::is_any_t<const char*> >&, axe::r_empty_t>&, axe::r_or_t<axe::r_char_t<char>&, axe::r_char_t<char>&>&>' requested 

我打從PDF的CSV-例。這裏是我使用的代碼:

#include <iostream> 
#include <axe.h> 
#include <iostream> 
#include <string.h> 

using namespace std; 


template<class I> 
void csv(I begin, I end) 
{ 
    // define comma rule 
    auto comma = axe::r_lit(','); 
    // endl matches end of line symbol 
    auto endl = axe::r_lit('\n'); 
    // space matches ' ' or '\t' 
    auto space = axe::r_any(" \t"); 
    // trailing spaces 
    auto trailing_spaces = *space & (comma | endl); 
    std::string value; 
    // create extractor to print matched value 
    auto print_value = axe::e_ref([&value](I, I) 
    { 
     std::cout << "<" << value << ">"; 
    }); 
    // rule for comma separated value 
    auto csv_str = *space & +(axe::r_printable() - trailing_spaces) 
     >> value & *space; 
    // rule for single string of comma separated values 
    auto line = *((csv_str & comma) >> print_value) 
     & csv_str >> print_value 
     & endl >> axe::e_ref([](I, I) 
    { 
     std::cout << "\n"; 
    }); 
    // file contaning many csv lines 
    auto csv_file = +line | axe::r_fail([](I i1, I i2) { 
             std::cout << "\nFailed: " << std::string(i1, i2); 
           }); 
           csv_file(begin, end); 
} 

int main() 
{ 
    auto space = axe::r_lit(' '); 
    auto spaces = space & space & space; 
    std::string moin = "232323233"; 
    csv(moin.begin(), moin.end()); 
} 

Cann任何人都可以幫我解決這個錯誤?不能gcc 4.6處理自動類型?我得到與|相同的錯誤(或運營商)。該怎麼辦?

非常感謝!

+0

我只是試圖斧:: r_and_t <斧:: r_many_t <斧:: r_pred_t <斧:: is_any_t >&,斧:: r_empty_t>,斧:: r_or_t <斧:: r_char_t &,斧:: r_char_t &>> trailing_spaces = * space&(comma | endl); 而gcc編譯它。看起來像GCC是問題... – extreme001 2012-02-27 15:48:35

回答

1

這是gcc版本4.6.x中的一個bug,它在4.7.0版本中修復了。如果您無法升級編譯器,請使用axe::r_rule<Iterator>而不是auto

+0

謝謝! YOu有一些來自boost :: spirit和AX的比較? – extreme001 2012-11-18 16:58:53