miki

Miki: personal wiki with the fmd markup format
git clone https://wtenison.com/repo/miki.git
Log | Files | Refs | README | LICENSE

commit c2a06cf2427eeadb1914c8128f82a0b361492cc3
parent e0ab93a77f243af664423974da884ec30a4876c5
Author: weetat <wtenison@protonmail.com>
Date:   Fri, 28 Feb 2025 18:41:13 +0000

Separated 'symbols' into arrays based on type

Diffstat:
Msrc/fmd/fmd.ebnf | 3++-
Msrc/fmd/fmd_test.go | 27++++++++++++++-------------
Msrc/fmd/lexer.go | 11++++++++---
3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/src/fmd/fmd.ebnf b/src/fmd/fmd.ebnf @@ -5,9 +5,10 @@ <keyword> "(" <block> ")" ":" <word> | <keyword> "(" <block> ")" ":" "{" <block> "}" | +<keyword> ::= "b" | "i" | "h" [1-6] | "@" | "#" | "col" | "img" | "_" + <block> ::= (<word> | <space>)+ <word> ::= (<letter> | <number> | <symbol>)+ -<keyword> ::= "b" | "i" | "h" [1-6] | "@" | "^" | "#" <space> ::= " " <letter> ::= [a-z] | [A-Z] diff --git a/src/fmd/fmd_test.go b/src/fmd/fmd_test.go @@ -1,26 +1,27 @@ package fmd import ( + "os" "testing" ) func TestFMD(t *testing.T) { - // _path := ("/home/weetat/MIKI/data/ents/home.fmd") + _path := ("/home/weetat/projects/miki/data/fmd/home.fmd") // WriteFMDtoHTMLFile(_path) - // t.Log("Path:", _path) - // _input, _err := os.ReadFile(_path) - // if _err != nil { - // t.Error("_ERROR\tcannot open file:", _err.Error()) - // return - // } + t.Log("Path:", _path) + _input, _err := os.ReadFile(_path) + if _err != nil { + t.Error("_ERROR\tcannot open file:", _err.Error()) + return + } - // _l := MakeLexer("MyLexer", _input) - // _tokens := _l.Exec() + _l := MakeLexer(_input) + _tokens := _l.Exec() - // // t.Log("Tokens:", _tokens) + // t.Log("Tokens:", _tokens) - // _p := MakeParser(_tokens) - // _ast := _p.Exec() + _p := MakeParser(_tokens) + _ast := _p.Exec() - // t.Log(interpret(_ast)) + t.Log(interpret(_ast)) } diff --git a/src/fmd/lexer.go b/src/fmd/lexer.go @@ -18,9 +18,9 @@ const ( tokenSpace // 2. " " tokenNewline // 3. \n tokenTab // 4. \t - tokenEscape // 5. \ // OPERATORS + tokenEscape // 5. \ tokenColon // 6. : tokenLBrace // 7. { tokenRBrace // 8. } @@ -33,7 +33,8 @@ type token struct { Value string } -var symbols = []string{" ", "\n", "\t", "\\", ":", "{", "}", "(", ")"} +var operatorSymbols = []string{"\\", ":", "{", "}", "(", ")"} +var spacingSymbols = []string{" ", "\n", "\t"} var keywords = []string{ "b", // bold "i", // italic @@ -86,7 +87,11 @@ func (l *lexer) Exec() []token { var _tokenString string _start := l.pos - for l.pos < len(l.input) && !slices.Contains(symbols, string(l.input[l.pos])) { + var _symbols []string + _symbols = append(_symbols, spacingSymbols...) + _symbols = append(_symbols, operatorSymbols...) + + for l.pos < len(l.input) && !slices.Contains(_symbols, string(l.input[l.pos])) { l.pos++ }