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

Add lexer for the Odin programming language #116

Open
wants to merge 2 commits into
base: default
Choose a base branch
from

Conversation

brett-mahar
Copy link

Lexer for Odin based on scintillua/lexers/go.lua
Tested in Vis editor

Add lexer for Odin language
Add Odin language
@orbitalquark
Copy link
Owner

Thanks! I'll have a look when I have some time :)

Copy link
Owner

@orbitalquark orbitalquark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I've left some suggestions for changes. If you prefer that I make them, let me know, and I can do so in my own time.

-- Fold points.
lex:add_fold_point(lexer.OPERATOR, '{', '}')
lex:add_fold_point(lexer.COMMENT, '/*', '*/')

Copy link
Owner

@orbitalquark orbitalquark Sep 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this entire range is just a copy of the Go lexer, I would suggest replacing it with

local lex = lexer.new(..., {inherit = lexer.load('go')})

Comment on lines +61 to +64
'size_of', 'align_of', 'offset_of', 'type_of', 'type_info', 'type_info_of', 'typeid_of', 'identifier',
'cast', 'transmute', 'auto_cast', 'down_cast', 'union_cast', 'accumulator', 'offset_of_selector',
'offset_of_member', 'offset_of_by_string', 'swizzle', 'min', 'max', 'abs', 'clamp',
'is_package_imported', 'sqrt', 'valgrind_client_request'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally built-in functions like these would go into the built-in functions word list. Is there a particular reason they should be labeled as keywords?

'package', 'import_load', 'foreign_library', 'foreign_system_library', 'or_else', 'or_return',
'or_break','or_continue', 'where', 'expect', 'syscall',
-- keyword operator
'distinct', 'context',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

distinct appears more related to types than keywords (kind of like your storage type section). What do you think about moving it to the types word list?

'package', 'import_load', 'foreign_library', 'foreign_system_library', 'or_else', 'or_return',
'or_break','or_continue', 'where', 'expect', 'syscall',
-- keyword operator
'distinct', 'context',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context seems more like a built-in variable than a keyword. We could probably modify the 'constant' rule to add an option for built-in variables and add this to its list. Something like:

lex:modify_rule('constant', lex:get_rule('constant') + lex:word_match(lexer.VARIABLE_BUILTIN))

lex:set_word_list(lexer.VARIABLE_BUILTIN, 'context')

Does this sound reasonable?

Comment on lines +71 to +74
'i8', 'i16', 'i32', 'i64', 'i128', 'int', 'u8', 'u32', 'u64', 'u128', 'uint', 'uintptr',
'f16', 'f32', 'f64', 'complex32', 'complex64', 'complex128', 'bool', 'b8', 'b16', 'b32', 'b64',
'string', 'rune', 'rawptr', 'any', 'byte', 'cstring', 'complex', 'quaternion', 'real', 'imag',
'jmag', 'kmag', 'conj',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://pkg.odin-lang.org/base/builtin/ there appear to be more types. Are they worth adding here?

'is_package_imported', 'sqrt', 'valgrind_client_request'
})

lex:set_word_list(lexer.CONSTANT_BUILTIN, 'true false nil iota')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://pkg.odin-lang.org/base/builtin/ there are more constants. Are they worth adding?

Comment on lines +83 to +88
'thread_local', 'test', 'static', 'require_target_feature', 'require_results', 'require', 'private',
'optimization_mode', 'objc_type', 'objc_name', 'objc_is_class_method', 'objc_class',
'no_instrumentation', 'linkage', 'link_prefix', 'link_name', 'instrumentation_enter',
'instrumentation_exit', 'init', 'fini', 'extra_linker_flags', 'disabled', 'entry_point_only',
'enable_target_feature', 'enable_target_features', 'deprecated', 'deferred_out', 'deferred_in_out',
'deferred_in', 'builtin', 'cold', 'default_calling_convention'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These do not feel like functions to me. We could extend the lexer:modify_rule() I proposed earlier to also include a word list for these, like lexer.ATTRIBUTE. For example:

lex:modify_rule('constant', lex:get_rule('constant') +
  lex:word_match(lexer.VARIABLE_BUILTIN) +
  lex:word_match(lexer.ATTRIBUTE)

[...]

lex:set_word_list(lexer.ATTRIBUTE, { ... })

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanos for reviewing! I may have some spare time later in the week to include these suggestions. I'm happy for you to go ahead and make the changes if you beat me to it :-)

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

Successfully merging this pull request may close these issues.

2 participants