Adjust to string changes
This commit is contained in:
parent
f11b870600
commit
349f466283
@ -40,10 +40,11 @@ Num aConstant = 30 // <- `val` is optional
|
|||||||
Num var aVariable = 20 // <- `var` required
|
Num var aVariable = 20 // <- `var` required
|
||||||
|
|
||||||
// You can assign the result of many operations to a variable
|
// You can assign the result of many operations to a variable
|
||||||
val roi =
|
val roi = do {
|
||||||
val income = someIncomeCalculation()
|
val income = someIncomeCalculation()
|
||||||
val investment = 25000
|
val investment = 25000
|
||||||
income / investment // This will be the value of `roi`
|
income / investment // This will be the value of `roi`
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Basic datatypes
|
## Basic datatypes
|
||||||
@ -63,17 +64,18 @@ Str string = "John Doe"
|
|||||||
//
|
//
|
||||||
// Conditionals
|
// Conditionals
|
||||||
//
|
//
|
||||||
if name == "John Doe" do
|
if name == "John Doe" {
|
||||||
val message = "Hello John"
|
val message = "Hello John"
|
||||||
console.log(message)
|
console.log(message)
|
||||||
else if name == "Mark" do
|
} else if name == "Mark" {
|
||||||
console.log("Hi Mark!")
|
console.log("Hi Mark!")
|
||||||
else
|
} else {
|
||||||
console.log("Hello there")
|
console.log("Hello there")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// You can use conditionals as expressions
|
// You can use conditionals as expressions
|
||||||
val response = if risk < 0.2 do "Go ahead" else "Don't"
|
val response = if risk < 0.2 { "Go ahead" } else { "Don't" }
|
||||||
|
|
||||||
// There is no ternary conditional
|
// There is no ternary conditional
|
||||||
```
|
```
|
||||||
@ -121,16 +123,18 @@ var #(name, age, isMarried) = person
|
|||||||
//
|
//
|
||||||
// Loops
|
// Loops
|
||||||
//
|
//
|
||||||
for key in object do
|
for #(key, value) in object {
|
||||||
console.log("key: {key}, value: {object.[key]}")
|
console.log("key: {key}, value: {value}")
|
||||||
|
}
|
||||||
|
|
||||||
|
for value of array {
|
||||||
for value of array do
|
|
||||||
console.log("value: {value}")
|
console.log("value: {value}")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while condition do
|
while condition {
|
||||||
print("while")
|
print("while")
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
@ -147,15 +151,15 @@ add(10, 20)
|
|||||||
substring(input: "Hello, world!", start: 7, end: 12)
|
substring(input: "Hello, world!", start: 7, end: 12)
|
||||||
|
|
||||||
// Funtion declaration
|
// Funtion declaration
|
||||||
fun add(Num x, Num y) -> Num =
|
fun add(Num x, Num y) -> Num {
|
||||||
x + y
|
x + y
|
||||||
|
}
|
||||||
|
|
||||||
// Function with default value
|
// Function with default value
|
||||||
fun calculate(Num price, Num discount = 0.0) =
|
fun calculate(Num price, Num discount = 0.0) {
|
||||||
val total = price * (1.0 - discount)
|
val total = price * (1.0 - discount)
|
||||||
console.log("Your total is {total}$")
|
console.log("Your total is {total}$")
|
||||||
|
}
|
||||||
|
|
||||||
calculate(100, 0.25) // "Your total is 75$"
|
calculate(100, 0.25) // "Your total is 75$"
|
||||||
calculate(100) // "Your total is 100$"
|
calculate(100) // "Your total is 100$"
|
||||||
@ -361,15 +365,32 @@ match result with
|
|||||||
## JSX
|
## JSX
|
||||||
|
|
||||||
```misti
|
```misti
|
||||||
//
|
use Solid.{createSignal}
|
||||||
// JSX
|
use Search
|
||||||
//
|
use Person
|
||||||
|
use Registers
|
||||||
|
use NewRegister
|
||||||
|
|
||||||
|
pub fun 'Certs() {
|
||||||
|
val #(person, setPerson) = createSignal[Person?](None)
|
||||||
|
val #(lastUpdate, setLastUpdate) = createSignal(0)
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1
|
||||||
|
class="px-4 py-2 text-2xl font-bold"
|
||||||
|
>
|
||||||
|
Registrar certificado
|
||||||
|
</h1>
|
||||||
|
<Search setPerson={setPerson}/>
|
||||||
|
<Registers person={person()} lastUpdate={lastUpdate()} />
|
||||||
|
<NewRegister
|
||||||
|
personId={person()?.id ?? -1}
|
||||||
|
onSuccess={{setLastUpdate {$ + 1}}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
val element = <div>This is JSX</div>
|
|
||||||
val list = items.map fun (item, count) {<li key={count}>{item}</li>}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,42 +3,58 @@ name: ""
|
|||||||
has_index: true
|
has_index: true
|
||||||
children:
|
children:
|
||||||
- path: index
|
- path: index
|
||||||
|
name: Index
|
||||||
|
|
||||||
- path: basics
|
- path: basics
|
||||||
name: Basics
|
name: Basics
|
||||||
children:
|
children:
|
||||||
- path: variables-and-constants
|
- path: variables-and-constants
|
||||||
|
name: Variables and constants
|
||||||
- path: simple-datatypes
|
- path: simple-datatypes
|
||||||
|
name: Simple datatypes
|
||||||
- path: function-calls
|
- path: function-calls
|
||||||
|
name: Function calls
|
||||||
- path: operators
|
- path: operators
|
||||||
|
name: Operators
|
||||||
- path: tuples
|
- path: tuples
|
||||||
|
name: Tuples
|
||||||
- path: indentation-rules
|
- path: indentation-rules
|
||||||
|
name: Indentation rules
|
||||||
|
|
||||||
- path: flow-control
|
- path: flow-control
|
||||||
name: Flow control
|
name: Flow control
|
||||||
children:
|
children:
|
||||||
- path: conditionals
|
- path: conditionals
|
||||||
|
name: Conditionals
|
||||||
- path: arrays
|
- path: arrays
|
||||||
|
name: Arrays
|
||||||
- path: loops
|
- path: loops
|
||||||
|
name: Loops
|
||||||
|
|
||||||
- path: functions
|
- path: functions
|
||||||
name: Functions
|
name: Functions
|
||||||
children:
|
children:
|
||||||
- path: definition
|
- path: definition
|
||||||
|
name: Definition
|
||||||
- path: lambdas
|
- path: lambdas
|
||||||
|
name: Lambdas
|
||||||
- path: parameters
|
- path: parameters
|
||||||
|
name: Parameters
|
||||||
|
|
||||||
- path: objects
|
- path: objects
|
||||||
name: Objects
|
name: Objects
|
||||||
children:
|
children:
|
||||||
- path: definition
|
- path: definition
|
||||||
|
name: Definition
|
||||||
|
|
||||||
- path: classes
|
- path: classes
|
||||||
name: Classes
|
name: Classes
|
||||||
children:
|
children:
|
||||||
- path: definition
|
- path: definition
|
||||||
|
name: Definition
|
||||||
|
|
||||||
- path: modules
|
- path: modules
|
||||||
name: Modules
|
name: Modules
|
||||||
children:
|
children:
|
||||||
- path: import
|
- path: import
|
||||||
|
name: Import
|
||||||
|
@ -5,4 +5,6 @@ children:
|
|||||||
name: Prelude
|
name: Prelude
|
||||||
children:
|
children:
|
||||||
- path: String
|
- path: String
|
||||||
|
name: String
|
||||||
- path: Console
|
- path: Console
|
||||||
|
name: Console
|
||||||
|
@ -36,17 +36,7 @@ pub fn highlight(input: &String) -> String {
|
|||||||
TokenType::Identifier if token.value == "true" || token.value == "false" => {
|
TokenType::Identifier if token.value == "true" || token.value == "false" => {
|
||||||
replace!("keyword", token, offset, output)
|
replace!("keyword", token, offset, output)
|
||||||
}
|
}
|
||||||
TokenType::String => {
|
TokenType::String => replace!("string", token, offset, output),
|
||||||
let start_pos = token.position;
|
|
||||||
let end_pos = token.get_end_position();
|
|
||||||
|
|
||||||
let range = (start_pos + offset)..(end_pos + offset);
|
|
||||||
let html = format!("<span class=\"token string\">\"{}\"</span>", token.value);
|
|
||||||
|
|
||||||
offset += 34;
|
|
||||||
|
|
||||||
output.replace_range(range, html.as_str());
|
|
||||||
}
|
|
||||||
TokenType::Comment => replace!("comment", token, offset, output),
|
TokenType::Comment => replace!("comment", token, offset, output),
|
||||||
TokenType::VAL | TokenType::VAR => replace!("keyword", token, offset, output),
|
TokenType::VAL | TokenType::VAR => replace!("keyword", token, offset, output),
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -32,12 +32,14 @@ pub fn compile(file: &PathBuf, input_folder: &Path, output_folder: &Path, file_t
|
|||||||
output_file.set_extension("html");
|
output_file.set_extension("html");
|
||||||
|
|
||||||
//
|
//
|
||||||
// Compilation
|
// Read MD from disk
|
||||||
//
|
//
|
||||||
let file_content_bytes = fs::read(&input_file).unwrap();
|
let file_content_bytes = fs::read(&input_file).unwrap();
|
||||||
let markdown_text = String::from_utf8(file_content_bytes).unwrap();
|
let markdown_text = String::from_utf8(file_content_bytes).unwrap();
|
||||||
|
|
||||||
// let html_text = to_html(markdown_text.as_str());
|
//
|
||||||
|
// Compile MD
|
||||||
|
//
|
||||||
let md_ast = markdown::to_mdast(&markdown_text, &markdown::ParseOptions::gfm()).unwrap();
|
let md_ast = markdown::to_mdast(&markdown_text, &markdown::ParseOptions::gfm()).unwrap();
|
||||||
let html_text = md_ast.to_html();
|
let html_text = md_ast.to_html();
|
||||||
let sidebar_html = md_ast.generate_sidebar();
|
let sidebar_html = md_ast.generate_sidebar();
|
||||||
|
@ -14,6 +14,8 @@ pub enum Node<'a> {
|
|||||||
pub struct File<'a> {
|
pub struct File<'a> {
|
||||||
/// Name of the file
|
/// Name of the file
|
||||||
path: &'a String,
|
path: &'a String,
|
||||||
|
/// Display name of the file
|
||||||
|
name: &'a String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Folder<'a> {
|
pub struct Folder<'a> {
|
||||||
@ -42,18 +44,17 @@ pub fn parse_yaml(values: &Yaml) -> Node {
|
|||||||
let Yaml::String(path) = table.get(y_str!("path")).expect("YAML: Node MUST have a `path` key")
|
let Yaml::String(path) = table.get(y_str!("path")).expect("YAML: Node MUST have a `path` key")
|
||||||
else { panic!("YAML: `path` MUST be a String") };
|
else { panic!("YAML: `path` MUST be a String") };
|
||||||
|
|
||||||
|
let Yaml::String(name) = table.get(y_str!("name")).expect("YAML: Node MUST have a `name` key")
|
||||||
|
else { panic!("YAML: `name` MUST be a String") };
|
||||||
|
|
||||||
let input_data = (
|
let input_data = (
|
||||||
table.get(y_str!("name")),
|
|
||||||
table.get(y_str!("has_index")),
|
table.get(y_str!("has_index")),
|
||||||
table.get(y_str!("children")),
|
table.get(y_str!("children")),
|
||||||
);
|
);
|
||||||
|
|
||||||
match input_data {
|
match input_data {
|
||||||
(None, None, None) => Node::File(File { path }),
|
(None, None) => Node::File(File { path, name }),
|
||||||
(Some(name), has_index, Some(children)) => {
|
(has_index, Some(children)) => {
|
||||||
let Yaml::String(name) = name
|
|
||||||
else { panic!("YAML: `name` MUST be a String") };
|
|
||||||
|
|
||||||
let has_index = match has_index {
|
let has_index = match has_index {
|
||||||
Some(Yaml::Boolean(v)) => *v,
|
Some(Yaml::Boolean(v)) => *v,
|
||||||
Some(_) => panic!("YAML: if key `has_index` exists, it MUST be a Boolean"),
|
Some(_) => panic!("YAML: if key `has_index` exists, it MUST be a Boolean"),
|
||||||
@ -100,7 +101,7 @@ pub fn generate_pages_html(file_tree: &Node, current_path: &Path) -> String {
|
|||||||
</li>",
|
</li>",
|
||||||
current_path.to_str().unwrap(),
|
current_path.to_str().unwrap(),
|
||||||
file.path,
|
file.path,
|
||||||
file.path
|
file.name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"watch": "concurrently -k \"tailwindcss -i ./tailwind/input.css -o ./tailwind/output.css --watch\" \"live-server . --port=3333\"",
|
"watch": "concurrently -k \"tailwindcss -i ./tailwind/input.css -o ./tailwind/output.css --watch\" \"live-server . --port=3333\"",
|
||||||
"server": "live-server . --port=3333",
|
"start": "live-server . --port=3333",
|
||||||
"styles": "tailwindcss -i ./tailwind/input.css -o ./tailwind/output.css --watch"
|
"styles": "tailwindcss -i ./tailwind/input.css -o ./tailwind/output.css --watch"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
Loading…
Reference in New Issue
Block a user