~berciu-deactivatedaccount/cristallparser/unstable-qt

« back to all changes in this revision

Viewing changes to numbersgrammar.cpp

  • Committer: Sylwke3100
  • Date: 2014-02-03 14:10:31 UTC
  • Revision ID: git-v1:166ce1967fc3953c6a7f9b770d7ff1386b240370
Add new version with rebuild method detect

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "numbersgrammar.h"
 
2
 
 
3
NumbersGrammar::NumbersGrammar(std::string Label, int Limit = 0){
 
4
    this->Label = Label;
 
5
    if (Limit != 0)
 
6
        this->Limit = 0;
 
7
}
 
8
bool NumbersGrammar::isRule(std::string& Text){
 
9
    return (isdigit(Text[0]) == true || Text[0] == '-' );
 
10
}
 
11
 
 
12
void NumbersGrammar::parse(std::string& Text, std::vector<CristallStack>& LocalStack){
 
13
    int Element = 0;
 
14
    for (char Char:Text){
 
15
        if (isdigit(Char) || Char == '-')
 
16
            Element++;
 
17
        else
 
18
            break;
 
19
        }
 
20
    if (Limit == Element || (Limit == 0)){
 
21
        LocalStack.push_back(this->getResult(boost::lexical_cast<int>(Text.substr(0,Element) ) ));
 
22
        Text.erase(0,Element);
 
23
    }
 
24
}
 
25
 
 
26
CristallStack NumbersGrammar::getResult(int Value){
 
27
    CristallStack ResultRule;
 
28
    ResultRule.Label = this->Label;
 
29
    ResultRule.Type = CristallTypes::Number;
 
30
    ResultRule.Value = Value;
 
31
    return ResultRule;
 
32
}