Boost Spirit Signals Successful Parsing Despite Token Being Incomplete

前端 未结 3 1938
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 04:44

I have a very simple path construct that I am trying to parse with boost spirit.lex.

We have the following grammar:

token := [a-z]+
path := (token :          


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-21 05:18

    The problem lies in the meaning of first and last after your call to tokenize_and_parse. first==last checks if your string has been completely tokenized, you can't infer anything about grammar. If you isolate the parsing like this, you obtain the expected result:

      PathTokens tokens;
      PathGrammar grammar(tokens);
    
      BaseIteratorType first = str.begin();
      BaseIteratorType last = str.end();
    
      LexerType::iterator_type lexfirst = tokens.begin(first,last);
      LexerType::iterator_type lexlast = tokens.end();
    
    
      bool r = parse(lexfirst, lexlast, grammar);
    
      std::cerr << r << " " << (lexfirst==lexlast) << "\n";
    

提交回复
热议问题