Skip to content

Commit bbbb628

Browse files
Introducing 'as' keyword
1 parent b438204 commit bbbb628

File tree

18 files changed

+163
-46
lines changed

18 files changed

+163
-46
lines changed

CHANGELOG

Lines changed: 0 additions & 12 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# SOARE Changelog
3+
4+
---
5+
6+
## v1.0.0+
7+
8+
- First SOARE release
9+
10+
## v1.2.0+
11+
12+
- Implement external/custom functions and keywords
13+
14+
## v1.2.3+
15+
16+
- Introducing `as` keyword

CODE_OF_CONDUCT.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
# Contributor Code of Conduct
3+
4+
## Our Commitment
5+
6+
We are committed to providing a friendly, safe, and welcoming environment, regardless of age, body type, disability, ethnicity, etc.
7+
8+
## Our Standards
9+
10+
**Examples of positive behavior**:
11+
12+
- Use welcoming and inclusive language
13+
- Respect different points of view
14+
- Accept constructive criticism
15+
16+
## Reporting
17+
18+
If you witness or experience inappropriate behavior, please contact us privately.
19+
20+
Thank you for contributing to a healthy and respectful project! ❤️

CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# Contribute to `SOARE`
3+
4+
If you wish to contribute to the project, I recommend focusing on the features outlined in the [TODO.md](TODO.md) and [issues](https://github.com/AntoineLandrieux/SOARE/issues).
5+
6+
## Contribution Process
7+
8+
1. Fork this repository
9+
2. Create a branch (`feature/my-new-feature`)
10+
3. Commit your changes
11+
4. Push your branch
12+
5. Open a Pull Request
13+
14+
## Coding rules
15+
16+
- Respect the project style
17+
- 1 feature = 1 Pull Request
18+
- Provide unit tests if possible

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ soareinfo();
2424
## 📖 Documentation
2525

2626
> [!IMPORTANT]
27-
> See [SOARE Documentation](doc/documentation.md) and [SOARE Changelog](CHANGELOG)
27+
> See [SOARE Documentation](doc/documentation.md) and [SOARE Changelog](CHANGELOG.md)
28+
>
2829
2930
## 🛠️ Recommended tools
3031

@@ -51,6 +52,11 @@ soareinfo();
5152
The SOARE source code is located in the Git repository at [github.com/AntoineLandrieux/SOARE](https://github.com/AntoineLandrieux/SOARE/).
5253
Contributions are most welcome by forking the repository and sending a pull request.
5354

55+
> [!IMPORTANT]
56+
>
57+
> Please read the [Code of Conduct](CODE_OF_CONDUCT.md) and [contribution guidelines](CONTRIBUTING.md)
58+
>
59+
5460
## 📜 Credit
5561

5662
See **[AUTHORS file](AUTHORS)**

TODO.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# TODO
3+
4+
## ✅/❌ Important Task List
5+
6+
- [ ] Possibility of having more than 100 custom keywords/functions
7+
8+
## ✅/❌ Optional Task List
9+
10+
- [ ] Create more professional unit tests
11+
12+
## 🧑‍💻 In progress
13+
14+
- [ ] Possibility of having more than 100 custom keywords/functions
15+
16+
## ✅ Done
17+
18+
- [X] Introducing `as` keyword

core/Error.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ static unsigned char enable = 1;
2222
/* Error level */
2323
static char errorlevel = EXIT_SUCCESS;
2424

25+
/* Last Error */
26+
static char *lasterror = "NoError";
27+
2528
/* Exceptions */
2629
static char *Exceptions[] = {
2730

@@ -71,6 +74,16 @@ void ClearException(void)
7174
errorlevel = EXIT_SUCCESS;
7275
}
7376

77+
/**
78+
* @brief Get last error
79+
*
80+
* @return char*
81+
*/
82+
char *GetError(void)
83+
{
84+
return lasterror;
85+
}
86+
7487
/**
7588
* @brief Returns the error level
7689
*
@@ -91,6 +104,11 @@ char ErrorLevel(void)
91104
*/
92105
void *LeaveException(SoareExceptions error, char *string, Document file)
93106
{
107+
// Set lasterror
108+
lasterror = Exceptions[error];
109+
// Set error at level EXIT_FAILURE (1)
110+
errorlevel = EXIT_FAILURE;
111+
94112
// If the errors are disabled, nothing is displayed
95113
if (enable)
96114
{
@@ -103,7 +121,7 @@ void *LeaveException(SoareExceptions error, char *string, Document file)
103121
//
104122
__soare_stderr,
105123
"\aExcept: %s\n\t\"%.13s\"\n\t ^~~~\n\tAt file %s:%lld:%lld\n",
106-
Exceptions[error],
124+
lasterror,
107125
string,
108126
file.file,
109127
file.ln,
@@ -117,7 +135,5 @@ void *LeaveException(SoareExceptions error, char *string, Document file)
117135
#endif /* __SOARE_COLORED_OUTPUT */
118136
}
119137

120-
// Set error at level EXIT_FAILURE (1)
121-
errorlevel = EXIT_FAILURE;
122138
return NULL;
123139
}

core/Parser.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,19 @@ AST Parse(Tokens *tokens)
439439
Node *iferror = Branch(NULL, NODE_IFERROR, old->file);
440440
BranchJoin(curr->parent, iferror);
441441
curr = iferror;
442+
443+
// iferror as <varname>
444+
if (!strcmp(tokens->value, KEYWORD_AS) && tokens->type == TKN_KEYWORD)
445+
{
446+
tokens = tokens->next;
447+
448+
if (tokens->type != TKN_NAME)
449+
return LeaveException(SyntaxError, old->value, old->file);
450+
451+
BranchJoin(curr, Branch(tokens->value, NODE_STRERROR, old->file));
452+
453+
tokens = tokens->next;
454+
}
442455
}
443456

444457
else if (!strcmp(old->value, KEYWORD_IF) || !strcmp(old->value, KEYWORD_WHILE))

core/Runtime.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ static char *Runtime(AST tree)
212212
// Raise an exception
213213
return ExitStatementError(statement, RaiseException, curr->value, curr->file);
214214

215+
case NODE_STRERROR:
216+
// Store error
217+
MemPush(statement, curr->value, strdup(GetError()));
218+
break;
219+
215220
case NODE_IMPORT:
216221
{
217222
// Import external file and merge its AST

core/Tokenizer.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static inline unsigned char strKeyword(char *string)
108108
{
109109
return (
110110
//
111+
!strcmp(KEYWORD_AS, string) ||
111112
!strcmp(KEYWORD_DO, string) ||
112113
!strcmp(KEYWORD_FN, string) ||
113114
!strcmp(KEYWORD_IF, string) ||
@@ -340,7 +341,7 @@ void TokensLog(Tokens *token)
340341
* [TOKENS] [test.soare:00001:00001, 09, "write"]
341342
* [TOKENS] [test.soare:00001:00007, 03, "Hello"]
342343
* [TOKENS] [test.soare:00001:00014, 0B, ";"]
343-
* [TOKENS] [test.soare:00000:00000, 00, "(null)"]
344+
* [TOKENS] [test.soare:00000:00000, 00, "EOF"]
344345
*
345346
*/
346347

@@ -555,6 +556,7 @@ Tokens *Tokenizer(char *__restrict__ filename, char *__restrict__ text)
555556
col += type == TKN_STRING;
556557
}
557558

559+
curr->value = strdup("EOF");
558560
// Return token
559561
return token;
560562
}

0 commit comments

Comments
 (0)