Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odin Programming Language #3204

Closed
gingerBill opened this issue Nov 23, 2021 · 3 comments
Closed

Odin Programming Language #3204

gingerBill opened this issue Nov 23, 2021 · 3 comments

Comments

@gingerBill
Copy link

Language
Odin is a general-purpose programming language with distinct typing, built for high performance, modern systems, and built-in data-oriented data types. The Odin Programming Language, the C alternative for the joy of programming. The Data-Oriented Language for Sane Software Development.

Additional resources
https://odin-lang.org/
https://odin-lang.org/docs/overview/
https://github.com/odin-lang/Odin

Syntax:

Prism.languages.odin = Prism.languages.extend('clike', {
	'string': {
		pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
		greedy: true
	},
	'keyword': /\b(?:asm|auto_cast|bit_set|break|case|cast|context|continue|defer|distinct|do|dynamic|else|enum|fallthrough|for|foreign|if|import|in|map|matrix|not_in|or_else|or_return|package|proc|return|struct|switch|transmute|typeid|union|using|when|where)\b/,
	'boolean': /\b(?:_|false|true|nil)\b/,
	'number': /(?:\b0[xh][0-9a-fA-F_]+|(?:\b0b[01_])|(?:\b0o[0-7_])|(?:\b0d[0-9_])|(?:\b0z[0-9abAB_])|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[-+]?\d+)?)[ijk]?/i,
	'operator': /[+-\/%~!=<>]=?|%%=?|---|\?|\|(?:=|\|=?)?|&(?:=|&=?|\~=?)?|>(?:>=?|=)?|<(?:<=?|=)?|:\s*=|:\s*:|\.\.[=<]?|->|[@#$]/,
	'builtin': /\b(?:abs|align_of|cap|clamp|complex|conj|expand_to_tuple|hadamard_product|imag|jmag|kmag|len|matrix_flatten|max|min|offset_of|offset_of_by_string|outer_product|quaternion|real|size_of|soa_unzip|soa_zip|swizzle|transpose|type_info_of|type_of|typeid_of|any|b(?:8|16|32|64)|bool|byte|c?string|complex(?:32|64|128)|f(?:16|32|64)(?:le|be)?|quaternion(?:64|128|256)|rawptr|rune|[ui](?:8|16|32|64|128)(?:le|be)?|u?int(?:ptr)?\b/
});
delete Prism.languages.odin['class-name'];
@RunDevelopment
Copy link
Member

Hi @gingerBill!

The language definition you suggested looks quite good. Do you want to make a PR?

@edukisto
Copy link
Contributor

edukisto commented Dec 11, 2021

Hi, @gingerBill and @RunDevelopment!

Just a few notes about the code.

  1. 'boolean'. Is nil a Boolean? And I don’t get what the Boolean _ is.

  2. 'operator':

    • [+-\/%~!=<>]=? captures ,= and .=, but these are not operators. [+-\/] (or [-+,./]) should be replaced with [-+/];

    • since [+-\/%~!=<>]=? captures all the hyphens, --- and -> find nothing;

    • the pattern splits %%, %%=, ++, --, ---, ->, .., ..<, ..=, <<, <<=, >>, and >>=;

    • the pattern doesn’t find (, ), *, *=, :, ;, [, ], ^, {, };

    • reserved/forbidden operators (++ and --) are not highlighted in a special way.

  3. The Odin strings are more complex than shown here. "Strings" and 'characters' support escaped characters, but don’t allow to escape newlines. `Raw strings` don’t support escaping. 'Characters' are escaped sequences themselves.

In addition, there are some ambiguities in the documentation.

  1. Although not documented, octal 4‑bit characters require the \0 prefix.
  2. 24‑bit Unicode characters (both "\UNNNNNN" and '\UNNNNNN') don’t work. However, it’s possible that I’ve misapplied them.
  3. matrix is a keyword, but it is not classified as a keyword in the docs.

Do you mind if I try to make a PR?

@RunDevelopment
Copy link
Member

  1. 'boolean'. Is nil a Boolean? And I don’t get what the Boolean _ is.

Some languages have an extended boolean algebra that includes the bottom type (null, nil, undefined, etc).

And I don’t get what the Boolean _ is.

That's a good point. _ is something like a discard, right? It should probably be a keyword.

  • [+-\/%~!=<>]=? captures ,= and .=, but these are not operators. [+-\/] (or [-+,./]) should be replaced with [-+/];

Very good find. Our ESLint rule regexp/no-obscure-range would have also caught this.

  • since [+-\/%~!=<>]=? captures all the hyphens, --- and -> find nothing;
  • the pattern splits %%, %%=, ++, --, ---, ->, .., ..<, ..=, <<, <<=, >>, and >>=;

Good point. Seems like operators still need some polish.

  • the pattern doesn’t find (, ), *, *=, :, ;, [, ], ^, {, };

Most of these are highlighted as punctuation.

  • reserved/forbidden operators (++ and --) are not highlighted in a special way.

Prism grammars generally don't care about invalid syntax, it's pretty much undefined behavior. I would suggest to just highlight them as regular operators. Prism isn't a parser or compiler, we don't valid code, we just produce some pretty colors.

  1. The Odin strings are more complex than shown here. "Strings" support escaped characters, but don’t allow to escape newlines. `Raw strings` don’t support escaping. 'Characters' are escaped sequences themselves.

String are always difficult in modern languages. I'm just thankful that there is no string interpolation syntax to make this even more difficult.

Do you mind if I try to make a PR?

I'm looking forward to it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants