diff --git a/lexers/embedded/odin.xml b/lexers/embedded/odin.xml new file mode 100644 index 000000000..5fca0a39d --- /dev/null +++ b/lexers/embedded/odin.xml @@ -0,0 +1,113 @@ + + + Odin + odin + *.odin + text/odin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lexers/testdata/odin.actual b/lexers/testdata/odin.actual new file mode 100644 index 000000000..ae7801c05 --- /dev/null +++ b/lexers/testdata/odin.actual @@ -0,0 +1,90 @@ +package main + +import "core:fmt" + +/* +some comments in odin can + /* be nested! */ +and it should still work +*/ + +Data :: struct { + c: complex64, + q: quaternion256, +} + +/* some other comment */ + +E :: enum(u32) { + First, + Second, + Third, +} + +E_Set :: distinct bit_set[E; u32] + +foo_int :: proc(x: int) -> bool { + return false +} + +foo_float :: proc(f: f32) -> bool { + return true +} + +foo_en :: proc(e: E) -> bool { + return e == .Third +} + +foo :: proc{foo_int, foo_float, foo_en} + +SOME_CONSTANT :: #config(COMMAND_LINE_ARG, 3) +main :: proc() { + loc := #caller_location + + m: map[string]struct{} + da: [dynamic]f64 + + len(da) + cap(da) + + foo(32) + + #panic("oof") + + y := &da + y^ = make([dynamic]f64, 100) + defer delete(da) + + x := []int{1, 2, 3, 4} + for v, i in x { + fmt.println(i, "-", v) + } + + z := E_Set{.First, .Second} + z2 := E_Set{.Third} + + assert(z | z2 == {.First, .Second, .Third}) +} + +@(test) +a_test_proc :: proc(t: ^testing.T) { + value: int + value = 3 + testing.errnof("a format: %s", value) +} + +@(disable = ODIN_DEBUG) +debug_thing :: proc(x, y, z: int) { + fmt.println(x, y, z) +} + +@private +program := ` +foo :: proc() { + fmt.println("hellope!") +} +` + +@(private = "file") +pkg: int + diff --git a/lexers/testdata/odin.expected b/lexers/testdata/odin.expected new file mode 100644 index 000000000..272c1c2e2 --- /dev/null +++ b/lexers/testdata/odin.expected @@ -0,0 +1,444 @@ +[ + {"type":"KeywordNamespace","value":"package"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"main"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"KeywordNamespace","value":"import"}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"core:fmt\""}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"CommentMultiline","value":"/*\nsome comments in odin can\n /* be nested! */\nand it should still work\n*/"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Name","value":"Data"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"struct"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"c"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"complex64"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"q"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"quaternion256"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"CommentMultiline","value":"/* some other comment */"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Name","value":"E"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"enum"}, + {"type":"Punctuation","value":"("}, + {"type":"KeywordType","value":"u32"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"First"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"Second"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"Third"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Name","value":"E_Set"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"distinct"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"bit_set"}, + {"type":"Punctuation","value":"["}, + {"type":"Name","value":"E"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"u32"}, + {"type":"Punctuation","value":"]"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Name","value":"foo_int"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"proc"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"x"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"int"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"-\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"bool"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Keyword","value":"return"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordConstant","value":"false"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Name","value":"foo_float"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"proc"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"f"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"f32"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"-\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"bool"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Keyword","value":"return"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordConstant","value":"true"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Name","value":"foo_en"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"proc"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"e"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"E"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"-\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"bool"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Keyword","value":"return"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"=="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"Third"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Name","value":"foo"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"proc"}, + {"type":"Punctuation","value":"{"}, + {"type":"Name","value":"foo_int"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"foo_float"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"foo_en"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"Name","value":"SOME_CONSTANT"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameDecorator","value":"#config"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"COMMAND_LINE_ARG"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameOther","value":"3"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Name","value":"main"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"proc"}, + {"type":"Punctuation","value":"()"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"loc"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":":="}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameDecorator","value":"#caller_location"}, + {"type":"TextWhitespace","value":"\n\n\t"}, + {"type":"Name","value":"m"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"map"}, + {"type":"Punctuation","value":"["}, + {"type":"KeywordType","value":"string"}, + {"type":"Punctuation","value":"]"}, + {"type":"KeywordDeclaration","value":"struct"}, + {"type":"Punctuation","value":"{}"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"da"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"["}, + {"type":"Keyword","value":"dynamic"}, + {"type":"Punctuation","value":"]"}, + {"type":"KeywordType","value":"f64"}, + {"type":"TextWhitespace","value":"\n\n\t"}, + {"type":"Keyword","value":"len"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"da"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Keyword","value":"cap"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"da"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\n\t"}, + {"type":"Name","value":"foo"}, + {"type":"Punctuation","value":"("}, + {"type":"NameOther","value":"32"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\n\t"}, + {"type":"NameDecorator","value":"#panic"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\"oof\""}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\n\t"}, + {"type":"Name","value":"y"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":":="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"\u0026"}, + {"type":"Name","value":"da"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"y"}, + {"type":"Operator","value":"^"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"make"}, + {"type":"Punctuation","value":"(["}, + {"type":"Keyword","value":"dynamic"}, + {"type":"Punctuation","value":"]"}, + {"type":"KeywordType","value":"f64"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameOther","value":"100"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Keyword","value":"defer"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"delete"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"da"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\n\t"}, + {"type":"Name","value":"x"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":":="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"[]"}, + {"type":"KeywordType","value":"int"}, + {"type":"Punctuation","value":"{"}, + {"type":"NameOther","value":"1"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameOther","value":"2"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameOther","value":"3"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameOther","value":"4"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Keyword","value":"for"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"v"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"i"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"in"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"x"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t\t"}, + {"type":"Name","value":"fmt"}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"println"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"i"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"\"-\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"v"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n\t"}, + {"type":"Name","value":"z"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":":="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"E_Set"}, + {"type":"Punctuation","value":"{."}, + {"type":"Name","value":"First"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"Second"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"z2"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":":="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"E_Set"}, + {"type":"Punctuation","value":"{."}, + {"type":"Name","value":"Third"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n\t"}, + {"type":"Name","value":"assert"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"z"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"|"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"z2"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"=="}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{."}, + {"type":"Name","value":"First"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"Second"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"Third"}, + {"type":"Punctuation","value":"})"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"NameAttribute","value":"@(test)"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Name","value":"a_test_proc"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"proc"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"t"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"^"}, + {"type":"Name","value":"testing"}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"T"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"value"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"int"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"value"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameOther","value":"3"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"testing"}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"errnof"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralString","value":"\"a format: %s\""}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"value"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"NameAttribute","value":"@(disable = ODIN_DEBUG)"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Name","value":"debug_thing"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"::"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordDeclaration","value":"proc"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"x"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"y"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"z"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"int"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n\t"}, + {"type":"Name","value":"fmt"}, + {"type":"Punctuation","value":"."}, + {"type":"Name","value":"println"}, + {"type":"Punctuation","value":"("}, + {"type":"Name","value":"x"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"y"}, + {"type":"Punctuation","value":","}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"z"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"NameAttribute","value":"@private\n"}, + {"type":"Name","value":"program"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":":="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralString","value":"`\nfoo :: proc() {\n\tfmt.println(\"hellope!\")\n}\n`"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"NameAttribute","value":"@(private = \"file\")"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Name","value":"pkg"}, + {"type":"Operator","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordType","value":"int"}, + {"type":"TextWhitespace","value":"\n\n"} +]