-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvements to xmlgen recursive example, walk function for recursibe…
… block handling , smaller improvements
- Loading branch information
Showing
9 changed files
with
187 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
private { | ||
spaces: fn1 { .produce "" { + " " } } | ||
myprn: fn { t d } { prn spaces d , prn t } | ||
is-not: fn { a b } { a = b |not } | ||
nl: does { print "" } | ||
|
||
proc: fn\par { val blk depth current } current-ctx { | ||
sleep 10 | ||
walk blk { :bk | ||
.peek :tok .type? .switch { | ||
xword { | ||
nl , | ||
myprn tok depth , | ||
proc val next bk inc depth tok | ||
} | ||
exword { | ||
print tok , | ||
if not tok .to-word = to-word current { print "<!-- Tag mismatch -->" } , | ||
return next bk | ||
} | ||
block { | ||
with val tok :vv \type? .is-not 'function \if { prn vv } , | ||
next bk | ||
} | ||
string { | ||
myprn join { "<!-- " tok " -->" } depth , | ||
next bk | ||
} | ||
} | ||
} | ||
} | ||
fn\par { val blk } current-ctx { proc val blk 0 'no } | ||
|
||
} :xmlgen | ||
|
||
xml-template: { | ||
<header> | ||
<author> ( name ) </author> | ||
</header> | ||
<data> | ||
<fullname> ( .fullname ) </fullname> | ||
<name id="first"> ( -> "name" ) </name> | ||
"Surname next" | ||
<surname> ( -> "surname" ) </surname> | ||
</data> | ||
} | ||
|
||
fullname: fn1 { -> "name" :n , -> "surname" :s , n + " " + s } | ||
input "Enter author's name: " :name | ||
xmlgen dict { "name" "Jim" "surname" "Metelko" } xml-template | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
; match: fn { val blk } { .type? .switch blk } ; TODO -- match in switch confuses return function. Look into it soon. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Drag and Drop File with Movable Div</title> | ||
<link rel="stylesheet" type="text/css" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="drop-area"> | ||
<p>Drag and drop a text file here</p> | ||
</div> | ||
<div id="file-content" class="draggable"> | ||
<p>File content will appear here</p> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
document.addEventListener('DOMContentLoaded', (event) => { | ||
let dropArea = document.getElementById('drop-area'); | ||
let fileContent = document.getElementById('file-content'); | ||
|
||
// Drag and drop | ||
dropArea.addEventListener('dragover', (e) => { | ||
e.preventDefault(); | ||
}); | ||
|
||
dropArea.addEventListener('drop', (e) => { | ||
e.preventDefault(); | ||
let file = e.dataTransfer.files[0]; | ||
let reader = new FileReader(); | ||
reader.onload = function(e) { | ||
fileContent.style.display = 'block'; | ||
fileContent.innerText = e.target.result; | ||
}; | ||
reader.readAsText(file); | ||
}); | ||
|
||
// Draggable div | ||
fileContent.onmousedown = function(event) { | ||
let shiftX = event.clientX - fileContent.getBoundingClientRect().left; | ||
let shiftY = event.clientY - fileContent.getBoundingClientRect().top; | ||
|
||
function moveAt(pageX, pageY) { | ||
fileContent.style.left = pageX - shiftX + 'px'; | ||
fileContent.style.top = pageY - shiftY + 'px'; | ||
} | ||
|
||
function onMouseMove(event) { | ||
moveAt(event.pageX, event.pageY); | ||
} | ||
|
||
document.addEventListener('mousemove', onMouseMove); | ||
|
||
fileContent.onmouseup = function() { | ||
document.removeEventListener('mousemove', onMouseMove); | ||
fileContent.onmouseup = null; | ||
}; | ||
|
||
}; | ||
|
||
fileContent.ondragstart = function() { | ||
return false; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#drop-area { | ||
width: 300px; | ||
height: 100px; | ||
border: 2px dashed #ccc; | ||
text-align: center; | ||
padding: 20px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.draggable { | ||
width: 300px; | ||
padding: 10px; | ||
border: 1px solid black; | ||
background-color: #f3f3f3; | ||
cursor: move; | ||
position: absolute; | ||
display: none; | ||
} |