mirror of
https://github.com/Ed94/metadesk.git
synced 2026-07-23 16:07:51 +00:00
[examples] write labels.mdesk with examples of labels
This commit is contained in:
@@ -322,7 +322,7 @@ main:
|
||||
@doc("This is a string literal that used triplets (three of its boundary characters in a row, on either side) to mark its boundaries, making it multiline.")
|
||||
StringTriplet,
|
||||
|
||||
@doc("The label on this node comes from a token with the @code MD_TokenKind_NumericLiteral kind.")
|
||||
@doc("The label on this node comes from a token with the @code MD_TokenKind_Numeric kind.")
|
||||
Numeric,
|
||||
@doc("The label on this node comes from a token with the @code MD_TokenKind_Identifier kind.")
|
||||
Identifier,
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
////////////////////////////////
|
||||
// Identifiers (MD_NodeFlag_Identifier)
|
||||
abc _foo_ x123
|
||||
almostAnyCIdentifier // not including $
|
||||
|
||||
////////////////////////////////
|
||||
// Numerics (MD_NodeFlag_Numeric)
|
||||
123 0x123ABC 0b10101 123.456
|
||||
0.123 123_456_789
|
||||
123abc456xyz
|
||||
123e+100
|
||||
456E-100
|
||||
789e+E-e+E-100100xyz
|
||||
|
||||
////////////////////////////////
|
||||
// String Literals (MD_NodeFlag_StringLiteral)
|
||||
|
||||
//(MD_NodeFlag_StringDoubleQuote)
|
||||
"Hello World"
|
||||
" 'Hello World` "
|
||||
"\"Hello World\""
|
||||
"\\\a\b\c\d\e\f\""
|
||||
""
|
||||
|
||||
//(MD_NodeFlag_StringSingleQuote)
|
||||
'Hello World'
|
||||
' "Hello World` '
|
||||
''
|
||||
|
||||
//(MD_NodeFlag_StringTick)
|
||||
`Hello World`
|
||||
` "Hello World' `
|
||||
``
|
||||
|
||||
////////////////////////////////
|
||||
// Multi-Line String Literals (MD_NodeFlag_StringLiteral|MD_NodeFlag_StringTriplet)
|
||||
|
||||
//(MD_NodeFlag_StringDoubleQuote)
|
||||
"""
|
||||
This string can go on
|
||||
for as many lines as I want.
|
||||
And it can say things like
|
||||
"Hello World"
|
||||
or you know, whatever.
|
||||
"""
|
||||
|
||||
//(MD_NodeFlag_StringSingleQuote)
|
||||
'''
|
||||
Multi-line strings can start
|
||||
with a triplet of any of the
|
||||
string markers.
|
||||
'''
|
||||
|
||||
//(MD_NodeFlag_Tick)
|
||||
```
|
||||
```
|
||||
|
||||
////////////////////////////////
|
||||
// Symbols (MD_NodeFlag_Symbol)
|
||||
+ - * / = & ^ % ! | ? < > . ~
|
||||
$
|
||||
++ -- ** == && ^^ %% !! || ??
|
||||
<< >> .. ~~ $$ -> <- => <= ?.
|
||||
+= -= *= /= |= &= ^= %= != |=
|
||||
...
|
||||
+- +++++++ ??? !? $! $$$ <->
|
||||
+-*/=&^%~|?<>.~$
|
||||
|
||||
/*
|
||||
** A few punctuation characters are not counted with the rest
|
||||
** of the symbol characters. These are the 'reserved' characters:
|
||||
** ( ) { } [ ] : ; , @ # \
|
||||
**
|
||||
** And the sequences // and /* start comments so no symbol
|
||||
** can start with either of those pairs.
|
||||
**
|
||||
** Block comments are nested */
|
||||
*/
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
// Identifiers, Numbers, Strings, and Symbols are the different kinds
|
||||
// of 'labels' in Metadesk. They can all form main metadesk nodes:
|
||||
|
||||
_foo_: { bar123456; _123; }
|
||||
|
||||
0: (1.0.1.1, 1.2.0.0)
|
||||
|
||||
```
|
||||
#include <stdio.h>
|
||||
int main(){
|
||||
printf("Hello World\n");
|
||||
}
|
||||
```: "Hello World"
|
||||
|
||||
..: . + .
|
||||
+1
-1
@@ -19,7 +19,7 @@ Example Programs:
|
||||
|
||||
Example Metadesk Files:
|
||||
[x] Hello world
|
||||
[ ] identifiers, numbers, strings, and symbols
|
||||
[x] identifiers, numbers, strings, and symbols
|
||||
[ ] sets, seperators, labels, and tags
|
||||
|
||||
|
||||
|
||||
+4
-3
@@ -619,7 +619,7 @@ MD_CharIsUnreservedSymbol(MD_u8 c)
|
||||
return (c == '~' || c == '!' || c == '$' || c == '%' || c == '^' ||
|
||||
c == '&' || c == '*' || c == '-' || c == '=' || c == '+' ||
|
||||
c == '<' || c == '.' || c == '>' || c == '/' || c == '?' ||
|
||||
c == '|' || c == '\\');
|
||||
c == '|');
|
||||
}
|
||||
|
||||
MD_FUNCTION_IMPL MD_b32
|
||||
@@ -1891,7 +1891,7 @@ MD_TokenFromString(MD_String8 string)
|
||||
|
||||
}break;
|
||||
|
||||
// NOTE(allen): Identifiers, Numbers, Operators
|
||||
// NOTE(allen): Identifiers, Numbers, Symbols
|
||||
default:
|
||||
{
|
||||
if (MD_CharIsAlpha(*at) || *at == '_')
|
||||
@@ -1905,7 +1905,7 @@ MD_TokenFromString(MD_String8 string)
|
||||
else if (MD_CharIsDigit(*at))
|
||||
{
|
||||
token.node_flags |= MD_NodeFlag_Numeric;
|
||||
token.kind = MD_TokenKind_NumericLiteral;
|
||||
token.kind = MD_TokenKind_Numeric;
|
||||
at += 1;
|
||||
|
||||
for (; at < one_past_last;){
|
||||
@@ -1932,6 +1932,7 @@ MD_TokenFromString(MD_String8 string)
|
||||
{
|
||||
symbol_lex:
|
||||
|
||||
token.node_flags |= MD_NodeFlag_Symbol;
|
||||
token.kind = MD_TokenKind_Symbol;
|
||||
at += 1;
|
||||
MD_TokenizerScan(MD_CharIsUnreservedSymbol(*at));
|
||||
|
||||
+3
-2
@@ -584,6 +584,7 @@ enum
|
||||
MD_NodeFlag_Numeric = (1<<14),
|
||||
MD_NodeFlag_Identifier = (1<<15),
|
||||
MD_NodeFlag_StringLiteral = (1<<16),
|
||||
MD_NodeFlag_Symbol = (1<<17),
|
||||
};
|
||||
|
||||
typedef struct MD_Node MD_Node;
|
||||
@@ -670,7 +671,7 @@ typedef MD_u32 MD_TokenKind;
|
||||
enum
|
||||
{
|
||||
MD_TokenKind_Identifier = (1<<0),
|
||||
MD_TokenKind_NumericLiteral = (1<<1),
|
||||
MD_TokenKind_Numeric = (1<<1),
|
||||
MD_TokenKind_StringLiteral = (1<<2),
|
||||
MD_TokenKind_Symbol = (1<<3),
|
||||
MD_TokenKind_Reserved = (1<<4),
|
||||
@@ -692,7 +693,7 @@ enum
|
||||
MD_TokenGroup_Whitespace),
|
||||
MD_TokenGroup_Regular = ~MD_TokenGroup_Irregular,
|
||||
MD_TokenGroup_Label = (MD_TokenKind_Identifier|
|
||||
MD_TokenKind_NumericLiteral|
|
||||
MD_TokenKind_Numeric|
|
||||
MD_TokenKind_StringLiteral|
|
||||
MD_TokenKind_Symbol),
|
||||
MD_TokenGroup_Error = (MD_TokenKind_BrokenComment|
|
||||
|
||||
@@ -104,15 +104,15 @@ int main(void)
|
||||
TestResult(TokenMatch(tokens[1], MD_S8Lit(" "), MD_TokenKind_Whitespace));
|
||||
TestResult(TokenMatch(tokens[2], MD_S8Lit("def"), MD_TokenKind_Identifier));
|
||||
TestResult(TokenMatch(tokens[3], MD_S8Lit(" "), MD_TokenKind_Whitespace));
|
||||
TestResult(TokenMatch(tokens[4], MD_S8Lit("123"), MD_TokenKind_NumericLiteral));
|
||||
TestResult(TokenMatch(tokens[4], MD_S8Lit("123"), MD_TokenKind_Numeric));
|
||||
TestResult(TokenMatch(tokens[5], MD_S8Lit(" "), MD_TokenKind_Whitespace));
|
||||
TestResult(TokenMatch(tokens[6], MD_S8Lit("456"), MD_TokenKind_NumericLiteral));
|
||||
TestResult(TokenMatch(tokens[6], MD_S8Lit("456"), MD_TokenKind_Numeric));
|
||||
TestResult(TokenMatch(tokens[7], MD_S8Lit(" "), MD_TokenKind_Whitespace));
|
||||
TestResult(TokenMatch(tokens[8], MD_S8Lit("123_456"), MD_TokenKind_NumericLiteral));
|
||||
TestResult(TokenMatch(tokens[8], MD_S8Lit("123_456"), MD_TokenKind_Numeric));
|
||||
TestResult(TokenMatch(tokens[9], MD_S8Lit(" "), MD_TokenKind_Whitespace));
|
||||
TestResult(TokenMatch(tokens[10], MD_S8Lit("abc123"), MD_TokenKind_Identifier));
|
||||
TestResult(TokenMatch(tokens[11], MD_S8Lit(" "), MD_TokenKind_Whitespace));
|
||||
TestResult(TokenMatch(tokens[12], MD_S8Lit("123abc"), MD_TokenKind_NumericLiteral));
|
||||
TestResult(TokenMatch(tokens[12], MD_S8Lit("123abc"), MD_TokenKind_Numeric));
|
||||
TestResult(TokenMatch(tokens[13], MD_S8Lit(" "), MD_TokenKind_Whitespace));
|
||||
TestResult(TokenMatch(tokens[14], MD_S8Lit("+-*"), MD_TokenKind_Symbol));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user