Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
cfry committed Nov 20, 2018
1 parent 300634d commit d2f0f06
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 68 deletions.
102 changes: 99 additions & 3 deletions blocksde/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

function blocks_init(){
javascript_pane_header_wrapper_id.appendChild(
make_dom_elt("span",
/*make_dom_elt("span",
{id:"text_blocks_toggle_id",
title: "Toggle editor view between text and blocks.",
"font-size":"20px",
Expand All @@ -20,7 +20,16 @@ function blocks_init(){
margin:"0px",
"vertical-align":"20%",
onclick:"toggle_text_blocks_display()"},
" ⧉ "))
" ⧉ "))*/
make_dom_elt("select",
{id:"code_view_kind_id",
title:"Translate the Editor pane to a different syntax for viewing your code.",
"background-color": "#4cc9fd",
"vertical-align":"50%",
onclick:"change_code_view_kind()"},
"<option value='JS'>JS</option><option value='Blocks'>Blocks</option><option value='DefEng'>DefEng</option>"
)
)
}

function make_blocksde_dom_elt(){
Expand Down Expand Up @@ -53,7 +62,7 @@ var blocksde_dom_elt = null



function toggle_text_blocks_display(){
/*function toggle_text_blocks_display(){
if (Editor.view == "text"){
out("installing blocks")
let src = Editor.get_javascript("auto") //must do before the switch
Expand Down Expand Up @@ -97,6 +106,93 @@ function toggle_text_blocks_display(){
Editor.view = "text"
myCodeMirror.focus()
}
}*/

function change_code_view_kind(){
let new_view_kind = code_view_kind_id.value
if (Editor.view == "JS"){ //old_view_kind
if (new_view_kind == "Blocks"){ js_to_blocks() }
else if (new_view_kind == "DefEng"){ js_to_defeng() }
}
else if(Editor.view == "Blocks"){ //old_view_kind
if (new_view_kind == "JS"){ blocks_to_js() }
else if (new_view_kind == "DefEng"){ blocks_to_defeng() }
}
else if(Editor.view == "DefEng") { //old_view_kind
if (new_view_kind == "JS") { defeng_to_js() }
else if (new_view_kind == "Blocks"){ defeng_to_blocks() }
}
}

function js_to_blocks(){
out("installing blocks")
let src = Editor.get_javascript() //must do before the switch
let block_to_install
try{
if (src.trim() != ""){block_to_install = JS2B.js_to_blocks(src.trim())} //do before switching views in case this errors, we want to stay in text view
}
catch(err){
warning("Could not convert JavaScript source to blocks due to error:<br/>" +
err.message +
"<br/> Make sure your JS text evals without errors before switching to blocks.")
return
}
if (!the_codemirror_elt) { //haven't used blocksde yet so initialize it
the_codemirror_elt = document.getElementsByClassName("CodeMirror")[0]
blocksde_dom_elt = make_blocksde_dom_elt()
let blocks_style_content = file_content(__dirname + "/blocksde/style2.css")
let style_elt = make_dom_elt("style", {}, blocks_style_content) //"* { background-color:blue;}")
blocksde_dom_elt.appendChild(style_elt)
replace_dom_elt(the_codemirror_elt, blocksde_dom_elt) //must occur before calling make_workspace_instance
//because that needs workspace_container_id to be installed in order to
//install workspace_id inside it
Workspace.make_workspace_instance(
//the_codemirror_elt.offsetWidth, the_codemirror_elt.offsetHeight //this vals are always zero
)
}
else { replace_dom_elt(the_codemirror_elt, blocksde_dom_elt) }
Workspace.inst.clear_blocks()
if (block_to_install){ //we've got non empty src code so turn it into blocks.
install_top_left_block(block_to_install)
}
text_blocks_toggle_id.style["background-color"] = "#AAFFAA"
Editor.view = "Blocks"
}

function blocks_to_js(){
out("installing text")
let js = Workspace.inst.to_js()
replace_dom_elt(blocksde_dom_elt, the_codemirror_elt)
text_blocks_toggle_id.style["background-color"] = "#CCCCCC"
Editor.set_javascript(js)
Editor.view = "JS"
myCodeMirror.focus()
}

var old_source_defeng = "" //kludge to fake JS to defeng
function js_to_defeng(){
let defeng = old_source_defeng //usualy wrong but ok for limited demos if you first do a defeng_to_js()
Editor.set_javascript(defeng)
Editor.view = "DefEng"
}

function defeng_to_js(){
let defeng = Editor.get_javascript()
old_source_defeng = defeng //kludge for js_to_defeng
let js = DE.de_to_js(defeng)
Editor.set_javascript(js)
Editor.view = "JS"
}

function blocks_to_defeng(){
blocks_to_js()
js_to_defeng()
}

function defeng_to_blocks(){
old_source_defeng = Editor.get_javascript("auto") //kludge
defeng_to_js()
js_to_blocks()
}


40 changes: 24 additions & 16 deletions de/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ DE.ops = {"less than": "<",
"also": "&&",
"or": "||"
}
DE.peg = require("pegjs")
DE.peg = require("pegjs")
DE.PegTracer = require('pegjs-backtrace');

DE.parser = DE.peg.generate(
`start = result:expr { return result }
expr = before_com:comment* ws_or_not result:(fn_def / assignment / maker / sentence / string1 / path / variable / undefined / number) ws_or_not after_com:comment*
{ return before_com + result + after_com }
`start = result:exprs { return result }
exprs = ws_or_not first_exper:expr rest_expers:(ws expr)* {
let result = first_exper
for(let ex of rest_expers) {
result += "\\n" + ex[1]
}
return result
}
expr = result:(fn_def / assignment / maker / sentence / string1 / path / variable / undefined / number) {
return result
}
maker = "make" ws (("an" / "a") ws)? subj:subject ws "with" ws args:arguments? sent_end
{ if (subj == "Array") {
args = args.substring(1, args.length - 1)
Expand All @@ -100,17 +108,17 @@ assignment = scope:(("variable" / "local") ws)? loc:(path / variable)
return the_scope + loc + " = " + val
}
fn_def = "to" ws sentence ws_or_not eb:exprs_block
{ let result = "function " + name + args + eb
fn_def = "to" ws name_and_args:sentence ws_or_not eb:exprs_block{
debugger
let result = "function " + name_and_args + eb
console.log("got fn_def: " + result)
return result
}
exprs_block = "do" ws the_expers:(expr ws)* "!" {
console.log("got expers_block with: " + the_expers)
let result = "{"
for(expr of the_expers){
}
result += "}"
exprs_block = "do" ws the_exprs:exprs ws_or_not "!" {
debugger;
console.log("got exprs_block with: " + the_exprs)
let result = "{" + the_exprs + "}"
return result
}
sentence = result:(sent_subj_verb_args / sent_verb_args / sent_subj_verb / sent_verb) {
Expand Down Expand Up @@ -147,7 +155,6 @@ verb = ` + DE.make_verb_rule_expers() + ` {
}
arguments = var_num1:argument var_nums:(arg_sep argument)* {
let args = var_num1
debugger
out("hi")
//get rid of trailing undefined args as would happen with DE "nothing"
for(let i = (var_nums.length - 1); i >= 0; i--){
Expand All @@ -171,9 +178,11 @@ argument = arg_name:(variable ws "of" ws)? the_expr:expr {
if(arg_name) { prefix = arg_name[0] + ": " }
let result = prefix + the_expr
console.log("got arg: " + result)
return
return result
}
arg_sep "arg_sep" = (ws "and" ws) / (ws_or_not "," ws_or_not) { return ", " }
arg_sep "arg_sep" = (ws "and" ws) / (ws_or_not "," ws_or_not) {
console.log("got arg_sep: " + text())
return ", " }
Expand Down Expand Up @@ -256,7 +265,6 @@ string1 = ('"' [^"]* '"') / ("'" [^\\']* "'") {
// HEXDIG = [0-9a-f]i
"to" ws name:variable ws "with" ws args:arguments sent_end ws eb:exprs_block
*/


8 changes: 6 additions & 2 deletions de/de_testsuite.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

new TestSuite("DE comparison",
['DE.de_to_js("4 less than with 67.")', '"(4 < 67)"'],
['DE.de_to_js("4 more than with 67.")', '"(4 > 67)"'],
Expand Down Expand Up @@ -89,9 +90,12 @@ new TestSuite("DE assignment",
['DE.de_to_js("variable bar means 6.")', '"var bar = 6"'],
['DE.de_to_js("local bar means 6.")', '"let bar = 6"']
)
new TestSuite("multiple expressions",
['DE.de_to_js("foo means 2. bar with 123.")', '"foo = 2\\nbar(123)"']
)

DE.de_to_js("to double with num. do num1 plus with num2.!")
DE.de_to_js("double with num.")
DE.de_to_js("to double with num. do num plus with num.!")
DE.de_to_js("double with 3.")



Expand Down
7 changes: 4 additions & 3 deletions doc/ref_man.html
Original file line number Diff line number Diff line change
Expand Up @@ -1926,14 +1926,15 @@
Other options are: "sine", "square", "sawtooth".<br/>
<b>callback</b> A function of no arguments that is called when the beep finishes playing.
Default: null, meaning do nothing.<br/>
<i>Example</i>: <pre><code title="not in TestSuite">
<i>Examples</i>:<br/>
<code> beep() </code>
<pre><code title="not in TestSuite">
beep({dur: 0.125,
frequency: 440,
volume: 1,
waveform: "triangle",
callback: function(){beep({dur: 0.125, frequency: 493.88})}
})
</code></pre>
}) </code></pre>
</details>

<details id="beeps_doc_id" class="doc_details"><summary>beeps</summary>
Expand Down
23 changes: 23 additions & 0 deletions doc/release_notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@
.doc_details summary { font-weight: 600; }
</style>

<details class="doc_details"><summary>v 2.5.13, Nov 20, 2018</summary>
Highlights: bug fixes.
<ul>
<li> J6_MEASURED_TORQUE swapped with J7_MEASURED_TORQUE
in robot_status table.</li>

<li> While reading robot status into DDE from Dexter, adjusted conversion for J6.</li>

<li> robot status window widened to accommodate long numbers.</li>


<li> Fixed bug in robot status dialog that when switching between
robots the table wasn't updated.
Also fixed bug that when switching to a defined robot that
never had a job run on it, it errored.</li>

<li> robot status dialog "Run Update Job" button now works.</li>

<li> Fixed bug when a file in DDE's menu of files has only a name and no folder.
It now defaults the folder to "dde_apps".</li>
</ul>
</details>

<details class="doc_details"><summary>v 2.5.12, Nov 18, 2018</summary>
Highlights: new Job() with no args now works. Many bug fixes.
<ul>
Expand Down
18 changes: 11 additions & 7 deletions editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var myCodeMirror
function Editor(){} //just a namespace of *some* internal fns
Editor.current_file_path = null //could be "new file" or "/Users/.../foo.fs"

Editor.view = "text"
Editor.view = "JS"

Editor.init_editor = function(){
myCodeMirror = CodeMirror.fromTextArea(js_textarea_id,
Expand Down Expand Up @@ -145,7 +145,8 @@ Editor.files_menu_path_to_path = function(menu_path){
let name_and_fold = menu_path.split(" ")
let name = name_and_fold[0]
let fold = name_and_fold[1]
if (fold.startsWith("dde_apps/")){
if (!fold) { fold = dde_apps_dir + "/" }
else if (fold.startsWith("dde_apps/")){
fold = dde_apps_dir + fold.substring(8)
}
let path = fold + name
Expand Down Expand Up @@ -219,10 +220,13 @@ Editor.get_any_selection = function(){
}
sel_text = Editor.get_cmd_selection()
if(sel_text.length > 0 ) { return sel_text }
if (Editor.view == "text") {
if (Editor.view == "JS") {
sel_text = myCodeMirror.doc.getValue().substring(Editor.selection_start(), Editor.selection_end())
}
else { //blocks view
else if (Editor.view == "DefEng") {
sel_text = myCodeMirror.doc.getValue().substring(Editor.selection_start(), Editor.selection_end())
}
else { //Blocks view
sel_text = Workspace.inst.get_javascript(use_selection=true)
}
if(sel_text.length > 0) { return sel_text }
Expand Down Expand Up @@ -251,7 +255,7 @@ Editor.get_javascript = function(use_selection=false){
//if use_selection is true, return it.
// if false, return whole buffer.
// if "auto", then if sel, return it, else return whole buffer.
if(Editor.view == "text") {
if((Editor.view == "JS") || (Editor.view == "DefEng")) {
let full_src = myCodeMirror.doc.getValue() //$("#js_textarea_id").val() //careful: js_textarea_id.value returns a string with an extra space on the end! A crhome bug that jquery fixes
if (use_selection){
let sel_text = full_src.substring(Editor.selection_start(), Editor.selection_end())
Expand All @@ -263,7 +267,7 @@ Editor.get_javascript = function(use_selection=false){
}
else { return full_src }
}
else if (Editor.view == "blocks"){
else if (Editor.view == "Blocks"){
return Workspace.inst.get_javascript(use_selection)
}
else { shouldnt("Editor.get_javascript found invalid Editor.view of: " + Editor.view) }
Expand Down Expand Up @@ -1308,7 +1312,7 @@ Editor.skip_forward_over_whitespace = function(full_src, cursor_pos){
return full_src.length
}

//______literal stirngs ________
//______literal strings ________
Editor.is_quote = function(char){ return (`"'` + "`").includes(char) }

// pos of the quote or null
Expand Down
16 changes: 14 additions & 2 deletions eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,17 @@ function fix_code_to_be_evaled(src){
}

//part 1 of 3.
//Onlu called by eval_button_action
//when this is called, there is no selection, so either we're evaling the whole editor buffer
//or the whole cmd line.
function eval_js_part1(step=false){
let src = Editor.get_javascript("auto") //if no selection get whole buffer, else get just the selection
//tricky: when button is clicked, Editor.get_any_selection() doesn't work,
//I guess because the button itself is now in focus,
//so we grab the selection on mousedown of the the Eval button.
//then use that here if its not "", otherwise, Editor.get_javascript("auto"), getting the whol editor buffer
let src = ((selected_text_when_eval_button_clicked.length > 0) ?
selected_text_when_eval_button_clicked :
Editor.get_javascript("auto"))
//we do NOT want to pass to eval part 2 a trimmed string as getting its char
//offsets into the editor buffer correct is important.
if (src.trim() == ""){
Expand All @@ -62,6 +69,11 @@ function eval_js_part1(step=false){
"in the Documentation pane for help.")
}
else{
if (Editor.view == "DefEng") {
src = DE.de_to_js(src)
//out("<code>" + src + "</code>") //don't need this as JS is printed in Output pane after "Eval result of"
}
//must add "debugger" after converting DefEng to JS.
eval_js_part2((step? "debugger; ": "") + src)
}
}
Expand Down Expand Up @@ -202,7 +214,7 @@ function error_message_start_and_end_pos(err){
//that I can't parse, so just bail.
}
}

//action for the Eval&Start button
function eval_and_start(){
let sel_text = Editor.get_any_selection()
if (sel_text.length == 0) {
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
<script type="text/javascript" src="blocksde/blocks2.js"></script>
<script type="text/javascript" src="blocksde/jsdb_newObject.js"></script>
<script type="text/javascript" src="blocksde/js2b.js"></script>
<script type="text/javascript" src="de/de.js"></script>


<script type="text/javascript" src="ready.js"></script>
<link rel="stylesheet" href="styles.css" type="text/css"/>
Expand Down
Loading

0 comments on commit d2f0f06

Please sign in to comment.