From f651d97279a7c3f6945ccd9b2695743d89096d6f Mon Sep 17 00:00:00 2001 From: Ben Saupp Date: Tue, 18 Jul 2023 12:00:48 -0400 Subject: [PATCH] attempting errormessages --- public/features.html | 8 +- src/{milestone1.js => ast.js} | 10 +- src/{milestone2.js => lexer-parser.js} | 107 ++++++++--------- src/main.js | 20 ++-- src/share.js | 2 +- src/toolbox.js | 154 +++++++++++++------------ src/tree2blocks.js | 2 +- 7 files changed, 150 insertions(+), 153 deletions(-) rename src/{milestone1.js => ast.js} (99%) rename src/{milestone2.js => lexer-parser.js} (93%) diff --git a/public/features.html b/public/features.html index b1728df..5f1a8b1 100644 --- a/public/features.html +++ b/public/features.html @@ -42,7 +42,7 @@ .completed { color: white; - background-color: green; + background-color: purple; border-radius: 5px; padding: 3px 6px; } @@ -56,7 +56,7 @@ .unlikely-change { color: white; - background-color: purple; + background-color: green; border-radius: 5px; padding: 3px 6px; } @@ -107,13 +107,13 @@

Completed Features

The following are features that are considered to be working:
- Green - Stable but unfinished + Purple - Stable but unfinished
Blue - Finished but will be upgraded soon
- Purple - Finished and unlikely to change + Green - Finished and unlikely to change
diff --git a/src/milestone1.js b/src/ast.js similarity index 99% rename from src/milestone1.js rename to src/ast.js index 558d292..37eb93b 100644 --- a/src/milestone1.js +++ b/src/ast.js @@ -4,15 +4,13 @@ // import { highlightError, indextoAceRange } from "./milestone2"; // import { textEditor } from "./milestone2"; // import { block } from "blockly/core/tooltip"; -import { sendRuntimeError } from "./milestone2"; -import { printBuffer } from "./milestone2"; -import { addToPrintBuffer } from "./milestone2"; +import { sendRuntimeError } from "./lexer-parser"; +import { printBuffer } from "./lexer-parser"; +import { addToPrintBuffer } from "./lexer-parser"; var scopes = {}; -// export var printBuffer = ""; -// export var errorOutput = ""; -// export var blockErrorsBuffer = {}; + diff --git a/src/milestone2.js b/src/lexer-parser.js similarity index 93% rename from src/milestone2.js rename to src/lexer-parser.js index 31d48d5..d1d7ae4 100644 --- a/src/milestone2.js +++ b/src/lexer-parser.js @@ -1,9 +1,5 @@ import ace from 'ace-builds'; -// import { createExecutable } from './milestone1'; -// import { printBuffer } from './milestone1'; -// import { clearOutput } from './milestone1'; -// import { variables } from 'blockly/blocks'; -// import { textError } from './milestone1'; + export const textEditor = ace.edit("aceCode", {fontSize: 16}); @@ -28,11 +24,54 @@ export function clearOutput() { } -export function textError(type, error, startIndex, endIndex){ - var ranges = indextoAceRange(startIndex, endIndex); - errorOutput += `${type} error occured on line line ${ranges[0]}: ${error}
`; - // highlightError(ranges, error); -} +// export function textError(type, error, startIndex, endIndex){ + +// if (endIndex ?? 0 < startIndex){ +// endIndex = textEditor?.getValue().length - 1; +// } +// var ranges = indextoAceRange(startIndex, endIndex); +// errorOutput += `${type} error occured on line line ${ranges[0]}: ${error}
`; +// var range = new AceRange(rangeArray[0], rangeArray[1], rangeArray[2], rangeArray[3]); +// highlightError(range); +// } + + +// export function highlightError(range) { +// const marker = document.createElement('div'); +// marker.className = 'ace_error'; +// marker.style.position = 'absolute'; +// marker.style.borderBottom = '1px solid red'; +// marker.style.pointerEvents = 'none'; +// marker.style.width = '100%'; +// marker.style.marginBottom = '-1px'; +// marker.style.zIndex = '1'; + +// const session = textEditor?.getSession(); +// const line = range.start.row; +// const rowHeight = session.getRowLength(line) * session.getScreenLineHeight(line); +// marker.style.height = rowHeight + 'px'; + +// const markerLayer = session.getMarkerLayer('ace_error'); +// markerLayer.drawSingleLineMarker(marker, range.start, range.end, session); + +// textEditor?.renderer.scrollCursorIntoView({ row: line, column: 0 }, 0.5); +// } + +// export function textError(type, error, startIndex, endIndex) { +// const editorValue = textEditor?.getValue(); +// if (!editorValue || !startIndex || !endIndex) { +// console.error('Invalid parameters'); +// return; +// } + +// const range = new AceRange( +// startIndex.row || 0, +// startIndex.column || 0, +// endIndex.row || editorValue.length - 1, +// endIndex.column || editorValue.length - 1 +// ); +// highlightError(range); +// } @@ -46,62 +85,18 @@ export function addBlockErrors(workspace){ } export function sendRuntimeError(errormessage, blockjson){ - if (typeof(blockjson.startIndex !== 'undefined') && typeof(blockjson.endIndex !== 'undefined')){ - textError('runtime', errormessage, blockjson.startIndex, blockjson.endIndex); - } + textError('runtime', errormessage, blockjson.startIndex, blockjson.endIndex); if (typeof(blockjson.blockid !== 'undefined')){ blockErrorsBuffer[blockjson.blockid] = errormessage + '
'; } -} - - - -// needs tested -export function highlightError(rangeArray, errorMessage) { - // Get the session from the editor - var session = textEditor?.getSession(); - - // Convert the range array to an Ace Range object - var range = new AceRange(rangeArray[0], rangeArray[1], rangeArray[2], rangeArray[3]); - // Create a marker for the error range - var marker = session.addMarker(range, "error-marker", "text"); - - // Create a div element for the error message tooltip - var tooltip = document.createElement('div'); - tooltip.className = 'error-tooltip'; - tooltip.textContent = errorMessage; - - // Calculate the line height based on the editor's font size - var lineHeight = parseInt(textEditor?.renderer?.lineHeight, 10); +} - // Create the marker element and add the tooltip - var markerElement = document.createElement('div'); - markerElement.className = 'ace_error-marker'; - markerElement.style.top = range.start.row * lineHeight + 'px'; - markerElement.style.height = lineHeight + 'px'; - markerElement.appendChild(tooltip); - try { - // Find the marker layer's parent container - var markerLayer = session.getMarkerLayer("error-marker"); - markerLayer?.element.appendChild(markerElement); - // Add a mouse hover effect to display the error message - markerElement.addEventListener('mouseenter', function() { - tooltip.style.display = 'block'; - }); - markerElement.addEventListener('mouseleave', function() { - tooltip.style.display = 'none'; - }); - } - catch(error) { - console.log('error adding the hover effect'); - } -} diff --git a/src/main.js b/src/main.js index 052666c..5dc8e04 100644 --- a/src/main.js +++ b/src/main.js @@ -3,21 +3,21 @@ import Blockly from 'blockly'; import {praxlyDefaultTheme } from "./theme" import { PraxlyDark } from './theme'; import {toolbox} from './toolbox'; -import { textEditor } from './milestone2'; +import { textEditor } from './lexer-parser'; import { tree2text } from './tree2text'; import {definePraxlyBlocks} from './newBlocks'; import { makeGenerator } from './generators'; import { blocks2tree } from './generators'; -import { createExecutable } from './milestone1'; -import { printBuffer } from './milestone2'; -import { clearOutput } from './milestone2'; +import { createExecutable } from './ast'; +import { printBuffer } from './lexer-parser'; +import { clearOutput } from './lexer-parser'; import ace from 'ace-builds'; import "ace-builds/src-min-noconflict/theme-twilight"; import "ace-builds/src-min-noconflict/theme-katzenmilch"; import { tree2blocks } from './tree2blocks'; -import { errorOutput } from './milestone2'; -import { text2tree } from './milestone2'; +import { errorOutput } from './lexer-parser'; +import { text2tree } from './lexer-parser'; import { generateUrl, loadFromUrl } from './share'; import { colour } from 'blockly/blocks'; @@ -37,7 +37,7 @@ const blockUpdatesButton = document.getElementById('blockUpdates'); let darkMode = false; let live = true; -runButton.addEventListener('click', () => { +runButton.addEventListener('mouseup', () => { clearOutput(); // mainTree = blocks2tree(workspace, praxlyGenerator); if (mainTree === null){ @@ -178,21 +178,23 @@ darkModeButton.addEventListener('click', ()=> { ); blockUpdatesButton.innerText = 'block updates: live '; -workspace.addChangeListener( turnBlocksToCode); +workspace.addChangeListener( turnBlocksToCode); textEditor.addEventListener("input", turnCodeToBLocks); blockUpdatesButton.addEventListener('click', () => { if (!live){ + runButton.removeEventListener('mousedown', turnCodeToBLocks); blockUpdatesButton.innerText = 'block updates: live '; workspace.addChangeListener( turnBlocksToCode); textEditor.addEventListener("input", turnCodeToBLocks); live = true; } else { + blockUpdatesButton.innerText = 'block updates: on run (not implimented yet)'; workspace.removeChangeListener(turnBlocksToCode); - blockUpdatesButton.innerText = 'block updates: on save (not implimented yet)'; textEditor.removeEventListener("input", turnCodeToBLocks); + runButton.addEventListener('mousedown', turnCodeToBLocks); live = false; } }); diff --git a/src/share.js b/src/share.js index a0a3f63..9adfc0b 100644 --- a/src/share.js +++ b/src/share.js @@ -1,5 +1,5 @@ -import { textEditor } from "./milestone2"; +import { textEditor } from "./lexer-parser"; export function generateUrl() { // yank the text in ace diff --git a/src/toolbox.js b/src/toolbox.js index 0a8668c..b96ff8d 100644 --- a/src/toolbox.js +++ b/src/toolbox.js @@ -398,6 +398,82 @@ export const toolbox = { } ] }, + { + "kind": "category", + "name": "expressions", + "categorystyle": "expression_blocks", + "contents": [ + { + 'kind': 'block', + 'type': 'praxly_literal_block' + }, + // { + // 'kind': 'block', + // 'type': 'praxly_String_block' + // }, + { + 'kind': 'block', + 'type': 'praxly_arithmetic_block', + 'inputs': { + 'A_OPERAND' : { + 'shadow': { + 'type' :'praxly_literal_block', + 'fields' : { + 'LITERAL' : 1, + } + }, + }, + 'B_OPERAND' : { + 'shadow': { + 'type' :'praxly_literal_block', + 'fields' : { + 'LITERAL' : 1, + } + }, + } + + + } + + }, + + { + 'kind': 'block', + 'type': 'praxly_null_block' + }, + { + 'kind': 'block', + 'type': 'praxly_true_block' + }, + { + 'kind': 'block', + 'type': 'praxly_false_block' + } + ] + }, + { + "kind": "category", + "name": "variables", + "categorystyle": "variable_blocks", + "contents": [ + + { + 'kind': 'block', + 'type': 'praxly_assignment_block' + }, + { + 'kind': 'block', + 'type': 'praxly_reassignment_block' + }, + { + 'kind': 'block', + 'type': 'praxly_variable_block' + }, + + + + ] + }, { "kind": "category", "name": "logic", @@ -566,59 +642,7 @@ export const toolbox = { } ] }, - { - "kind": "category", - "name": "expressions", - "categorystyle": "expression_blocks", - "contents": [ - { - 'kind': 'block', - 'type': 'praxly_literal_block' - }, - // { - // 'kind': 'block', - // 'type': 'praxly_String_block' - // }, - { - 'kind': 'block', - 'type': 'praxly_arithmetic_block', - 'inputs': { - 'A_OPERAND' : { - 'shadow': { - 'type' :'praxly_literal_block', - 'fields' : { - 'LITERAL' : 1, - } - }, - }, - 'B_OPERAND' : { - 'shadow': { - 'type' :'praxly_literal_block', - 'fields' : { - 'LITERAL' : 1, - } - }, - } - - - } - - }, - - { - 'kind': 'block', - 'type': 'praxly_null_block' - }, - { - 'kind': 'block', - 'type': 'praxly_true_block' - }, - { - 'kind': 'block', - 'type': 'praxly_false_block' - } - ] - }, + // { // "kind": "category", @@ -657,29 +681,7 @@ export const toolbox = { ] }, - { - "kind": "category", - "name": "variables", - "categorystyle": "variable_blocks", - "contents": [ - - { - 'kind': 'block', - 'type': 'praxly_assignment_block' - }, - { - 'kind': 'block', - 'type': 'praxly_reassignment_block' - }, - { - 'kind': 'block', - 'type': 'praxly_variable_block' - }, - - - - ] - }, + { "kind": "category", "name": "procedures", diff --git a/src/tree2blocks.js b/src/tree2blocks.js index adf8066..97c3dd3 100644 --- a/src/tree2blocks.js +++ b/src/tree2blocks.js @@ -1,4 +1,4 @@ -import { textEditor } from "./milestone2"; +import { textEditor } from "./lexer-parser";