Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
module attribute is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jlgeering committed Sep 10, 2018
1 parent 2e6aa5c commit a62450a
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 350 deletions.
74 changes: 72 additions & 2 deletions corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,87 @@ module with attributes
======================

defmodule Name do
@moduledoc "an apple a day, keeps the moduledoc away"
@after_compile
@before_compile
@behaviour Good.Module
@custom_attr [:hello, "world"]
# TODO @custom_attr [hello: "world"]
# TODO @dialyzer {:nowarn_function, my_fun: 1}
@file "hello.ex"
@external_resource
@moduledoc "an apple a day, keeps the moduledoc away"
@on_load
@vsn "1.0"
end

---

(program
(module (alias)
(module_attribute (string))
(module_attribute)
(module_attribute)
(module_attribute (alias))
(module_attribute (list (atom) (string)))
(comment)
(comment)
(module_attribute (string))
(module_attribute)
(module_attribute (string))
(module_attribute)
(module_attribute (string))))

===============================
module with function attributes
===============================

defmodule Name do
@deprecated "Use Module.bar/0 instead"
@doc "Hello world"
# TODO
# @doc """
# Doesn't do much.
# """
# TODO @doc deprecated: "Use Module.bar/0 instead"
# TODO @doc since: "1.1.0"
@impl true
@impl Module
@on_definition
# def foo() do
# end
end

---

(program
(module (alias)
(module_attribute (string))
(module_attribute (string))
(comment)
(comment)
(comment)
(comment)
(comment)
(comment)
(module_attribute (true))
(module_attribute (alias))
(module_attribute)
(comment)
(comment)))

===========================
module with type attributes
===========================

defmodule Name do
@typedoc "This type"
# TODO @typedoc since: "1.1.0"
# TODO @type t :: term
end

---

(program
(module (alias)
(module_attribute (string))
(comment)
(comment)))
2 changes: 1 addition & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ module.exports = grammar({

module_attribute: $ => seq(
/@\w+/,
$._value,
optional($._value),
),

comment: $ => token(seq('#', /.*/)),
Expand Down
12 changes: 10 additions & 2 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,16 @@
"value": "@\\w+"
},
{
"type": "SYMBOL",
"name": "_value"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_value"
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down
Loading

0 comments on commit a62450a

Please sign in to comment.