Skip to content

More Syntax Changes #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a52f8d2
Initial commit for implementing code blocks.
gdotdesign Jul 8, 2021
ffe62f5
Implement initial type checker for block.
gdotdesign Jul 12, 2021
7ebae89
Extract block related functions to their own files.
gdotdesign Oct 5, 2021
8352274
Remove where block language feature.
gdotdesign Oct 5, 2021
f18b898
Rmove with language feature.
gdotdesign Oct 5, 2021
887acaf
Use blocks in linline function as well.
gdotdesign Oct 5, 2021
6da15fd
Convert more blocks to new code blocks.
gdotdesign Oct 7, 2021
c2ea3be
Convert more blocks to new code blocks.
gdotdesign Oct 7, 2021
9c61be0
Update the last batch of code blocks to the new format.
gdotdesign Oct 7, 2021
944bc1a
Allow using block as an expression.
gdotdesign Oct 8, 2021
37b87c7
Remove references to `try` feature.
gdotdesign Oct 8, 2021
2dbe3da
Remove try language feature.
gdotdesign Oct 8, 2021
497cf8f
Move formatting of brackets of the code block into it's formatter.
gdotdesign Oct 8, 2021
7f1d9e7
Replace promises with only one parameter in core.
gdotdesign Oct 8, 2021
99b5c08
Make core tests pass.
gdotdesign Oct 9, 2021
5b2a5d2
Remove parallel language feature.
gdotdesign Oct 9, 2021
7ab8b99
Remove sequence, catch, finally and then laguage constructs.
gdotdesign Oct 9, 2021
9c369db
Updates for handling blocks.
gdotdesign Oct 11, 2021
13be2de
Fix tests.
gdotdesign Oct 13, 2021
de1f785
Add back previously removed syntax errors.
gdotdesign Oct 14, 2021
9d42772
Remove safe operator.
gdotdesign Oct 14, 2021
2637c42
Remove not used method.
gdotdesign Oct 14, 2021
bfc3797
Updates for the master branch.
gdotdesign Nov 26, 2021
26187bc
Format files.
gdotdesign Nov 26, 2021
0b20457
Switch await to be the right side of the equality and some cleanup.
gdotdesign Nov 26, 2021
7de7e90
Remove partial application feature.
gdotdesign Nov 26, 2021
8700111
Implement default arguments for functions.
gdotdesign Dec 14, 2021
a416fc3
Implement short enum ids.
gdotdesign Dec 15, 2021
0941cfd
Allow calling module functions in an OO fashion.
gdotdesign Dec 16, 2021
d245afc
Convert Array tests to use new function call syntax.
gdotdesign Dec 16, 2021
be8d0b8
Convert more tests to use the new function call syntax.
gdotdesign Dec 16, 2021
8af448d
Use arrow function for the inline function as well if it's async.
gdotdesign Dec 17, 2021
3e1ad53
Make sure calls to records are compiled correctly.
gdotdesign Dec 17, 2021
db0f16a
Allow returning a `Promise` in blocks without wrapping it again.
gdotdesign Dec 17, 2021
14891c7
Implement here document.
gdotdesign Dec 20, 2021
f2ad45c
Added markdown support to here documents.
gdotdesign Dec 24, 2021
e383687
Escape backticks in virtual dom renderer.
gdotdesign Dec 27, 2021
2035aad
Minor fixes for the vdom renderer.
gdotdesign Dec 29, 2021
90ea344
Unify handling of uppercase entities.
gdotdesign Dec 29, 2021
bf17ce3
Correctly parse constants in enum id.
gdotdesign Dec 31, 2021
4fe290b
Make sure or operation works properly on `Result`
gdotdesign Jan 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 2 additions & 4 deletions core/source/Array.mint
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ module Array {
Array.firstWithDefault("a", ["b", "x"]) == "b"
*/
fun firstWithDefault (item : a, array : Array(a)) : a {
first(array)
|> Maybe.withDefault(item)
array.first().withDefault(item)
}

/*
Expand Down Expand Up @@ -56,8 +55,7 @@ module Array {
Array.lastWithDefault("a", ["x", "b"]) == "b"
*/
fun lastWithDefault (item : a, array : Array(a)) : a {
last(array)
|> Maybe.withDefault(item)
array.last().withDefault(item)
}

/*
Expand Down
2 changes: 1 addition & 1 deletion core/source/Clipboard.mint
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* This module has functions for manipulating the clipboard. */
module Clipboard {
/* Sets the clipboards content to the given value. */
fun set (value : String) : Promise(Never, String) {
fun set (value : String) : Promise(String) {
`
(() => {
// Create a textarea element
Expand Down
72 changes: 32 additions & 40 deletions core/source/Dom.mint
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,15 @@ module Dom {
|> Dom.focus
|> Dom.getElementById()
*/
fun focus (maybeElement : Maybe(Dom.Element)) : Promise(Never, Void) {
fun focus (maybeElement : Maybe(Dom.Element)) : Promise(Void) {
case (maybeElement) {
Maybe::Just(element) =>
sequence {
{
focusWhenVisible(element)

Promise.never()
} catch {
Promise.never()
Promise.resolve(void)
}

Maybe::Nothing => Promise.never()
Maybe::Nothing => Promise.resolve(void)
}
}

Expand All @@ -174,14 +171,14 @@ module Dom {
|> Dom.getElementById
|> Dom.focusWhenVisible()
*/
fun focusWhenVisible (element : Dom.Element) : Promise(String, Void) {
fun focusWhenVisible (element : Dom.Element) : Promise(Result(String, Void)) {
`
new Promise((resolve, reject) => {
new Promise((resolve) => {
let counter = 0

let focus = () => {
if (counter > 15) {
reject('Could not focus the element in 150ms. Is it visible?')
resolve(#{Result::Err("Could not focus the element in 150ms. Is it visible?")})
}

#{element}.focus()
Expand All @@ -190,7 +187,7 @@ module Dom {
counter++
setTimeout(focus, 10)
} else {
resolve(#{void})
resolve(#{Result::Ok(void)})
}
}

Expand All @@ -212,13 +209,12 @@ module Dom {
Returns if the given base element contains the given element (as a maybe).

case (Dom.getElementBySelector("body")) {
Maybe::Just(body) =>
try {
div =
Dom.getElementBySelector("div")
Maybe::Just(body) => {
div =
Dom.getElementBySelector("div")

Dom.contains(div, body) == true
}
Dom.contains(div, body) == true
}

=> false
}
Expand All @@ -228,7 +224,7 @@ module Dom {
base : Dom.Element
) : Bool {
maybeElement
|> Maybe.map(Dom.contains(base))
|> Maybe.map((item : Dom.Element) { Dom.contains(item, base) })
|> Maybe.withDefault(false)
}

Expand All @@ -255,14 +251,12 @@ module Dom {
/*
If the attribute is present, it will return its value on the given element.

try {
outcome =
Dom.getElementById("my-div")
outcome =
Dom.getElementById("my-div")

case (outcome) {
Maybe::Just(element) => Dom.getAttribute("id", element) == "my-div"
Maybe::Nothing => false
}
case (outcome) {
Maybe::Just(element) => Dom.getAttribute("id", element) == "my-div"
Maybe::Nothing => false
}
*/
fun getAttribute (name : String, element : Dom.Element) : Maybe(String) {
Expand Down Expand Up @@ -382,7 +376,7 @@ module Dom {

Dom.blurActiveElement()
*/
fun blurActiveElement : Promise(Never, Void) {
fun blurActiveElement : Promise(Void) {
`document.activeElement && document.activeElement.blur()`
}

Expand Down Expand Up @@ -452,7 +446,7 @@ module Dom {
}

/* Focuses the first focusable descendant of the given element. */
fun focusFirst (element : Dom.Element) : Promise(Never, Void) {
fun focusFirst (element : Dom.Element) : Promise(Void) {
element
|> getFocusableElements
|> Array.first
Expand All @@ -464,7 +458,7 @@ module Dom {

Dom.smoothScrollTo(element, 10, 10)
*/
fun smoothScrollTo (element : Dom.Element, left : Number, top : Number) : Promise(Never, Void) {
fun smoothScrollTo (element : Dom.Element, left : Number, top : Number) : Promise(Void) {
`#{element}.scrollTo({
behavior: 'smooth',
left: #{left},
Expand All @@ -477,7 +471,7 @@ module Dom {

Dom.scrollTo(element, 10, 10)
*/
fun scrollTo (element : Dom.Element, left : Number, top : Number) : Promise(Never, Void) {
fun scrollTo (element : Dom.Element, left : Number, top : Number) : Promise(Void) {
`#{element}.scrollTo({
left: #{left},
top: #{top}
Expand Down Expand Up @@ -552,20 +546,18 @@ module Dom {
|> getElementsBySelector(selector)
|> Array.map(
(item : Dom.Element) : Tuple(String, String, String) {
try {
tag =
item
|> getTagName()
|> String.toLowerCase()
tag =
item
|> getTagName()
|> String.toLowerCase()

text =
getTextContent(item)
text =
getTextContent(item)

hash =
String.parameterize(text)
hash =
String.parameterize(text)

{tag, text, hash}
}
{tag, text, hash}
})
}
}
66 changes: 32 additions & 34 deletions core/source/File.mint
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ module File {
* The mime type can be restricted to the given one.
* It might not resolve if the user cancels the dialog.

sequence {
{
files =
File.selectMultiple("application/json")
await File.selectMultiple("application/json")

Debug.log(files)
}
*/
fun selectMultiple (accept : String) : Promise(Never, Array(File)) {
fun selectMultiple (accept : String) : Promise(Array(File)) {
`
(() => {
let input = document.createElement('input')
Expand All @@ -69,7 +69,7 @@ module File {

document.body.appendChild(input)

return new Promise((resolve, reject) => {
return new Promise((resolve) => {
input.addEventListener('change', () => {
resolve(Array.from(input.files))
})
Expand All @@ -86,14 +86,14 @@ module File {
* The mime type can be restricted to the given one.
* It might not resolve if the user cancels the dialog.

sequence {
{
file =
File.select("application/json")
await File.select("application/json")

Debug.log(file)
}
*/
fun select (accept : String) : Promise(Never, File) {
fun select (accept : String) : Promise(File) {
`
(() => {
let input = document.createElement('input')
Expand All @@ -109,7 +109,7 @@ module File {

document.body.appendChild(input)

return new Promise((resolve, reject) => {
return new Promise((resolve) => {
input.addEventListener('change', () => {
resolve(input.files[0])
})
Expand All @@ -123,21 +123,21 @@ module File {
/*
Reads the contents of the given file as a Data URL.

sequence {
{
file =
File.fromString("Some content...", "test.txt", "text/plain")
await File.fromString("Some content...", "test.txt", "text/plain")

url =
File.readAsDataURL(file)

url == "data:text/plain;...."
}
*/
fun readAsDataURL (file : File) : Promise(Never, String) {
fun readAsDataURL (file : File) : Promise(String) {
`
(() => {
let reader = new FileReader();
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
reader.addEventListener('load', (event) => {
resolve(reader.result)
})
Expand All @@ -150,21 +150,21 @@ module File {
/*
Reads the contents of the given file as a String.

sequence {
{
file =
File.create("Some content...", "test.txt", "text/plain")
await File.create("Some content...", "test.txt", "text/plain")

url =
File.readAsString(file)

url == "Some content..."
}
*/
fun readAsString (file : File) : Promise(Never, String) {
fun readAsString (file : File) : Promise(String) {
`
(() => {
let reader = new FileReader();
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
reader.addEventListener('load', (event) => {
resolve(reader.result)
})
Expand All @@ -177,28 +177,26 @@ module File {
/*
Prompts a save dialog for the given file.

sequence {
{
file =
File.select(*)
await File.select(*)

File.download(file)
}
*/
fun download (file : File) : Promise(Never, Void) {
sequence {
url =
Url.createObjectUrlFromFile(file)

`
(() => {
const anchor = document.createElement('a');
anchor.download = #{file}.name;
anchor.href = #{url};
anchor.click();
})()
`

Url.revokeObjectUrl(url)
}
fun download (file : File) : Void {
url =
Url.createObjectUrlFromFile(file)

`
(() => {
const anchor = document.createElement('a');
anchor.download = #{file}.name;
anchor.href = #{url};
anchor.click();
})()
`

Url.revokeObjectUrl(url)
}
}
12 changes: 4 additions & 8 deletions core/source/Html.Event.mint
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ module Html.Event {
/*
Stops the propagation of the given event.

try {
Html.Event.stopPropagation(event)
doSomethingElse()
}
Html.Event.stopPropagation(event)
doSomethingElse()
*/
fun stopPropagation (event : Html.Event) : Void {
`#{event.event}.stopPropagation()`
Expand All @@ -215,10 +213,8 @@ module Html.Event {
/*
Prevents the default action of the event from happening.

try {
Html.Event.preventDefault(event)
doSomethingElse()
}
Html.Event.preventDefault(event)
doSomethingElse()
*/
fun preventDefault (event : Html.Event) : Void {
`#{event.event}.preventDefault()`
Expand Down
Loading