about summary refs log blame commit diff stats
path: root/014literal_noninteger.cc
blob: 5f0b0327f25c9d48b60e1b30aca82d711a4dbbef (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                                            
                                                                                  












                                                                                

                                                            








                                                                    
//: Support literal non-integers.
//: '3.14159:literal' is ugly, so we'll just say '3.14159' for non-integers.

:(scenarios load)
:(scenario noninteger_literal)
recipe main [
  1:number <- copy 3.14159
]
+parse:   ingredient: {name: "3.14159", properties: ["3.14159": "literal-number"]}

:(after "reagent::reagent(string s)")
  if (is_noninteger(s)) {
    name = s;
    types.push_back(0);
    properties.push_back(pair<string, vector<string> >(name, vector<string>()));
    properties.back().second.push_back("literal-number");
    set_value(to_double(s));
    return;
  }

:(code)
bool is_noninteger(const string& s) {
  return s.find_first_not_of("0123456789-.") == string::npos
      && s.find('.') != string::npos;
}

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;
}
an> background-color: #ECF5F5; } .inherited td { font-size: 82%; padding-left: 1em; text-indent: -0.8em; padding-right: 0.2em; } .inheritedlbl { font-style: italic; } /* ---------------------------------------- */ /* Racket text styles */ .RktIn { color: #cc6633; background-color: #eeeeee; } .RktInBG { background-color: #eeeeee; } .RktRdr { } .RktPn { color: #843c24; } .RktMeta { color: black; } .RktMod { color: black; } .RktOpt { color: black; } .RktKw { color: black; /* font-weight: bold; */ } .RktErr { color: red; font-style: italic; } .RktVar { color: #262680; font-style: italic; } .RktSym { color: #262680; } .RktValLink { text-decoration: none; color: blue; } .RktModLink { text-decoration: none; color: blue; } .RktStxLink { text-decoration: none; color: black; /* font-weight: bold; */ } .RktRes { color: #0000af; } .RktOut { color: #960096; } .RktCmt { color: #c2741f; } .RktVal { color: #228b22; } /* ---------------------------------------- */ /* Some inline styles */ .together { width: 100%; } .prototype, .argcontract, .RBoxed { white-space: nowrap; } .prototype td { vertical-align: text-top; } .longprototype td { vertical-align: bottom; } .RktBlk { white-space: inherit; text-align: left; } .RktBlk tr { white-space: inherit; } .RktBlk td { vertical-align: baseline; white-space: inherit; } .argcontract td { vertical-align: text-top; } .highlighted { background-color: #ddddff; } .defmodule { width: 100%; background-color: #F5F5DC; } .specgrammar { float: right; } .RBibliography td { vertical-align: text-top; } .leftindent { margin-left: 1em; margin-right: 0em; } .insetpara { margin-left: 1em; margin-right: 1em; } .Rfilebox { } .Rfiletitle { text-align: right; margin: 0em 0em 0em 0em; } .Rfilename { border-top: 1px solid #6C8585; border-right: 1px solid #6C8585; padding-left: 0.5em; padding-right: 0.5em; background-color: #ECF5F5; } .Rfilecontent { margin: 0em 0em 0em 0em; } /* ---------------------------------------- */ /* For background labels */ .RBackgroundLabel { float: right; width: 0px; height: 0px; } .RBackgroundLabelInner { position: relative; width: 25em; left: -25.5em; top: 0px; text-align: right; color: white; z-index: 0; font-weight: bold; } .RForeground { position: relative; left: 0px; top: 0px; z-index: 1; }