Compare commits

...
2 Commits
Author SHA1 Message Date
HEL 9b59306604 feat: add vscode extension for basic syntax highlighting 2026-05-13 14:38:01 +02:00
HEL 3cf3011160 feat: add some syntax examples 2026-05-13 14:36:51 +02:00
7 changed files with 262 additions and 0 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
.vscode
@@ -0,0 +1,16 @@
# type: ignore
# ruff: disable[F821]
from __future__ import annotations
# A simple data-frame with different column of various simple types
# Columns can be named and/or typed
df: Frame[
verified: bool,
birth_year: int,
height: float,
name: str,
date: datetime,
float, # unnamed
unknown: _, # untyped
_ # unnamed and untyped
]
@@ -0,0 +1,24 @@
// Simple custom type derived from floats
type Latitude<float>
type Longitude<float>
// Complex custom type, containing two values accessible through properties
type GeoLocation<Latitude, Longitude> {
lat: Latitude
lon: Longitude
}
type LatitudeDiff<float>
type LongitudeDiff<float>
// Simple operation defined on our custom types
op <Latitude> - <Latitude> = <LatitudeDiff>
op <Longitude> - <Longitude> = <LongitudeDiff>
// Simple custom type with a constraint
type Age<int + (0 <= _ < 150)>
// Predefined custom constraints that can be referenced in other definitions
constraint Positive = _ >= 0
constraint StrictlyPositive = _ > 0
constraint Even = _ % 2 == 0
@@ -0,0 +1,34 @@
# type: ignore
# ruff: disable[F821]
from __future__ import annotations
# Prototype of custom type import to use valid Python syntax
import midas
midas.using("02_custom_types.midas")
# A data-frame using a custom type
df: Frame[
location: GeoLocation
]
# Properties of a type can be used on a column of that type
lat: Column[GeoLocation] = df["location"].lat
lon: Column[GeoLocation] = df["location"].lon
# Unregistered operations between types are not permitted
lat + lon # Invalid operation
# Registered operations are permitted
lat1: Latitude = lat[0]
lat2: Latitude = lat[1]
lat_diff: LatitudeDiff = lat2 - lat1 # Valid operation
# In addition to the type, a column can have one or more constraints, either defined inline or in a separate file
df2: Frame[
age: int + (_ >= 0),
height: float + (_ >= 0),
]
df2_bis: Frame[
age: int + Positive,
height: float + Positive,
]
+19
View File
@@ -0,0 +1,19 @@
{
"brackets": [
["{", "}"],
["[", "]"],
["<", ">"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}" },
{ "open": "[", "close": "]" },
{ "open": "(", "close": ")" },
{ "open": "<", "close": ">" }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["<", ">"]
]
}
+33
View File
@@ -0,0 +1,33 @@
{
"name": "midas",
"version": "0.1.0",
"engines": {
"vscode": "*"
},
"categories": ["Programming Languages"],
"contributes": {
"languages": [
{
"id": "midas",
"extensions": [
".mpy",
".midas"
],
"aliases": [
"Midas"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "midas",
"scopeName": "source.midas",
"path": "./syntaxes/midas.tmLanguage.json",
"embeddedLanguages": {
"meta.embedded.block.python": "python"
}
}
]
}
}
+135
View File
@@ -0,0 +1,135 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Midas",
"scopeName": "source.midas",
"patterns": [{ "include": "#statement" }],
"repository": {
"comment": {
"begin": "(//)",
"end": "($)",
"name": "comment.line",
"beginCaptures": {
"1": {
"name": "comment.line.double-dash"
}
}
},
"type-def": {
"begin": "\\b(type)\\s+([a-zA-Z_][a-zA-Z_\\d]*)",
"end": "$",
"beginCaptures": {
"1": {
"name": "keyword.control.type.midas"
},
"2": {
"name" : "variable.name"
}
},
"patterns": [
{ "include": "#type-base" },
{ "include": "#type-body" }
]
},
"type-base": {
"begin": "<",
"end": ">",
"beginCaptures": {
"0": {
"name": "punctuation.definition.base.begin.midas"
}
},
"endCaptures": {
"0": {
"name": "punctuation.definition.base.end.midas"
}
},
"patterns": [
{"include": "source.python"}
]
},
"type-body": {
"begin": "\\{",
"end": "\\}",
"beginCaptures": {
"0": {
"name": "punctuation.definition.type-body.begin.midas"
}
},
"endCaptures": {
"0": {
"name": "punctuation.definition.type-body.end.midas"
}
},
"patterns": [
{"include": "#type-prop"}
]
},
"type-prop": {
"match": "([a-zA-Z_][a-zA-Z_\\d]*)(:)\\s*([a-zA-Z_][a-zA-Z_\\d]*)",
"captures": {
"1": {
"name": "variable.name"
},
"2": {
"name": "punctuation.separator.annotation.midas"
},
"3": {
"name": "meta.type.name"
}
}
},
"op-def": {
"match": "\\b(op)\\s+<([a-zA-Z_][a-zA-Z_\\d]*)>\\s+(\\S+)\\s+<([a-zA-Z_][a-zA-Z_\\d]*)>\\s+(=)\\s+<([a-zA-Z_][a-zA-Z_\\d]*)>",
"captures": {
"1": {
"name": "keyword.control.op.midas"
},
"2": {
"name" : "variable.name"
},
"3": {
"name" : "keyword.operator"
},
"4": {
"name" : "variable.name"
},
"5": {
"name" : "keyword.operator.assignment"
},
"6": {
"name" : "variable.name"
}
},
"patterns": [
{ "include": "#type-base" },
{ "include": "#type-body" }
]
},
"constr-def": {
"begin": "(constraint)\\s+([a-zA-Z_][a-zA-Z_\\d]*)\\s*(=)",
"end": "$",
"beginCaptures": {
"1": {
"name": "keyword.control.constr.midas"
},
"2": {
"name": "variable.name"
},
"3": {
"name": "keyword.operator.assignment"
}
},
"patterns": [
{ "include": "source.python" }
]
},
"statement": {
"patterns": [
{ "include": "#comment" },
{ "include": "#type-def" },
{ "include": "#op-def" },
{ "include": "#constr-def" }
]
}
}
}