diff --git a/CHANGELOG.md b/CHANGELOG.md index c2ba40c..d5f5971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### 0.11.1 +- (Bugfix) - Helix themes now properly inherit from parent names when not defined (that is, if `ui.x.y` isn't defined but `ui.x` is, `ui.x.y` copies `ui.x`.) (Thanks @guilhermeprokisch for catching this one.) +- (Bugfix) - example terminal highlighter now works properly. +- (Bugfix) - updated Rust and Ada highlighting queries to behave properly. + ### 0.11.0 - (Improvement, **breaking**) - the `Theme` API has been rebuilt to work with [Helix editor themes](https://docs.helix-editor.com/themes.html#modifiers) instead of the previous bespoke implementation. - The `theme` module has been hoisted out of the `formatter` module, and now lives at the crate root. diff --git a/build/languages.toml b/build/languages.toml index f690738..faabbdb 100644 --- a/build/languages.toml +++ b/build/languages.toml @@ -5,7 +5,6 @@ helix_sum = "beb5afc" name = "ada" repo = "https://github.com/briot/tree-sitter-ada" hash = "e8e2515" -helix_override = true [[languages]] name = "asm" @@ -473,6 +472,7 @@ name = "rust" repo = "https://github.com/tree-sitter/tree-sitter-rust" hash = "6b7d1fc" aliases = ["rs"] +helix_override = true [[languages]] name = "scala" diff --git a/examples/terminal_highlight.rs b/examples/terminal_highlight.rs index 4848fd3..b2cb57f 100644 --- a/examples/terminal_highlight.rs +++ b/examples/terminal_highlight.rs @@ -40,12 +40,12 @@ fn main() { // Create the Terminal formatter with both theme and stream let formatter = Terminal::new(theme, stream); - for line in source.lines() { - highlighter - .highlight_to_writer(language, &formatter, line, &mut io::stdout()) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?; - println!(); - } + highlighter.highlight_to_writer( + language, + &formatter, + &source, + &mut io::sink() + ); println!(); diff --git a/languages/ada/queries/highlights.scm b/languages/ada/queries/highlights.scm index a350d31..643fbd6 100644 --- a/languages/ada/queries/highlights.scm +++ b/languages/ada/queries/highlights.scm @@ -26,7 +26,6 @@ "interface" "is" "limited" - "null" "of" "others" "out" @@ -40,11 +39,14 @@ "until" "when" ] @keyword +[ + "null" +] @constant.builtin [ "aliased" "constant" "renames" -] @storageclass +] @keyword.storage [ "mod" "new" @@ -52,11 +54,11 @@ "record" "subtype" "type" -] @keyword.type +] @type.builtin [ "with" "use" -] @include +] @keyword.control.import [ "body" "function" @@ -71,7 +73,7 @@ "not" "or" "xor" -] @keyword.operator +] @operator [ "while" "loop" @@ -79,10 +81,10 @@ "parallel" "reverse" "some" -] @repeat +] @kewyord.control.repeat [ "return" -] @keyword.return +] @keyword.control.return [ "case" "if" @@ -90,70 +92,70 @@ "then" "elsif" "select" -] @conditional +] @keyword.control.conditional [ "exception" "raise" -] @exception -(comment) @comment @spell -(string_literal) @string +] @keyword.control.exception +(comment) @comment +(string_literal) @string (character_literal) @string -(numeric_literal) @number +(numeric_literal) @constant.numeric ;; Highlight the name of subprograms -(procedure_specification name: (_) @function) -(function_specification name: (_) @function) -(package_declaration name: (_) @function) -(package_body name: (_) @function) -(generic_instantiation name: (_) @function) -(entry_declaration . (identifier) @function) +(procedure_specification name: (_) @function.builtin) +(function_specification name: (_) @function.builtin) +(package_declaration name: (_) @function.builtin) +(package_body name: (_) @function.builtin) +(generic_instantiation name: (_) @function.builtin) +(entry_declaration . (identifier) @function.builtin) ;; Some keywords should take different categories depending on the context -(use_clause "use" @include "type" @include) -(with_clause "private" @include) -(with_clause "limited" @include) +(use_clause "use" @keyword.control.import "type" @keyword.control.import) +(with_clause "private" @keyword.control.import) +(with_clause "limited" @keyword.control.import) (use_clause (_) @namespace) (with_clause (_) @namespace) -(loop_statement "end" @keyword.repeat) -(if_statement "end" @conditional) -(loop_parameter_specification "in" @keyword.repeat) -(loop_parameter_specification "in" @keyword.repeat) -(iterator_specification ["in" "of"] @keyword.repeat) -(range_attribute_designator "range" @keyword.repeat) +(loop_statement "end" @keyword.control.repeat) +(if_statement "end" @keyword.control.conditional) +(loop_parameter_specification "in" @keyword.control.repeat) +(loop_parameter_specification "in" @keyword.control.repeat) +(iterator_specification ["in" "of"] @keyword.control.repeat) +(range_attribute_designator "range" @keyword.control.repeat) -(raise_statement "with" @exception) +(raise_statement "with" @keyword.control.exception) -(gnatprep_declarative_if_statement) @preproc -(gnatprep_if_statement) @preproc -(gnatprep_identifier) @preproc +(gnatprep_declarative_if_statement) @keyword.directive +(gnatprep_if_statement) @keyword.directive +(gnatprep_identifier) @keyword.directive (subprogram_declaration "is" @keyword.function "abstract" @keyword.function) (aspect_specification "with" @keyword.function) -(full_type_declaration "is" @keyword.type) -(subtype_declaration "is" @keyword.type) -(record_definition "end" @keyword.type) -(full_type_declaration (_ "access" @keyword.type)) -(array_type_definition "array" @keyword.type "of" @keyword.type) -(access_to_object_definition "access" @keyword.type) -(access_to_object_definition "access" @keyword.type +(full_type_declaration "is" @type.builtin) +(subtype_declaration "is" @type.builtin) +(record_definition "end" @type.builtin) +(full_type_declaration (_ "access" @type.builtin)) +(array_type_definition "array" @type.builtin "of" @type.builtin) +(access_to_object_definition "access" @type.builtin) +(access_to_object_definition "access" @type.builtin [ - (general_access_modifier "constant" @keyword.type) - (general_access_modifier "all" @keyword.type) + (general_access_modifier "constant" @type.builtin) + (general_access_modifier "all" @type.builtin) ] ) -(range_constraint "range" @keyword.type) -(signed_integer_type_definition "range" @keyword.type) -(index_subtype_definition "range" @keyword.type) -(record_type_definition "abstract" @keyword.type) -(record_type_definition "tagged" @keyword.type) -(record_type_definition "limited" @keyword.type) -(record_type_definition (record_definition "null" @keyword.type)) -(private_type_declaration "is" @keyword.type "private" @keyword.type) -(private_type_declaration "tagged" @keyword.type) -(private_type_declaration "limited" @keyword.type) -(task_type_declaration "task" @keyword.type "is" @keyword.type) +(range_constraint "range" @type.builtin) +(signed_integer_type_definition "range" @type.builtin) +(index_subtype_definition "range" @type.builtin) +(record_type_definition "abstract" @type.builtin) +(record_type_definition "tagged" @type.builtin) +(record_type_definition "limited" @type.builtin) +(record_type_definition (record_definition "null" @type.builtin)) +(private_type_declaration "is" @type.builtin "private" @type.builtin) +(private_type_declaration "tagged" @type.builtin) +(private_type_declaration "limited" @type.builtin) +(task_type_declaration "task" @type.builtin "is" @type.builtin) ;; Gray the body of expression functions (expression_function_declaration @@ -164,33 +166,11 @@ (subprogram_declaration (aspect_specification) @attribute) ;; Highlight full subprogram specifications -;(subprogram_body -; [ -; (procedure_specification) -; (function_specification) -; ] @function.spec -;) - -((comment) @comment.documentation - . [ - (entry_declaration) - (subprogram_declaration) - (parameter_specification) - ]) - -(compilation_unit - . (comment) @comment.documentation) - -(component_list - (component_declaration) - . (comment) @comment.documentation) - -(enumeration_type_definition - (identifier) - . (comment) @comment.documentation) +; (subprogram_body +; [ +; (procedure_specification) +; (function_specification) +; ] @function.builtin.spec +; ) -;; Highlight errors in red. This is not very useful in practice, as text will -;; be highlighted as user types, and the error could be elsewhere in the code. -;; This also requires defining :hi @error guifg=Red for instance. -(ERROR) @error diff --git a/languages/ada/queries/locals.scm b/languages/ada/queries/locals.scm index eda50c6..e532a2f 100644 --- a/languages/ada/queries/locals.scm +++ b/languages/ada/queries/locals.scm @@ -1,33 +1,32 @@ -;; Better highlighting by referencing to the definition, for variable -;; references. However, this is not yet supported by neovim +;; Better highlighting by referencing to the definition, for variable references. ;; See https://tree-sitter.github.io/tree-sitter/syntax-highlighting#local-variables -(compilation) @scope -(package_declaration) @scope -(package_body) @scope -(subprogram_declaration) @scope -(subprogram_body) @scope -(block_statement) @scope +(compilation) @local.scope +(package_declaration) @local.scope +(package_body) @local.scope +(subprogram_declaration) @local.scope +(subprogram_body) @local.scope +(block_statement) @local.scope -(with_clause (_) @definition.import) -(procedure_specification name: (_) @definition.function) -(function_specification name: (_) @definition.function) -(package_declaration name: (_) @definition.var) -(package_body name: (_) @definition.var) -(generic_instantiation . name: (_) @definition.var) -(component_declaration . (identifier) @definition.var) -(exception_declaration . (identifier) @definition.var) -(formal_object_declaration . (identifier) @definition.var) -(object_declaration . (identifier) @definition.var) -(parameter_specification . (identifier) @definition.var) -(full_type_declaration . (identifier) @definition.type) -(private_type_declaration . (identifier) @definition.type) -(private_extension_declaration . (identifier) @definition.type) -(incomplete_type_declaration . (identifier) @definition.type) -(protected_type_declaration . (identifier) @definition.type) -(formal_complete_type_declaration . (identifier) @definition.type) -(formal_incomplete_type_declaration . (identifier) @definition.type) -(task_type_declaration . (identifier) @definition.type) -(subtype_declaration . (identifier) @definition.type) +(with_clause (_) @local.definition) +(procedure_specification name: (_) @local.definition) +(function_specification name: (_) @local.definition) +(package_declaration name: (_) @local.definition) +(package_body name: (_) @local.definition) +(generic_instantiation . name: (_) @local.definition) +(component_declaration . (identifier) @local.definition) +(exception_declaration . (identifier) @local.definition) +(formal_object_declaration . (identifier) @local.definition) +(object_declaration . (identifier) @local.definition) +(parameter_specification . (identifier) @local.definition) +(full_type_declaration . (identifier) @local.definition) +(private_type_declaration . (identifier) @local.definition) +(private_extension_declaration . (identifier) @local.definition) +(incomplete_type_declaration . (identifier) @local.definition) +(protected_type_declaration . (identifier) @local.definition) +(formal_complete_type_declaration . (identifier) @local.definition) +(formal_incomplete_type_declaration . (identifier) @local.definition) +(task_type_declaration . (identifier) @local.definition) +(subtype_declaration . (identifier) @local.definition) -(identifier) @reference +(identifier) @local.reference diff --git a/languages/rust/queries/highlights.scm b/languages/rust/queries/highlights.scm index 7997c5e..8bfa388 100644 --- a/languages/rust/queries/highlights.scm +++ b/languages/rust/queries/highlights.scm @@ -1,410 +1,159 @@ -; ------- -; Tree-Sitter doesn't allow overrides in regards to captures, -; though it is possible to affect the child node of a captured -; node. Thus, the approach here is to flip the order so that -; overrides are unnecessary. -; ------- +; Identifiers -; ------- -; Types -; ------- - -(type_parameters - (type_identifier) @type.parameter) -(constrained_type_parameter - left: (type_identifier) @type.parameter) -(optional_type_parameter - name: (type_identifier) @type.parameter) - -; --- -; Primitives -; --- - -(escape_sequence) @constant.character.escape +(type_identifier) @type (primitive_type) @type.builtin -(boolean_literal) @constant.builtin.boolean -(integer_literal) @constant.numeric.integer -(float_literal) @constant.numeric.float -(char_literal) @constant.character -[ - (string_literal) - (raw_string_literal) -] @string -[ - (line_comment) - (block_comment) -] @comment - -; --- -; Extraneous -; --- - -(self) @variable.builtin -(enum_variant (identifier) @type.enum.variant) - -(field_initializer - (field_identifier) @variable.other.member) -(shorthand_field_initializer - (identifier) @variable.other.member) -(shorthand_field_identifier) @variable.other.member - -(lifetime - "'" @label - (identifier) @label) -(label - "'" @label - (identifier) @label) - -; --- -; Punctuation -; --- - -[ - "::" - "." - ";" - "," -] @punctuation.delimiter - -[ - "(" - ")" - "[" - "]" - "{" - "}" - "#" -] @punctuation.bracket -(type_arguments - [ - "<" - ">" - ] @punctuation.bracket) -(type_parameters - [ - "<" - ">" - ] @punctuation.bracket) -(closure_parameters - "|" @punctuation.bracket) - -; --- -; Variables -; --- - -(let_declaration - pattern: [ - ((identifier) @variable) - ((tuple_pattern - (identifier) @variable)) - ]) - -; It needs to be anonymous to not conflict with `call_expression` further below. -(_ - value: (field_expression - value: (identifier)? @variable - field: (field_identifier) @variable.other.member)) - -(parameter - pattern: (identifier) @variable.parameter) -(closure_parameters - (identifier) @variable.parameter) - -; ------- -; Keywords -; ------- - -(for_expression - "for" @keyword.control.repeat) -((identifier) @keyword.control - (#match? @keyword.control "^yield$")) - -"in" @keyword.control - -[ - "match" - "if" - "else" - "try" -] @keyword.control.conditional - -[ - "while" - "loop" -] @keyword.control.repeat - -[ - "break" - "continue" - "return" - "await" -] @keyword.control.return - -"use" @keyword.control.import -(mod_item "mod" @keyword.control.import !body) -(use_as_clause "as" @keyword.control.import) - -(type_cast_expression "as" @keyword.operator) - -[ - (crate) - (super) - "as" - "pub" - "mod" - "extern" - - "impl" - "where" - "trait" - "for" - - "default" - "async" -] @keyword - -[ - "struct" - "enum" - "union" - "type" -] @keyword.storage.type - -"let" @keyword.storage -"fn" @keyword.function -"unsafe" @keyword.special -"macro_rules!" @function.macro - -(mutable_specifier) @keyword.storage.modifier.mut +(field_identifier) @property -(reference_type "&" @keyword.storage.modifier.ref) -(self_parameter "&" @keyword.storage.modifier.ref) - -[ - "static" - "const" - "ref" - "move" - "dyn" -] @keyword.storage.modifier - -; TODO: variable.mut to highlight mutable identifiers via locals.scm - -; ------- -; Constructors -; ------- -; TODO: this is largely guesswork, remove it once we get actual info from locals.scm or r-a - -(struct_expression - name: (type_identifier) @constructor) - -(tuple_struct_pattern - type: [ - (identifier) @constructor - (scoped_identifier - name: (identifier) @constructor) - ]) -(struct_pattern - type: [ - ((type_identifier) @constructor) - (scoped_type_identifier - name: (type_identifier) @constructor) - ]) -(match_pattern - ((identifier) @constructor) (#match? @constructor "^[A-Z]")) -(or_pattern - ((identifier) @constructor) - ((identifier) @constructor) - (#match? @constructor "^[A-Z]")) - -; ------- -; Guess Other Types -; ------- +; Identifier conventions +; Assume all-caps names are constants ((identifier) @constant - (#match? @constant "^[A-Z][A-Z\\d_]*$")) + (#match? @constant "^[A-Z][A-Z\\d_]+$'")) + +; Assume uppercase names are enum constructors +((identifier) @constructor + (#match? @constructor "^[A-Z]")) + +; Assume that uppercase names in paths are types +((scoped_identifier + path: (identifier) @type) + (#match? @type "^[A-Z]")) +((scoped_identifier + path: (scoped_identifier + name: (identifier) @type)) + (#match? @type "^[A-Z]")) +((scoped_type_identifier + path: (identifier) @type) + (#match? @type "^[A-Z]")) +((scoped_type_identifier + path: (scoped_identifier + name: (identifier) @type)) + (#match? @type "^[A-Z]")) + +; Assume all qualified names in struct patterns are enum constructors. (They're +; either that, or struct names; highlighting both as constructors seems to be +; the less glaring choice of error, visually.) +(struct_pattern + type: (scoped_type_identifier + name: (type_identifier) @constructor)) -; --- -; PascalCase identifiers in call_expressions (e.g. `Ok()`) -; are assumed to be enum constructors. -; --- +; Function calls (call_expression - function: [ - ((identifier) @constructor - (#match? @constructor "^[A-Z]")) - (scoped_identifier - name: ((identifier) @constructor - (#match? @constructor "^[A-Z]"))) - ]) - -; --- -; PascalCase identifiers under a path which is also PascalCase -; are assumed to be constructors if they have methods or fields. -; --- - -(field_expression - value: (scoped_identifier - path: [ - (identifier) @type - (scoped_identifier - name: (identifier) @type) - ] - name: (identifier) @constructor - (#match? @type "^[A-Z]") - (#match? @constructor "^[A-Z]"))) - -; --- -; Other PascalCase identifiers are assumed to be structs. -; --- - -((identifier) @type - (#match? @type "^[A-Z]")) - -; ------- -; Functions -; ------- - + function: (identifier) @function) (call_expression - function: [ - ((identifier) @function) - (scoped_identifier - name: (identifier) @function) - (field_expression - field: (field_identifier) @function) - ]) -(generic_function - function: [ - ((identifier) @function) - (scoped_identifier - name: (identifier) @function) - (field_expression - field: (field_identifier) @function.method) - ]) - -(function_item - name: (identifier) @function) - -(function_signature_item - name: (identifier) @function) - -; --- -; Macros -; --- - -(attribute - (identifier) @special - arguments: (token_tree (identifier) @type) - (#eq? @special "derive") -) - -(attribute - (identifier) @function.macro) -(attribute - [ - (identifier) @function.macro - (scoped_identifier - name: (identifier) @function.macro) - ] - (token_tree (identifier) @function.macro)?) + function: (field_expression + field: (field_identifier) @function.method)) +(call_expression + function: (scoped_identifier + "::" + name: (identifier) @function)) -(inner_attribute_item) @attribute +(generic_function + function: (identifier) @function) +(generic_function + function: (scoped_identifier + name: (identifier) @function)) +(generic_function + function: (field_expression + field: (field_identifier) @function.method)) -(macro_definition - name: (identifier) @function.macro) (macro_invocation - macro: [ - ((identifier) @function.macro) - (scoped_identifier - name: (identifier) @function.macro) - ] + macro: (identifier) @function.macro "!" @function.macro) -(metavariable) @variable.parameter -(fragment_specifier) @type +; Function definitions + +(function_item (identifier) @function) +(function_signature_item (identifier) @function) -; ------- -; Operators -; ------- +(line_comment) @comment +(block_comment) @comment -[ - "*" - "'" - "->" - "=>" - "<=" - "=" - "==" - "!" - "!=" - "%" - "%=" - "&" - "&=" - "&&" - "|" - "|=" - "||" - "^" - "^=" - "*" - "*=" - "-" - "-=" - "+" - "+=" - "/" - "/=" - ">" - "<" - ">=" - ">>" - "<<" - ">>=" - "<<=" - "@" - ".." - "..=" - "'" -] @operator +(line_comment (doc_comment)) @comment.documentation +(block_comment (doc_comment)) @comment.documentation -; ------- -; Paths -; ------- +"(" @punctuation.bracket +")" @punctuation.bracket +"[" @punctuation.bracket +"]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket + +(type_arguments + "<" @punctuation.bracket + ">" @punctuation.bracket) +(type_parameters + "<" @punctuation.bracket + ">" @punctuation.bracket) + +"::" @punctuation.delimiter +":" @punctuation.delimiter +"." @punctuation.delimiter +"," @punctuation.delimiter +";" @punctuation.delimiter + +(parameter (identifier) @variable.parameter) + +(lifetime (identifier) @label) + +"as" @keyword +"async" @keyword +"await" @keyword +"break" @keyword +"const" @keyword +"continue" @keyword +"default" @keyword +"dyn" @keyword +"else" @keyword +"enum" @keyword +"extern" @keyword +"fn" @keyword +"for" @keyword +"if" @keyword +"impl" @keyword +"in" @keyword +"let" @keyword +"loop" @keyword +"macro_rules!" @keyword +"match" @keyword +"mod" @keyword +"move" @keyword +"pub" @keyword +"ref" @keyword +"return" @keyword +"static" @keyword +"struct" @keyword +"trait" @keyword +"type" @keyword +"union" @keyword +"unsafe" @keyword +"use" @keyword +"where" @keyword +"while" @keyword +"yield" @keyword +(crate) @keyword +(mutable_specifier) @keyword +(use_list (self) @keyword) +(scoped_use_list (self) @keyword) +(scoped_identifier (self) @keyword) +(super) @keyword -(use_declaration - argument: (identifier) @namespace) -(use_wildcard - (identifier) @namespace) -(extern_crate_declaration - name: (identifier) @namespace - alias: (identifier)? @namespace) -(mod_item - name: (identifier) @namespace) -(scoped_use_list - path: (identifier)? @namespace) -(use_list - (identifier) @namespace) -(use_as_clause - path: (identifier)? @namespace - alias: (identifier) @namespace) +(self) @variable.builtin -; --- -; Remaining Paths -; --- +(char_literal) @string +(string_literal) @string +(raw_string_literal) @string -(scoped_identifier - path: (identifier)? @namespace - name: (identifier) @namespace) -(scoped_type_identifier - path: (identifier) @namespace) +(boolean_literal) @constant.builtin +(integer_literal) @constant.builtin +(float_literal) @constant.builtin -; ------- -; Remaining Identifiers -; ------- +(escape_sequence) @escape -"?" @special +(attribute_item) @attribute +(inner_attribute_item) @attribute -(type_identifier) @type -(identifier) @variable -(field_identifier) @variable.other.member +"*" @operator +"&" @operator +"'" @operator diff --git a/languages/rust/queries/injections.scm b/languages/rust/queries/injections.scm index b05b9d9..6035d41 100644 --- a/languages/rust/queries/injections.scm +++ b/languages/rust/queries/injections.scm @@ -1,30 +1,3 @@ -([(line_comment) (block_comment)] @injection.content - (#set! injection.language "comment")) - -((macro_invocation - macro: - [ - (scoped_identifier - name: (_) @_macro_name) - (identifier) @_macro_name - ] - (token_tree) @injection.content) - (#eq? @_macro_name "html") - (#set! injection.language "html") - (#set! injection.include-children)) - -((macro_invocation - macro: - [ - (scoped_identifier - name: (_) @_macro_name) - (identifier) @_macro_name - ] - (token_tree) @injection.content) - (#eq? @_macro_name "slint") - (#set! injection.language "slint") - (#set! injection.include-children)) - ((macro_invocation (token_tree) @injection.content) (#set! injection.language "rust") @@ -34,44 +7,3 @@ (token_tree) @injection.content) (#set! injection.language "rust") (#set! injection.include-children)) - -(call_expression - function: (scoped_identifier - path: (identifier) @_regex (#eq? @_regex "Regex") - name: (identifier) @_new (#eq? @_new "new")) - arguments: (arguments (raw_string_literal) @injection.content) - (#set! injection.language "regex")) - -(call_expression - function: (scoped_identifier - path: (scoped_identifier (identifier) @_regex (#eq? @_regex "Regex") .) - name: (identifier) @_new (#eq? @_new "new")) - arguments: (arguments (raw_string_literal) @injection.content) - (#set! injection.language "regex")) - -; Highlight SQL in `sqlx::query!()`, `sqlx::query_scalar!()`, and `sqlx::query_scalar_unchecked!()` -(macro_invocation - macro: (scoped_identifier - path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query (#match? @_query "^query(_scalar|_scalar_unchecked)?$")) - (token_tree - ; Only the first argument is SQL - . - [(string_literal) (raw_string_literal)] @injection.content - ) - (#set! injection.language "sql")) - -; Highlight SQL in `sqlx::query_as!()` and `sqlx::query_as_unchecked!()` -(macro_invocation - macro: (scoped_identifier - path: (identifier) @_sqlx (#eq? @_sqlx "sqlx") - name: (identifier) @_query_as (#match? @_query_as "^query_as(_unchecked)?$")) - (token_tree - ; Only the second argument is SQL - . - ; Allow anything as the first argument in case the user has lower case type - ; names for some reason - (_) - [(string_literal) (raw_string_literal)] @injection.content - ) - (#set! injection.language "sql")) diff --git a/languages/rust/queries/locals.scm b/languages/rust/queries/locals.scm deleted file mode 100644 index cb75d15..0000000 --- a/languages/rust/queries/locals.scm +++ /dev/null @@ -1,31 +0,0 @@ -; Scopes - -[ - (function_item) - (struct_item) - (enum_item) - (union_item) - (type_item) - (trait_item) - (impl_item) - (closure_expression) - (block) -] @local.scope - -; Definitions - -(parameter - (identifier) @local.definition) - -(type_parameters - (type_identifier) @local.definition) -(constrained_type_parameter - left: (type_identifier) @local.definition) -(optional_type_parameter - name: (type_identifier) @local.definition) - -(closure_parameters (identifier) @local.definition) - -; References -(identifier) @local.reference -(type_identifier) @local.reference diff --git a/languages/rust/queries/tags.scm b/languages/rust/queries/tags.scm new file mode 100644 index 0000000..e22f2b2 --- /dev/null +++ b/languages/rust/queries/tags.scm @@ -0,0 +1,60 @@ +; ADT definitions + +(struct_item + name: (type_identifier) @name) @definition.class + +(enum_item + name: (type_identifier) @name) @definition.class + +(union_item + name: (type_identifier) @name) @definition.class + +; type aliases + +(type_item + name: (type_identifier) @name) @definition.class + +; method definitions + +(declaration_list + (function_item + name: (identifier) @name)) @definition.method + +; function definitions + +(function_item + name: (identifier) @name) @definition.function + +; trait definitions +(trait_item + name: (type_identifier) @name) @definition.interface + +; module definitions +(mod_item + name: (identifier) @name) @definition.module + +; macro definitions + +(macro_definition + name: (identifier) @name) @definition.macro + +; references + +(call_expression + function: (identifier) @name) @reference.call + +(call_expression + function: (field_expression + field: (field_identifier) @name)) @reference.call + +(macro_invocation + macro: (identifier) @name) @reference.call + +; implementations + +(impl_item + trait: (type_identifier) @name) @reference.implementation + +(impl_item + type: (type_identifier) @name + !trait) @reference.implementation diff --git a/src/languages.rs b/src/languages.rs index 1c9a768..0c9634c 100644 --- a/src/languages.rs +++ b/src/languages.rs @@ -2933,7 +2933,7 @@ pub mod rust { pub const INJECTIONS_QUERY: &str = include_str!( "../languages/rust/queries/injections.scm" ); - pub const LOCALS_QUERY: &str = include_str!("../languages/rust/queries/locals.scm"); + pub const LOCALS_QUERY: &str = ""; #[cfg(test)] mod tests { use super::*; diff --git a/src/theme/mod.rs b/src/theme/mod.rs index ed63981..c9ca8b9 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -351,6 +351,27 @@ impl Theme { None => Color::BLACK }; + for name in HIGHLIGHT_NAMES { + if styles.contains_key(*name) { + continue; + } + + let mut p = name.to_string(); + + while let Some((ancestor, _)) = p.rsplit_once('.') { + if let Some(s) = styles.get(ancestor) { + styles.insert( + name.to_string(), + s.clone() + ); + + break; + } + + p = ancestor.to_string(); + } + } + Ok(Self { styles, fg, bg }) } } diff --git a/src/theme/vendored/data/github_dark.toml b/src/theme/vendored/data/github_dark.toml index e980321..85cec79 100644 --- a/src/theme/vendored/data/github_dark.toml +++ b/src/theme/vendored/data/github_dark.toml @@ -56,7 +56,7 @@ label = "scale.red.3" "ui.window" = { fg = "border.default" } "ui.help" = { fg = "fg.default", bg = "canvas.overlay" } -"ui.text" = { fg = "fg.muted" } +"ui.text" = { fg = "fg.default" } "ui.text.focus" = { fg = "fg.default" } "ui.text.inactive" = "fg.subtle" "ui.virtual" = { fg = "scale.gray.6" } diff --git a/src/theme/vendored/mod.rs b/src/theme/vendored/mod.rs index a3d3481..3b6645e 100644 --- a/src/theme/vendored/mod.rs +++ b/src/theme/vendored/mod.rs @@ -1,4 +1,7 @@ //! A collection of theme definitions vendored from the Helix editor project. View previews [here](https://github.com/helix-editor/helix/wiki/Themes). +//! +//! Note that Helix is first and foremost a terminal text editor, and these themes are included as-is; you may see results slightly different from what you expect +//! depending on your output format. #![allow(dead_code)] pub const ACME: &str = include_str!("./data/acme.toml"); pub const ADWAITA_DARK: &str = include_str!("./data/adwaita-dark.toml"); diff --git a/tests/snippets.html b/tests/snippets.html index 280790a..e6391a0 100644 --- a/tests/snippets.html +++ b/tests/snippets.html @@ -1,18 +1,18 @@
-with Ada.Text_IO; use Ada.Text_IO; +with Ada.Text_IO; use Ada.Text_IO; procedure Fizzbuzz is begin - for I in 1..100 loop - if I mod 15 = 0 then + for I in 1..100 loop + if I mod 15 = 0 then Put_Line("FizzBuzz"); - elsif I mod 5 = 0 then + elsif I mod 5 = 0 then Put_Line("Buzz"); - elsif I mod 3 = 0 then + elsif I mod 3 = 0 then Put_Line("Fizz"); - else + else Put_Line(Integer'Image(I)); - end if; + end if; end loop; end Fizzbuzz;
@@ -70,9 +70,9 @@Bicep
output helloWorld string = '${hello} ${yourName}'Blueprint
-using Gtk 4.0; +using Gtk 4.0; -template MyAppWindow : Gtk.ApplicationWindow { +template MyAppWindow : Gtk.ApplicationWindow { title: _("My App Title"); [titlebar] @@ -89,48 +89,48 @@C
int main(void) { - for (int i = 1; i <= 100; i++) + for (int i = 1; i <= 100; i++) { - if (!(i % 15)) + if (!(i % 15)) printf("FizzBuzz"); - else if (!(i % 3)) + else if (!(i % 3)) printf("Fizz"); - else if (!(i % 5)) + else if (!(i % 5)) printf("Buzz"); - else + else printf("%d", i); printf("\n"); } - return EXIT_SUCCESS; + return EXIT_SUCCESS; }Capnp
-@0xdbb9ad1f14bf0b36; # unique file ID, generated by `capnp id` +@0xdbb9ad1f14bf0b36; # unique file ID, generated by `capnp id` -struct Person { - name @0 :Text; - birthdate @3 :Date; +struct Person { + name @0 :Text; + birthdate @3 :Date; - email @1 :Text; - phones @2 :List(PhoneNumber); + email @1 :Text; + phones @2 :List(PhoneNumber); - struct PhoneNumber { - number @0 :Text; - type @1 :Type; + struct PhoneNumber { + number @0 :Text; + type @1 :Type; - enum Type { - mobile @0; - home @1; - work @2; + enum Type { + mobile @0; + home @1; + work @2; } } } -struct Date { - year @0 :Int16; - month @1 :UInt8; - day @2 :UInt8; +struct Date { + year @0 :Int16; + month @1 :UInt8; + day @2 :UInt8; }Clojure
(defn fizzbuzz [start finish] @@ -139,7 +139,7 @@Clojure
(zero? (mod n 15)) "FizzBuzz" (zero? (mod n 3)) "Fizz" (zero? (mod n 5)) "Buzz" - :else n)) + :else n)) (range start finish))) (fizzbuzz 1 100)CSharp
@@ -179,18 +179,18 @@Cpp
int main () { - for (int i = 1; i <= 100; i++) { - if ((i % 15) == 0) + for (int i = 1; i <= 100; i++) { + if ((i % 15) == 0) std::cout << "FizzBuzz\n"; - else if ((i % 3) == 0) + else if ((i % 3) == 0) std::cout << "Fizz\n"; - else if ((i % 5) == 0) + else if ((i % 5) == 0) std::cout << "Buzz\n"; - else + else std::cout << i << "\n"; } - return 0; + return 0; }Css
body { @@ -199,7 +199,7 @@Css
h1 { color: #C26356; - font-size: 30px; + font-size: 30px; font-family: Menlo, Monaco, fixed-width; } @@ -229,16 +229,16 @@Cue
3, ]D
-import std.stdio, std.algorithm, std.conv; +import std.stdio, std.algorithm, std.conv; /// With if-else. void fizzBuzz(in uint n) { - foreach (immutable i; 1 .. n + 1) - if (!(i % 15)) + foreach (immutable i; 1 .. n + 1) + if (!(i % 15)) "FizzBuzz".writeln; - else if (!(i % 3)) + else if (!(i % 3)) "Fizz".writeln; - else if (!(i % 5)) + else if (!(i % 5)) "Buzz".writeln; else i.writeln; @@ -246,15 +246,15 @@D
/// With switch case. void fizzBuzzSwitch(in uint n) { - foreach (immutable i; 1 .. n + 1) - switch (i % 15) { - case 0: + foreach (immutable i; 1 .. n + 1) + switch (i % 15) { + case 0: "FizzBuzz".writeln; break; - case 3, 6, 9, 12: + case 3, 6, 9, 12: "Fizz".writeln; break; - case 5, 10: + case 5, 10: "Buzz".writeln; break; default: @@ -263,24 +263,24 @@D
} void fizzBuzzSwitch2(in uint n) { - foreach (immutable i; 1 .. n + 1) - (i % 15).predSwitch( - 0, "FizzBuzz", - 3, "Fizz", - 5, "Buzz", - 6, "Fizz", - 9, "Fizz", - 10, "Buzz", - 12, "Fizz", + foreach (immutable i; 1 .. n + 1) + (i % 15).predSwitch( + 0, "FizzBuzz", + 3, "Fizz", + 5, "Buzz", + 6, "Fizz", + 9, "Fizz", + 10, "Buzz", + 12, "Fizz", /*else*/ i.text).writeln; } void main() { - 100.fizzBuzz; + 100.fizzBuzz; writeln; - 100.fizzBuzzSwitch; + 100.fizzBuzzSwitch; writeln; - 100.fizzBuzzSwitch2; + 100.fizzBuzzSwitch2; }Dart
main() { @@ -335,17 +335,17 @@Elisp
(dotimes (i 101) (message "%s" (fizzbuzz i)))Elixir
-Enum.each 1..100, fn x -> - IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do - { true, true } -> "FizzBuzz" - { true, false } -> "Fizz" - { false, true } -> "Buzz" - { false, false } -> x +Enum.each 1..100, fn x -> + IO.puts(case { rem(x,3) == 0, rem(x,5) == 0 } do + { true, true } -> "FizzBuzz" + { true, false } -> "Fizz" + { false, true } -> "Buzz" + { false, false } -> x end) endElm
-import Html exposing (text) -import List exposing (map) +import Html exposing (text) +import List exposing (map) main = [1..100] |> map getWordForNum |> text @@ -424,14 +424,14 @@Gdscript
extends Node func _ready(): - for i in range(1, 101): - if i % 15 == 0: + for i in range(1, 101): + if i % 15 == 0: print("FizzBuzz") - elif i % 3 == 0: + elif i % 3 == 0: print("Fizz") - elif i % 5 == 0: + elif i % 5 == 0: print("Buzz") - else: + else: print(i) get_tree().quit()@@ -441,17 +441,17 @@Gleam
import gleam/iterator pub fn main() { - iterator.range(1, 101) + iterator.range(1, 101) |> iterator.map(to_fizzbuzz) |> iterator.map(io.println) |> iterator.run } fn to_fizzbuzz(n: Int) -> String { - case n % 3, n % 5 { - 0, 0 -> "FizzBuzz" - 0, _ -> "Fizz" - _, 0 -> "Buzz" + case n % 3, n % 5 { + 0, 0 -> "FizzBuzz" + 0, _ -> "Fizz" + _, 0 -> "Buzz" _, _ -> int.to_string(n) } }@@ -459,8 +459,8 @@Glsl
in vec3 fromPrevious; in uvec2 fromRange; -const int foo = 5; -const uvec2 range = uvec2(2, 5); +const int foo = 5; +const uvec2 range = uvec2(2, 5); uniform vec2 pairs; uniform sampler2d tex; @@ -473,7 +473,7 @@Glsl
value = range.x; // still dynamically uniform. value = range.y + fromRange.y; // not dynamically uniform; current contents come from a non-dynamically uniform source. value = 4; // dynamically uniform again. - if (fromPrevious.y < 3.14) + if (fromPrevious.y < 3.14) value = 12; value; // NOT dynamically uniform. Current contents depend on 'fromPrevious', an input variable. @@ -485,13 +485,13 @@Glsl
// It uses the same texture coordinate, thus getting the same texel every time. colors = texture(tex, fromPrevious.xy); // not dynamically uniform. - for(int i = range.x; i < range.y; ++i) + for(int i = range.x; i < range.y; ++i) { // loop initialized with, compared against, and incremented by dynamically uniform expressions. i; // Therefore, 'i' is dynamically uniform, even though it changes. } - for(int i = fromRange.x; i < fromRange.y; ++i) + for(int i = fromRange.x; i < fromRange.y; ++i) { i; // 'i' is not dynamically uniform; 'fromRange' is not dynamically uniform. } @@ -525,7 +525,7 @@Haskell
where f = (0 ==) . rem x -main :: IO () +main :: IO () main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]Hcl
terraform { @@ -610,16 +610,16 @@Java
public class FizzBuzz { // say it with me now, everyone // PUBLIC STATIC VOID MAIN STRI - - public static void main(String[] args) { + public static void main(String[] args) { for (int number = 1; number <= 100; number++) { if (number % 15 == 0) { - System.out.println("FizzBuzz"); + System.out.println("FizzBuzz"); } else if (number % 3 == 0) { - System.out.println("Fizz"); + System.out.println("Fizz"); } else if (number % 5 == 0) { - System.out.println("Buzz"); + System.out.println("Buzz"); } else { - System.out.println(number); + System.out.println(number); } } } @@ -631,7 +631,7 @@Javascript
output = ''; if (!(i % 3)) { output += 'Fizz'; } if (!(i % 5)) { output += 'Buzz'; } - console.log(output || i);//empty string is false, so we short-circuit + console.log(output || i);//empty string is false, so we short-circuit } };Json
@@ -701,9 +701,9 @@Kotlin
} }Latex
-\documentclass{minimal} -\usepackage{ifthen} -\usepackage{intcalc} +\documentclass{minimal} +\usepackage{ifthen} +\usepackage{intcalc} \newcounter{mycount} \newboolean{fizzOrBuzz} \newcommand\fizzBuzz[1]{% @@ -738,80 +738,80 @@Llvm
$"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = comdat any ;--- String constant defintions -@"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@" = linkonce_odr unnamed_addr constant [10 x i8] c"FizzBuzz\0A\00", comdat, align 1 -@"\01??_C@_05KEBFOHOF@Fizz?6?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"Fizz\0A\00", comdat, align 1 -@"\01??_C@_05JKJENPHA@Buzz?6?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"Buzz\0A\00", comdat, align 1 -@"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = linkonce_odr unnamed_addr constant [4 x i8] c"%d\0A\00", comdat, align 1 +@"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@" = linkonce_odr unnamed_addr constant [10 x i8] c"FizzBuzz\0A\00", comdat, align 1 +@"\01??_C@_05KEBFOHOF@Fizz?6?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"Fizz\0A\00", comdat, align 1 +@"\01??_C@_05JKJENPHA@Buzz?6?$AA@" = linkonce_odr unnamed_addr constant [6 x i8] c"Buzz\0A\00", comdat, align 1 +@"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@" = linkonce_odr unnamed_addr constant [4 x i8] c"%d\0A\00", comdat, align 1 ;--- The declaration for the external C printf function. declare i32 @printf(i8*, ...) ; Function Attrs: noinline nounwind optnone uwtable define i32 @main() #0 { - %1 = alloca i32, align 4 - store i32 1, i32* %1, align 4 + %1 = alloca i32, align 4 + store i32 1, i32* %1, align 4 ;--- It does not seem like this branch can be removed br label %loop ;--- while (i <= 100) loop: - %2 = load i32, i32* %1, align 4 - %3 = icmp sle i32 %2, 100 + %2 = load i32, i32* %1, align 4 + %3 = icmp sle i32 %2, 100 br i1 %3, label %divisible_15, label %finished ;--- if (i % 15 == 0) divisible_15: - %4 = load i32, i32* %1, align 4 - %5 = srem i32 %4, 15 - %6 = icmp eq i32 %5, 0 + %4 = load i32, i32* %1, align 4 + %5 = srem i32 %4, 15 + %6 = icmp eq i32 %5, 0 br i1 %6, label %print_fizzbuzz, label %divisible_3 ;--- Print 'FizzBuzz' print_fizzbuzz: - %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@", i32 0, i32 0)) + %7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @"\01??_C@_09NODAFEIA@FizzBuzz?6?$AA@", i32 0, i32 0)) br label %next ;--- if (i % 3 == 0) divisible_3: - %8 = load i32, i32* %1, align 4 - %9 = srem i32 %8, 3 - %10 = icmp eq i32 %9, 0 + %8 = load i32, i32* %1, align 4 + %9 = srem i32 %8, 3 + %10 = icmp eq i32 %9, 0 br i1 %10, label %print_fizz, label %divisible_5 ;--- Print 'Fizz' print_fizz: - %11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @"\01??_C@_05KEBFOHOF@Fizz?6?$AA@", i32 0, i32 0)) + %11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @"\01??_C@_05KEBFOHOF@Fizz?6?$AA@", i32 0, i32 0)) br label %next ;--- if (i % 5 == 0) divisible_5: - %12 = load i32, i32* %1, align 4 - %13 = srem i32 %12, 5 - %14 = icmp eq i32 %13, 0 + %12 = load i32, i32* %1, align 4 + %13 = srem i32 %12, 5 + %14 = icmp eq i32 %13, 0 br i1 %14, label %print_buzz, label %print_number ;--- Print 'Buzz' print_buzz: - %15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @"\01??_C@_05JKJENPHA@Buzz?6?$AA@", i32 0, i32 0)) + %15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @"\01??_C@_05JKJENPHA@Buzz?6?$AA@", i32 0, i32 0)) br label %next ;--- Print the number print_number: - %16 = load i32, i32* %1, align 4 - %17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@", i32 0, i32 0), i32 %16) + %16 = load i32, i32* %1, align 4 + %17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @"\01??_C@_03PMGGPEJJ@?$CFd?6?$AA@", i32 0, i32 0), i32 %16) ;--- It does not seem like this branch can be removed br label %next ;--- i = i + 1 next: - %18 = load i32, i32* %1, align 4 - %19 = add nsw i32 %18, 1 - store i32 %19, i32* %1, align 4 + %18 = load i32, i32* %1, align 4 + %19 = add nsw i32 %18, 1 + store i32 %19, i32* %1, align 4 br label %loop ;--- exit main finished: - ret i32 0 + ret i32 0 } attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } @@ -819,8 +819,8 @@Llvm
!llvm.module.flags = !{!0, !1} !llvm.ident = !{!2} -!0 = !{i32 1, !"wchar_size", i32 2} -!1 = !{i32 7, !"PIC Level", i32 2} +!0 = !{i32 1, !"wchar_size", i32 2} +!1 = !{i32 7, !"PIC Level", i32 2} !2 = !{!"clang version 6.0.1 (tags/RELEASE_601/final)"}Lua
for i = 1, 100 do @@ -845,32 +845,32 @@Make
define fb $1: -ifeq "$(call mod, $1, 15)" '0' +ifeq "$(call mod, $1, 15)" '0' @echo FizzBuzz -else ifeq "$(call mod, $1, 3)" '0' +else ifeq "$(call mod, $1, 3)" '0' @echo Fizz -else ifeq "$(call mod, $1, 5)" '0' +else ifeq "$(call mod, $1, 5)" '0' @echo Buzz -else +else @echo $1 -endif +endif endef -$(foreach _,${NUMS},$(eval $(call fb,$_))) +$(foreach _,${NUMS},$(eval $(call fb,$_))) .PHONY: fizzbuzz $(NUMS)Matlab
-for inum = 1:100 +for inum = 1:100 fizzbuzz = ''; - if mod(inum,3) == 0 + if mod(inum,3) == 0 fizzbuzz = [fizzbuzz 'Fizz']; end - if mod(inum,5) == 0 + if mod(inum,5) == 0 fizzbuzz = [fizzbuzz 'Buzz']; end - if isempty(fizzbuzz) + if isempty(fizzbuzz) disp(inum) - else + else disp(fizzbuzz) end end@@ -879,35 +879,35 @@Meson
src = ['source1.c', 'source2.c', 'source3.c'] executable('myexe', sources : src)Nix
-with (import <nixpkgs> { }).lib; +with (import <nixpkgs> { }).lib; with builtins; let - fizzbuzz = { x ? 1 }: + fizzbuzz = { x ? 1 }: '' - ${if (mod x 15 == 0) then + ${if (mod x 15 == 0) then "FizzBuzz" - else if (mod x 3 == 0) then + else if (mod x 3 == 0) then "Fizz" - else if (mod x 5 == 0) then + else if (mod x 5 == 0) then "Buzz" - else + else (toString x)} - '' + (if (x < 100) then - fizzbuzz { x = x + 1; } else ""); + '' + (if (x < 100) then + fizzbuzz { x = x + 1; } else ""); in fizzbuzz { }ObjectiveC
#import <Foundation/Foundation.h> int main(int argc, char* argv[]) { - for (NSInteger i=1; I <= 101; i++) { - if (i % 15 == 0) { + for (NSInteger i=1; I <= 101; i++) { + if (i % 15 == 0) { NSLog(@"FizzBuzz\n"); - } else if (i % 3 == 0) { + } else if (i % 3 == 0) { NSLog(@"Fizz\n"); - } else if (i % 5 == 0) { + } else if (i % 5 == 0) { NSLog(@"Buzz\n"); - } else { + } else { NSLog(@"%li\n", i); } } @@ -976,14 +976,14 @@Pascal
var i: integer; begin - for i := 1 to 100 do - if i mod 15 = 0 then + for i := 1 to 100 do + if i mod 15 = 0 then writeln('FizzBuzz') - else if i mod 3 = 0 then + else if i mod 3 = 0 then writeln('Fizz') - else if i mod 5 = 0 then + else if i mod 5 = 0 then writeln('Buzz') - else + else writeln(i) end.Php
@@ -1029,14 +1029,14 @@ProtoBuf
repeated Person people = 1; }Python
-for i in range(1, 101): - if i % 15 == 0: +for i in range(1, 101): + if i % 15 == 0: print("FizzBuzz") - elif i % 3 == 0: + elif i % 3 == 0: print("Fizz") - elif i % 5 == 0: + elif i % 5 == 0: print("Buzz") - else: + else: print(i)R
xx <- x <- 1:100 @@ -1057,31 +1057,31 @@Racket
Regex
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])Ruby
-1.upto(100) do |n| - print "Fizz" if a = (n % 3).zero? - print "Buzz" if b = (n % 5).zero? - print n unless (a || b) +1.upto(100) do |n| + print "Fizz" if a = (n % 3).zero? + print "Buzz" if b = (n % 5).zero? + print n unless (a || b) puts endRust
-fn main() { - for i in 1..=100 { - match (i % 3, i % 5) { - (0, 0) => println!("fizzbuzz"), - (0, _) => println!("fizz"), - (_, 0) => println!("buzz"), - (_, _) => println!("{}", i), +fn main() { + for i in 1..=100 { + match (i % 3, i % 5) { + (0, 0) => println!("fizzbuzz"), + (0, _) => println!("fizz"), + (_, 0) => println!("buzz"), + (_, _) => println!("{}", i), } } }Scala
-object FizzBuzz extends App { - 1 to 100 foreach { n => - println((n % 3, n % 5) match { - case (0, 0) => "FizzBuzz" - case (0, _) => "Fizz" - case (_, 0) => "Buzz" - case _ => n +object FizzBuzz extends App { + 1 to 100 foreach { n => + println((n % 3, n % 5) match { + case (0, 0) => "FizzBuzz" + case (0, _) => "Fizz" + case (_, 0) => "Buzz" + case _ => n }) } }@@ -1099,18 +1099,18 @@Scheme
Scss
@mixin theme($theme: DarkGray) { background: $theme; - box-shadow: 0 0 1px rgba($theme, .25); + box-shadow: 0 0 1px rgba($theme, .25); color: #fff; } .info { - @include theme; + @include theme; } .alert { - @include theme($theme: DarkRed); + @include theme($theme: DarkRed); } .success { - @include theme($theme: DarkGreen); + @include theme($theme: DarkGreen); }Sql
@@ -1152,13 +1152,13 @@Svelte
{count === 1 ? 'time' : 'times'} </button>Swift
-for i in 1...100 { - switch (i % 3, i % 5) { - case (0, 0): +for i in 1...100 { + switch (i % 3, i % 5) { + case (0, 0): print("FizzBuzz") - case (0, _): + case (0, _): print("Fizz") - case (_, 0): + case (_, 0): print("Buzz") default: print(i) @@ -1173,10 +1173,10 @@Toml
dob = 1979-05-27T07:32:00-08:00 [database] -enabled = true -ports = [ 8000, 8001, 8002 ] -data = [ ["delta", "phi"], [3.14] ] -temp_targets = { cpu = 79.5, case = 72.0 } +enabled = true +ports = [ 8000, 8001, 8002 ] +data = [ ["delta", "phi"], [3.14] ] +temp_targets = { cpu = 79.5, case = 72.0 } [servers] @@ -1236,27 +1236,27 @@Wast
(module ;; is_prime(n) takes a (positive) number and returns 1 if this number is ;; prime, 0 if it's composite. - (func $is_prime (export "is_prime") (param $n i32) (result i32) - (local $i i32) + (func $is_prime (export "is_prime") (param $n i32) (result i32) + (local $i i32) ;; n < 2 are not prime - (i32.lt_u (local.get $n) (i32.const 2)) + (i32.lt_u (local.get $n) (i32.const 2)) if - i32.const 0 + i32.const 0 return end ;; n == 2 is prime - (i32.eq (local.get $n) (i32.const 2)) + (i32.eq (local.get $n) (i32.const 2)) if - i32.const 1 + i32.const 1 return end ;; Other even numbers are not prime - (i32.eq (i32.rem_u (local.get $n) (i32.const 2)) (i32.const 0)) + (i32.eq (i32.rem_u (local.get $n) (i32.const 2)) (i32.const 0)) if - i32.const 0 + i32.const 0 return end @@ -1264,24 +1264,24 @@Wast
;; divide it by all odd numbers smaller than it. ;; ;; for i = 3; i < n; i += 2 - (local.set $i (i32.const 3)) + (local.set $i (i32.const 3)) (loop $testprime (block $breaktestprime (i32.ge_u (local.get $i) (local.get $n)) br_if $breaktestprime ;; divisor found; return false - (i32.eq (i32.rem_u (local.get $n) (local.get $i)) (i32.const 0)) + (i32.eq (i32.rem_u (local.get $n) (local.get $i)) (i32.const 0)) if - i32.const 0 + i32.const 0 return end - (local.set $i (i32.add (local.get $i) (i32.const 2))) + (local.set $i (i32.add (local.get $i) (i32.const 2))) br $testprime )) ;; if we're here, the loop didn't find a divisor - i32.const 1 + i32.const 1 ) )Wat
@@ -1292,27 +1292,27 @@Wat
(module ;; is_prime(n) takes a (positive) number and returns 1 if this number is ;; prime, 0 if it's composite. - (func $is_prime (export "is_prime") (param $n i32) (result i32) - (local $i i32) + (func $is_prime (export "is_prime") (param $n i32) (result i32) + (local $i i32) ;; n < 2 are not prime - (i32.lt_u (local.get $n) (i32.const 2)) + (i32.lt_u (local.get $n) (i32.const 2)) if - i32.const 0 + i32.const 0 return end ;; n == 2 is prime - (i32.eq (local.get $n) (i32.const 2)) + (i32.eq (local.get $n) (i32.const 2)) if - i32.const 1 + i32.const 1 return end ;; Other even numbers are not prime - (i32.eq (i32.rem_u (local.get $n) (i32.const 2)) (i32.const 0)) + (i32.eq (i32.rem_u (local.get $n) (i32.const 2)) (i32.const 0)) if - i32.const 0 + i32.const 0 return end @@ -1320,24 +1320,24 @@Wat
;; divide it by all odd numbers smaller than it. ;; ;; for i = 3; i < n; i += 2 - (local.set $i (i32.const 3)) + (local.set $i (i32.const 3)) (loop $testprime (block $breaktestprime (i32.ge_u (local.get $i) (local.get $n)) br_if $breaktestprime ;; divisor found; return false - (i32.eq (i32.rem_u (local.get $n) (local.get $i)) (i32.const 0)) + (i32.eq (i32.rem_u (local.get $n) (local.get $i)) (i32.const 0)) if - i32.const 0 + i32.const 0 return end - (local.set $i (i32.add (local.get $i) (i32.const 2))) + (local.set $i (i32.add (local.get $i) (i32.const 2))) br $testprime )) ;; if we're here, the loop didn't find a divisor - i32.const 1 + i32.const 1 ) )X86asm
@@ -1382,14 +1382,14 @@Yaml
items: - part_no: A4786 descrip: Water Bucket (Filled) - price: 1.47 - quantity: 4 + price: 1.47 + quantity: 4 - part_no: E1628 descrip: High Heeled "Ruby" Slippers - size: 8 - price: 133.7 - quantity: 1 + size: 8 + price: 133.7 + quantity: 1 bill-to: &id001 street: | @@ -1406,17 +1406,17 @@Yaml
Pay no attention to the man behind the curtain.Zig
-const print = @import("std").debug.print; -pub fn main() void { - var i: usize = 1; - while (i <= 100) : (i += 1) { - if (i % 3 == 0 and i % 5 == 0) { +const print = @import("std").debug.print; +pub fn main() void { + var i: usize = 1; + while (i <= 100) : (i += 1) { + if (i % 3 == 0 and i % 5 == 0) { print("FizzBuzz\n", .{}); - } else if (i % 3 == 0) { + } else if (i % 3 == 0) { print("Fizz\n", .{}); - } else if (i % 5 == 0) { + } else if (i % 5 == 0) { print("Buzz\n", .{}); - } else { + } else { print("{}\n", .{i}); } }