Skip to content

Commit

Permalink
Add public keyword and refactor import rules
Browse files Browse the repository at this point in the history
- Add `public_statement`
- Split import rule into `import_statement` and `using_statement`
  • Loading branch information
savq committed Oct 29, 2024
1 parent ac751d1 commit 8fcd1c1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
18 changes: 13 additions & 5 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ module.exports = grammar({
$.local_statement,
$.export_statement,
$.import_statement,
$.public_statement,
$.using_statement,
),

compound_statement: $ => seq('begin', optional($._terminator), optional($._block), 'end'),
Expand Down Expand Up @@ -476,19 +478,25 @@ module.exports = grammar({
$._import_list,
),

export_statement: $ => seq(
'export',
prec.right(sep1(',', $._exportable)),
),
export_statement: $ => seq('export', prec.right(sep1(',', $._exportable))),

public_statement: $ => seq('public', prec.right(sep1(',', $._exportable))),

import_statement: $ => seq(
choice('import', 'using'),
'import',
choice(
$._import_list,
$.selected_import,
),
),

using_statement: $ => seq(
'using',
choice(
$._import_list,
$.selected_import,
),
),

// Primary expressions can be called, indexed, accessed, and type parametrized.
_primary_expression: $ => choice(
Expand Down
11 changes: 7 additions & 4 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,14 @@
(export_statement
"export" @keyword.import)

(public_statement
"public" @keyword.import)

(import_statement
[
"import"
"using"
] @keyword.import)
"import" @keyword.import)

(using_statement
"using" @keyword.import)

(import_alias
"as" @keyword.import)
Expand Down
2 changes: 1 addition & 1 deletion test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ end
(integer_literal)
(integer_literal)))
(interpolation_expression (string_literal))
(import_statement
(using_statement
(selected_import
(interpolation_expression (identifier))
(interpolation_expression (parenthesized_expression (identifier)))))
Expand Down
13 changes: 10 additions & 3 deletions test/corpus/statements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,20 @@ export statements
export a
export a, b, +, (*)
export @macroMcAtface
public a
public a, b, +, (*)
public @macroMcAtface


---

(source_file
(export_statement (identifier))
(export_statement (identifier) (identifier) (operator) (operator))
(export_statement (macro_identifier (identifier))))
(export_statement (macro_identifier (identifier)))
(public_statement (identifier))
(public_statement (identifier) (identifier) (operator) (operator))
(public_statement (macro_identifier (identifier))))


==============================
Expand All @@ -330,10 +337,10 @@ import Base: @view as @v
(source_file
;; Simple import
(import_statement (identifier))
(import_statement (identifier))
(using_statement (identifier))

;; Relative paths
(import_statement
(using_statement
(import_path (identifier))
(import_path (identifier)))

Expand Down

0 comments on commit 8fcd1c1

Please sign in to comment.