Adjust to string changes

master
Araozu 2023-05-18 22:26:05 -05:00
parent f11b870600
commit 349f466283
7 changed files with 74 additions and 42 deletions

View File

@ -40,10 +40,11 @@ Num aConstant = 30 // <- `val` is optional
Num var aVariable = 20 // <- `var` required
// You can assign the result of many operations to a variable
val roi =
val roi = do {
val income = someIncomeCalculation()
val investment = 25000
income / investment // This will be the value of `roi`
}
```
## Basic datatypes
@ -63,17 +64,18 @@ Str string = "John Doe"
//
// Conditionals
//
if name == "John Doe" do
if name == "John Doe" {
val message = "Hello John"
console.log(message)
else if name == "Mark" do
} else if name == "Mark" {
console.log("Hi Mark!")
else
} else {
console.log("Hello there")
}
// 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
```
@ -121,16 +123,18 @@ var #(name, age, isMarried) = person
//
// Loops
//
for key in object do
console.log("key: {key}, value: {object.[key]}")
for #(key, value) in object {
console.log("key: {key}, value: {value}")
}
for value of array do
for value of array {
console.log("value: {value}")
}
while condition do
while condition {
print("while")
}
```
## Functions
@ -147,15 +151,15 @@ add(10, 20)
substring(input: "Hello, world!", start: 7, end: 12)
// Funtion declaration
fun add(Num x, Num y) -> Num =
fun add(Num x, Num y) -> Num {
x + y
}
// 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)
console.log("Your total is {total}$")
}
calculate(100, 0.25) // "Your total is 75$"
calculate(100) // "Your total is 100$"
@ -361,15 +365,32 @@ match result with
## JSX
```misti
//
// JSX
//
use Solid.{createSignal}
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 = &lt;div>This is JSX&lt;/div>
val list = items.map fun (item, count) {&lt;li key={count}>{item}&lt;/li>}
```

View File

@ -3,42 +3,58 @@ name: ""
has_index: true
children:
- path: index
name: Index
- path: basics
name: Basics
children:
- path: variables-and-constants
name: Variables and constants
- path: simple-datatypes
name: Simple datatypes
- path: function-calls
name: Function calls
- path: operators
name: Operators
- path: tuples
name: Tuples
- path: indentation-rules
name: Indentation rules
- path: flow-control
name: Flow control
children:
- path: conditionals
name: Conditionals
- path: arrays
name: Arrays
- path: loops
name: Loops
- path: functions
name: Functions
children:
- path: definition
name: Definition
- path: lambdas
name: Lambdas
- path: parameters
name: Parameters
- path: objects
name: Objects
children:
- path: definition
name: Definition
- path: classes
name: Classes
children:
- path: definition
name: Definition
- path: modules
name: Modules
children:
- path: import
name: Import

View File

@ -5,4 +5,6 @@ children:
name: Prelude
children:
- path: String
name: String
- path: Console
name: Console

View File

@ -36,17 +36,7 @@ pub fn highlight(input: &String) -> String {
TokenType::Identifier if token.value == "true" || token.value == "false" => {
replace!("keyword", token, offset, output)
}
TokenType::String => {
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::String => replace!("string", token, offset, output),
TokenType::Comment => replace!("comment", token, offset, output),
TokenType::VAL | TokenType::VAR => replace!("keyword", token, offset, output),
_ => {}

View File

@ -32,12 +32,14 @@ pub fn compile(file: &PathBuf, input_folder: &Path, output_folder: &Path, file_t
output_file.set_extension("html");
//
// Compilation
// Read MD from disk
//
let file_content_bytes = fs::read(&input_file).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 html_text = md_ast.to_html();
let sidebar_html = md_ast.generate_sidebar();

View File

@ -14,6 +14,8 @@ pub enum Node<'a> {
pub struct File<'a> {
/// Name of the file
path: &'a String,
/// Display name of the file
name: &'a String,
}
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")
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 = (
table.get(y_str!("name")),
table.get(y_str!("has_index")),
table.get(y_str!("children")),
);
match input_data {
(None, None, None) => Node::File(File { path }),
(Some(name), has_index, Some(children)) => {
let Yaml::String(name) = name
else { panic!("YAML: `name` MUST be a String") };
(None, None) => Node::File(File { path, name }),
(has_index, Some(children)) => {
let has_index = match has_index {
Some(Yaml::Boolean(v)) => *v,
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>",
current_path.to_str().unwrap(),
file.path,
file.path
file.name
)
}
}

View File

@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"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"
},
"keywords": [],