Skip to content

Commit 8d63382

Browse files
committed
[docs] OK seriously, last docs change today
1 parent 8ed59da commit 8d63382

File tree

8 files changed

+68
-42
lines changed

8 files changed

+68
-42
lines changed

docs/book.toml

+6
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@ authors = ["iiPython"]
55
language = "en"
66
src = "./"
77

8+
[build]
9+
create-missing = false
10+
811
[output.html]
912
git-repository-url = "https://github.com/iiPythonx/xpp"
13+
14+
[output.html.redirect]
15+
"/README.html" = "/"

docs/documents/datatypes.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ It can be compared using mathematical comparators or be modified using certain o
126126

127127
Unlike Python, integers do allow leading `0`s to exist:
128128

129-
```xt
129+
```xpp
130130
var myInteger 05
131131
prt myInteger :: 5
132132
```
133133

134134
In vanilla x++, it can also be used as a boolean value, where `1` represents `true` and `0` represents `false`:
135135

136-
```xt
136+
```xpp
137137
psh hamburgerIsEaten 1
138138
if (hamburgerIsEaten == 1) "prt 'Someone ate my hamburger'"
139139
```
@@ -225,7 +225,7 @@ Any non-string data type within a string interpolation will require the use of `
225225

226226
When being compared against using mathematical comparators, it is compared lexicographically:
227227

228-
```xt
228+
```xpp
229229
if "abc" < "cba" "prt 'true'"
230230
```
231231

docs/documents/packages.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
Packages are x++ files written by other people that can be imported to your x++ project using the `imp` operator:
2828

29-
```xt
29+
```xpp
3030
imp "examplePackage"
3131
```
3232

@@ -36,7 +36,7 @@ Imported packages are only available in that one specific file. When attempting
3636

3737
You can use an imported package by referencing the package name and then followed by a dot and the section name like so:
3838

39-
```xt
39+
```xpp
4040
imp "examplePackage"
4141
4242
examplePackage.mySection

docs/tutorials/branching.md

+30-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Now let's put it together:
4343

4444
```xpp
4545
var myAge 20
46-
if (myAge == 20) "prt 'I am 20 years old'" "prt 'I am not 20 years old'"
46+
if (myAge == 20) { prt "I am 20 years old" } { prt "I am not 20 years old" }
4747
```
4848

4949
When you run the code, you should see it outputs `"I am 20 years old"`. Try changing the value of `myAge` and see what happens.
@@ -52,38 +52,54 @@ The `else` branch is optional. If you only want to check if the expression is tr
5252

5353
```xpp
5454
var myInteger 5
55-
if (myInteger == 5) "prt 'My integer is 5'"
55+
if (myInteger == 5) { prt "My integer is 5" }
5656
```
5757

5858
With that knowledge, you can now output a special text if the user name matches yours:
5959

6060
```xpp
6161
:: main.xpp
6262
read "What is your name? " ?name
63-
upr name
6463
read "What is your age? " ?age
65-
int age
66-
sub 2023 age ?birthYear
67-
if (name == "BOB") "prt 'Welcome, Bob!'"
68-
prt "Your name is $(name) and you were born in $(birthYear)"
64+
65+
:: Keep a copy of their original string
66+
var ogName name
67+
68+
:: Calculate birth year by using the current year
69+
int age :: Ensure it's an integer
70+
sub 2024 age ?birthYear
71+
72+
:: Convert the name to lowercase (so we can check it)
73+
if ((lwr name) == "bob") { prt "Welcome, Bob!" }
74+
75+
:: Show them their info
76+
prt "Your name is $(ogName) and you were born in $(birthYear)."
6977
```
7078

7179
There are many more comparators, such as the `greater than` (`>`) or `not equal` (`!=`). They work the same way as the `equal to` comparator.
7280

7381
Now's your turn. Check if the user's age is equal to or above 16 and output `"You can also drive a car"` after you output their name and their birth year if it is true.
7482

75-
Did you get something like this:
83+
Did you get something like this?
7684

7785
```xpp
7886
:: main.xpp
7987
read "What is your name? " ?name
80-
upr name
8188
read "What is your age? " ?age
82-
int age
83-
sub 2023 age ?birthYear
84-
if (name == "BOB") "prt 'Welcome, Bob!'"
85-
prt "Your name is $(name) and you were born in $(birthYear)"
86-
if (age >= 16) "prt 'You can also drive a car'"
89+
90+
:: Keep a copy of their original string
91+
var ogName name
92+
93+
:: Calculate birth year by using the current year
94+
int age :: Ensure it's an integer
95+
sub 2024 age ?birthYear
96+
97+
:: Convert the name to lowercase (so we can check it)
98+
if ((lwr name) == "bob") { prt "Welcome, Bob!" }
99+
100+
:: Show them their info
101+
prt "Your name is $(ogName) and you were born in $(birthYear)."
102+
if (age >= 16) { prt "You can also drive a car." }
87103
```
88104

89105
In the next lesson, you will be learning how to make a calculator using x++.

docs/tutorials/calculator.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ From the last three lessons, you learned how to print values into the terminal,
2424

2525
Let's introduce the program and get some inputs from the user using the `prt` and `read` operators:
2626

27-
```xt
27+
```xpp
2828
:: main.xpp
2929
prt "Welcome to the x++ calculator!"
3030
prt "-----"
@@ -74,7 +74,7 @@ upr o
7474

7575
Now we can use the `if` operator to check what operator the user selected and act accordingly. Currently, there are four types of mathematical operators: `add`, `sub`, `mul`, and `div`. Let's use them:
7676

77-
```xt
77+
```xpp
7878
:: main.xpp
7979
prt "Welcome to the x++ calculator!"
8080
prt "-----"
@@ -91,15 +91,15 @@ prt "-----"
9191
int a
9292
int b
9393
upr o
94-
if (o == "A") "add a b ?c"
95-
if (o == "S") "sub a b ?c"
96-
if (o == "M") "mul a b ?c"
97-
if (o == "D") "div a b ?c"
94+
if (o == "A") { add a b ?c } \
95+
(o == "S") { sub a b ?c } \
96+
(o == "M") { mul a b ?c } \
97+
(o == "D") { div a b ?c }
9898
```
9999

