mighty

The mighty programming language, compiler and tools (WIP)
Log | Files | Refs

commit d4f7bfc0f042898f41dccf822797c2298c9f491c
parent 6771a98d86a09d29fa22b68ea33037624db8469c
Author: citbl <citbl@citbl.org>
Date:   Sat, 16 May 2026 18:01:07 +1000

refac

Diffstat:
Mmtc/lexer/lexer.go | 70++++++++++++++++++++++++++++++++++------------------------------------
Mmtc/makefile | 2+-
2 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/mtc/lexer/lexer.go b/mtc/lexer/lexer.go @@ -8,23 +8,25 @@ type Kind int const ( Ident Kind = iota - Plus - PlusEq - PlusPlus + Dot Colon ColonColon + Comma + EOF + Eq + LiteralBool + LiteralChar + LiteralFloat + LiteralInt + LiteralString Minus MinusEq MinusMinus LParen RParen - Dot - EOF - IntLiteral - FloatLiteral - StringLiteral - CharLiteral - BoolLiteral + Plus + PlusEq + PlusPlus BadToken ) @@ -67,10 +69,10 @@ func Lex(src string) []Token { continue } if is_digit(c) { - numeric := IntLiteral + numeric := LiteralInt for i < len(src) && (is_digit(src[i]) || is__(src[i]) && is_dot(src[i])) { if is_dot(src[i]) { - numeric = FloatLiteral + numeric = LiteralFloat } i++ col++ @@ -87,7 +89,7 @@ func Lex(src string) []Token { col++ } - res = append(res, Token{StringLiteral, src[start+1 : i], line, startCol}) + res = append(res, Token{LiteralString, src[start+1 : i], line, startCol}) i++ // consume closing dbquote col++ continue @@ -129,6 +131,10 @@ func Lex(src string) []Token { default: res = append(res, Token{Plus, src[i : i+1], line, col}) } + case '=': + res = append(res, Token{Eq, src[i : i+1], line, col}) + case ',': + res = append(res, Token{Comma, src[i : i+1], line, col}) case '(': res = append(res, Token{LParen, src[i : i+1], line, col}) case ')': @@ -144,31 +150,23 @@ func Lex(src string) []Token { return res } -func is_space(c byte) bool { - return c == ' ' || c == '\t' || c == '\r' || c == '\n' -} - -func is_alpha(c byte) bool { - return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' -} - -func is_alphanum(c byte) bool { - return is_alpha(c) || is_digit(c) -} - -func is__(c byte) bool { return c == '_' } -func is_dot(c byte) bool { return c == '.' } - -func is_digit(c byte) bool { - return c >= '0' && c <= '9' -} +func is__(c byte) bool { return c == '_' } +func is_alpha(c byte) bool { return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' } +func is_alphanum(c byte) bool { return is_alpha(c) || is_digit(c) } +func is_digit(c byte) bool { return c >= '0' && c <= '9' } +func is_dot(c byte) bool { return c == '.' } +func is_space(c byte) bool { return c == ' ' || c == '\t' || c == '\r' || c == '\n' } func (k Kind) String() string { switch k { case Dot: return "Dot" + case Comma: + return "Comma" case Ident: return "Ident" + case Eq: + return "Eq" case Plus: return "Plus" case PlusEq: @@ -191,15 +189,15 @@ func (k Kind) String() string { return "RParen" case EOF: return "EOF" - case IntLiteral: + case LiteralInt: return "IntLiteral" - case FloatLiteral: + case LiteralFloat: return "FloatLiteral" - case StringLiteral: + case LiteralString: return "StringLiteral" - case CharLiteral: + case LiteralChar: return "CharLiteral" - case BoolLiteral: + case LiteralBool: return "BoolLiteral" case BadToken: return "BAD~~~TOKEN" diff --git a/mtc/makefile b/mtc/makefile @@ -1,2 +1,2 @@ default: - go run . test.mty + go run . target.mty