Skip to content

Commit 259ed35

Browse files
committed
More await corrections
1 parent 69f7b5d commit 259ed35

File tree

6 files changed

+42
-9
lines changed

6 files changed

+42
-9
lines changed

GlowScriptOffline/glowscript_libraries/RScompiler.2.9.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GlowScriptOffline/glowscript_libraries/compiler.2.9.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/VPythonDocs/text_output.html

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,38 @@ <h1 class="Heading-1"> <font color="#0000a0">The print function</font></h1>
7474
<p class="Normal">The elements &quot;sep=..., end=...&quot; must be the last arguments in the print statement. </p>
7575
<h1 class="Heading-1"><font color="#0000a0"> String formatting</font></h1>
7676
<div>
77-
<p class="Normal">Python has a powerful mechanism for formatting a string. This has now been implemented in GlowScript (for VPython, RapydScript, and JavaScript). Here is an example (in VPython):</p>
77+
<p class="Normal">The easiest way to format a string is to use what are called &quot;f-strings&quot;, so-called because the string is preceded by &quot;f&quot; or, equivalently, &quot;F&quot;:</p>
78+
</div>
79+
<div></div>
80+
<div>
81+
<p class="program">V = 13.47<br>
82+
units = 'liters'
83+
<br />
84+
s = f&quot;There are {V:.1f} {units}.&quot;<br />
85+
print(s) # &quot;There are 13.5 liters.&quot; </p>
86+
</div>
87+
<div>
88+
<p class="Normal">The string begins with an initial &quot;f&quot; (or &quot;F&quot;). Quantities within braces are evaluated and converted to strings. The form {V:.1f} means &quot;evaluate the variable V and display it in fixed format, with 1 digit after the decimal point. The value 13.47 is rounded to 13.5. If you specify {V:12.3f}, what will be displayed is &quot;      13.470&quot;, with 6 spaces before the number, plus the 6 digits of &quot;13.470&quot; (3 after the decimal point), for a total of 12 characters.</p>
89+
<p class="Normal">A variable quantity such as V above can be a call to a function, whether your own function or a built-in function such as sqrt(). In fact, you can have entire expressions within braces, such as &quot;10*V + sqrt(pi)&quot;.</p>
90+
</div>
91+
<div></div>
92+
<div></div>
93+
<div></div>
94+
<div>
95+
<p class="Normal">There are many formats available in addtion to fixed format numbers: b for binary (base 2), o for octal (base 8), x for hexidecimal (base 16; 28 displays as 1c), d for decimal integer, e for exponential (e.g. 5.32e-7), c for character code (e.g. converts &quot;b&quot; to 97), % for percent (displays 0.34 as 34%). The E exponential format gives 5.32E-7 and the X hexidecimal format gives 1C. The g format (g for general) is particularly useful because it flips between fixed and exponential formats depending on the size of the number.</p>
96+
</div>
97+
<div></div>
98+
<div>
99+
<p class="Normal">Currently the standard Python way to use f-strings in multiline situations does not work in GlowScript, so it is necessary to insert &quot;\n&quot; new-line characters: <span class="program">f&quot;There are\n{V:12.3f} {units}.&quot;</span> </p>
100+
<div></div>
101+
<div></div>
102+
<div>
103+
<div> </div>
104+
</div>
105+
</div>
106+
<div>
107+
<h1 class="Heading-1"><font color="#0000a0">An older form of string formatting</font></h1>
108+
<p class="Normal">Here is an older form of string formatting):</p>
78109
</div>
79110
<div></div>
80111
<div>
@@ -92,7 +123,7 @@ <h1 class="Heading-1"><font color="#0000a0"> String formatting</font></h1>
92123
</div>
93124
<div></div>
94125
<div>
95-
<p class="Normal">The element &quot;{}&quot; indicates that the default method for representing an argument should be used. In this case &quot;bucket&quot; is displayed.</p>
126+
<p class="Normal">The element &quot;{}&quot; indicates that the default method for representing an argument should be used. In this case &quot;liters&quot; is displayed.</p>
96127
</div>
97128
<div></div>
98129
<div>

lib/compiling/GScompiler.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,13 +1012,15 @@ where compile() was called, in untrusted/run.js.
10121012
program = prog.replace(/\n\n\n\n/g, '') // eliminate lots of white space
10131013

10141014
start = initialstart
1015-
// RapydScript converts "box(color=color.red" into
1015+
// RapydScript converts "box(color=color.red") into
10161016
// RS_interpolate_kwargs.call(this, box, [RS_desugar_kwargs({color: color.red})]);
1017-
var kw = 'RS_interpolate_kwargs.call\\(([^,]*),\\s([^,\\.]*)'
1017+
var kw = '(RS_interpolate_kwargs.call)\\(([^,]*),\\s([^,\\.]*)'
10181018
while (true) {
10191019
var m = program.slice(start).match(kw)
10201020
if (m == null) break
1021-
if (m[1] != 'this') {
1021+
if (m[2] != 'this') {
1022+
program = program.slice(0,start+m.index)+'await '+program.slice(start+m.index)
1023+
} else if (fcts.indexOf(m[3]) >= 0) {
10221024
program = program.slice(0,start+m.index)+'await '+program.slice(start+m.index)
10231025
}
10241026
start += m.index+kw.length

package/RScompiler.2.9.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/compiler.2.9.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)