about summary refs log tree commit diff stats
path: root/wiki/inc/lang/cy/editrev.txt
Commit message (Expand)AuthorAgeFilesLines
* installed dokuwiki, added to navbar, updated newsahriman2018-12-031-0/+2
015-05-17 00:52:23 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-05-17 00:52:23 -0700 1390 - support non-integer literals' href='/akkartik/mu/commit/014literal_noninteger.cc?h=main&id=6f8f9fb53b5a7ef26496d496a4b93266c78d6332'>6f8f9fb5 ^
1ead3562 ^
6f8f9fb5 ^

acc4792d ^
6f8f9fb5 ^
1f59be84 ^


c4e143d6 ^
1f59be84 ^


6f8f9fb5 ^


ad6eb923 ^



6f8f9fb5 ^








dd3bd122 ^





8ec12cbe ^


ad6eb923 ^




dd3bd122 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
                                 


                              
          

                          
                                                            
 


                                    
                                                       


                          


                                     



                                                                                    








                                                                    





                                


                             




                                
 
//: Support literal non-integers.

:(scenarios load)
:(scenario noninteger_literal)
def main [
  1:number <- copy 3.14159
]
+parse:   ingredient: {3.14159: "literal-fractional-number"}

:(after "Parsing reagent(string s)")
if (is_noninteger(s)) {
  name = s;
  type = new type_tree("literal-fractional-number", 0);
  set_value(to_double(s));
  return;
}

:(code)
bool is_noninteger(const string& s) {
  return s.find_first_not_of("0123456789-.") == string::npos  // no other characters
      && s.find_first_of("0123456789") != string::npos  // at least one digit
      && s.find('-', 1) == string::npos  // '-' only at first position
      && std::count(s.begin(), s.end(), '.') == 1;  // exactly one decimal point
}

double to_double(string n) {
  char* end = NULL;
  // safe because string.c_str() is guaranteed to be null-terminated
  double result = strtod(n.c_str(), &end);
  assert(*end == '\0');
  return result;
}

void test_is_noninteger() {
  CHECK(!is_noninteger("1234"));
  CHECK(!is_noninteger("1a2"));
  CHECK(is_noninteger("234.0"));
  CHECK(!is_noninteger("..."));
  CHECK(!is_noninteger("."));
  CHECK(is_noninteger("2."));
  CHECK(is_noninteger(".2"));
  CHECK(is_noninteger("-.2"));
  CHECK(is_noninteger("-2."));
  CHECK(!is_noninteger("--.2"));
  CHECK(!is_noninteger(".-2"));
  CHECK(!is_noninteger("..2"));
}