diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-03-09 02:56:27 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-03-09 02:56:27 -0800 |
commit | 4690ce81e079fc58cae8d6d583e5e3eb3ed81a83 (patch) | |
tree | b62ebb7e9a7fb88f8db3a168354acfebced83dd2 /html/015literal_noninteger.cc.html | |
parent | 1d079fc574a35f39fd52e3de23a1c8bfa45238ae (diff) | |
download | mu-4690ce81e079fc58cae8d6d583e5e3eb3ed81a83.tar.gz |
2743
Looks like "TOhtml | <other command>" doesn't work on Mac OS X for some reason..
Diffstat (limited to 'html/015literal_noninteger.cc.html')
-rw-r--r-- | html/015literal_noninteger.cc.html | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/html/015literal_noninteger.cc.html b/html/015literal_noninteger.cc.html index 89a405df..e2aa9d4e 100644 --- a/html/015literal_noninteger.cc.html +++ b/html/015literal_noninteger.cc.html @@ -3,68 +3,61 @@ <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Mu - 015literal_noninteger.cc</title> -<meta name="Generator" content="Vim/7.4"> -<meta name="plugin-version" content="vim7.4_v1"> +<meta name="Generator" content="Vim/7.3"> +<meta name="plugin-version" content="vim7.3_v6"> <meta name="syntax" content="cpp"> -<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy="> -<meta name="colorscheme" content="minimal"> +<meta name="settings" content="use_css"> <style type="text/css"> <!-- -pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; } +pre { font-family: monospace; color: #eeeeee; background-color: #080808; } body { font-family: monospace; color: #eeeeee; background-color: #080808; } -* { font-size: 1.05em; } -.traceContains { color: #008000; } .cSpecial { color: #008000; } -.Comment { color: #9090ff; } -.Delimiter { color: #a04060; } -.Special { color: #ff6060; } .Identifier { color: #804000; } +.Normal { color: #eeeeee; background-color: #080808; } +.traceContains { color: #008000; } +.Special { color: #ff6060; } .Constant { color: #00a0a0; } +.Delimiter { color: #a04060; } +.Comment { color: #9090ff; } --> </style> - -<script type='text/javascript'> -<!-- - ---> -</script> </head> <body> -<pre id='vimCodeElement'> +<pre> <span class="Comment">//: Support literal non-integers.</span> <span class="Delimiter">:(scenarios load)</span> <span class="Delimiter">:(scenario noninteger_literal)</span> -recipe main [ +def main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3.14159</span> ] <span class="traceContains">+parse: ingredient: 3.14159: "literal-fractional-number"</span> <span class="Delimiter">:(after "Parsing reagent(string s)")</span> -if <span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span class="Normal">if</span> <span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> name = s<span class="Delimiter">;</span> - type = new type_tree<span class="Delimiter">(</span><span class="Constant">"literal-fractional-number"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> + type = <span class="Normal">new</span> type_tree<span class="Delimiter">(</span><span class="Constant">"literal-fractional-number"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> set_value<span class="Delimiter">(</span>to_double<span class="Delimiter">(</span>s<span class="Delimiter">));</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> -bool is_noninteger<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span class="Normal">bool</span> is_noninteger<span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-."</span><span class="Delimiter">)</span> == string::npos <span class="Comment">// no other characters</span> && s<span class="Delimiter">.</span>find_first_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos <span class="Comment">// at least one digit</span> && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'-'</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">)</span> == string::npos <span class="Comment">// '-' only at first position</span> && std::count<span class="Delimiter">(</span>s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> s<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">'.'</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// exactly one decimal point</span> <span class="Delimiter">}</span> -double to_double<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> - char* end = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span class="Normal">double</span> to_double<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> + <span class="Normal">char</span>* end = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span class="Comment">// safe because string.c_str() is guaranteed to be null-terminated</span> - double result = strtod<span class="Delimiter">(</span>n<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">);</span> + <span class="Normal">double</span> result = strtod<span class="Delimiter">(</span>n<span class="Delimiter">.</span>c_str<span class="Delimiter">(),</span> &end<span class="Delimiter">);</span> assert<span class="Delimiter">(</span>*end == <span class="cSpecial">'\0'</span><span class="Delimiter">);</span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span class="Delimiter">}</span> -void test_is_noninteger<span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span class="Normal">void</span> test_is_noninteger<span class="Delimiter">()</span> <span class="Delimiter">{</span> CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">"1234"</span><span class="Delimiter">));</span> CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">"1a2"</span><span class="Delimiter">));</span> CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">"234.0"</span><span class="Delimiter">));</span> @@ -81,4 +74,3 @@ void test_is_noninteger<span class="Delimiter">()</span> <span class="Delimiter" </pre> </body> </html> -<!-- vim: set foldmethod=manual : --> |