100100
Since you defined `c` as the answer to the equation, you can simply output it to the terminal. Using string interpolation, you can also use variables within your strings:
101101

102-
```xt
102+
```xpp
103103
:: main.xpp
104104
prt "Welcome to the x++ calculator!"
105105
prt "-----"
@@ -116,11 +116,11 @@ prt "-----"
116116
int a
117117
int b
118118
upr o
119-
if (o == "A") "add a b ?c"
120-
if (o == "S") "sub a b ?c"
121-
if (o == "M") "mul a b ?c"
122-
if (o == "D") "div a b ?c"
123-
prt "The answer to that equation is $(c)"
119+
if (o == "A") { add a b ?c } \
120+
(o == "S") { sub a b ?c } \
121+
(o == "M") { mul a b ?c } \
122+
(o == "D") { div a b ?c }
123+
prt "The answer to that equation is $(c)."
124124
```
125125

126126
Tada! You got a working calculator. How cool is that?

docs/tutorials/hello-world.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Let's put that in your code!
6060
:: main.xpp
6161
var name "Bob"
6262
var age 20
63-
prt "My name is Bob and I am 20 years old"
63+
prt "My name is Bob and I am 20 years old."
6464
```
6565

6666
Your can put your variables into your string using `string interpolation`. String interpolation is the process of inserting another statement within a string. This is usually done so by wrapping them in `$()`.
@@ -69,8 +69,8 @@ The statement you can wrap inside of `$()` can be any valid x++ syntax, however
6969

7070
```xpp
7171
var x 5
72-
prt "$(x) should be 5"
73-
:: 5 should be 5
72+
prt "$(x) should be 5."
73+
:: 5 should be 5.
7474
```
7575

7676
Let's try it!
@@ -79,7 +79,7 @@ Let's try it!
7979
:: main.xpp
8080
var name "Bob"
8181
var age 20
82-
prt "My name is $(name) and I am $(age) years old"
82+
prt "My name is $(name) and I am $(age) years old."
8383
```
8484

8585
You did it! You made your first ever x++ project.

docs/tutorials/user-input.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ So far, you should've gotten this in your `main.xpp` file:
2828
:: main.xpp
2929
var name "Bob"
3030
var age 20
31-
prt "My name is $(name) and I am $(age) years old"
31+
prt "My name is $(name) and I am $(age) years old."
3232
```
3333

3434
What if you want to ask what the user's name is instead of yours? You can use the `read` operator to get user input from the terminal. The `read` operator takes in two arguments, the `prompt` and the `output`. The prompt is what the user will see when you get a user input. You can think of it as asking a question. The output is the answer from the user input.
@@ -41,11 +41,11 @@ read "What is your favorite color? " ?favoriteColor
4141

4242
You can replace your `var` operators and use the `read` operators instead:
4343

44-
```xt
44+
```xpp
4545
:: main.xpp
4646
read "What is your name? " ?name
4747
read "What is your age? " ?age
48-
prt "Your name is $(name) and you are $(age) years old"
48+
prt "Your name is $(name) and you are $(age) years old."
4949
```
5050

5151
You can also make the name more standout from the rest of the string by making it all capitalized. You can uppercase all the letters in a string by using the `upr` operator:
@@ -63,7 +63,7 @@ Let's try it:
6363
read "What is your name? " ?name
6464
upr name
6565
read "What is your age? " ?age
66-
prt "Your name is $(name) and you are $(age) years old"
66+
prt "Your name is $(name) and you are $(age) years old."
6767
```
6868

6969
You can also use mathematical operators to calculate the user's birth year. By subtracting the user's age from the current year, you get their birth year. You can use the `sub` operator for this purpose:
@@ -89,8 +89,8 @@ read "What is your name? " ?name
8989
upr name
9090
read "What is your age? " ?age
9191
int age
92-
sub 2023 age ?birthYear
93-
prt "Your name is $(name) and you were born in $(birthYear)"
92+
sub 2024 age ?birthYear
93+
prt "Your name is $(name) and you were born in $(birthYear)."
9494
```
9595

9696
Now it will ask the user their name and age and output their name and birth year. Incredible isn't it?

src/xpp/core/datastore.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ def _parse(self) -> Any:
9191
elif token[1].isdigit() or token[1] in "+-":
9292
break
9393

94-
expr = expr.replace(token, str(self.mem.interpreter.execute(token[1:][:-1])))
94+
new_data = self.mem.interpreter.execute(token[1:][:-1])
95+
if isinstance(new_data, str):
96+
new_data = f"\"{new_data}\""
97+
98+
expr = expr.replace(token, str(new_data))
9599

96100
return simple_eval(expr, names = self.mem.variables["scope"][self.last_stack.sid])
97101

0 commit comments

Comments
 (0)