Skip to content

Commit

Permalink
hmmm, some stuff broken
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Mar 15, 2021
1 parent c8a6d07 commit 0244e8d
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 57 deletions.
72 changes: 69 additions & 3 deletions corpus/documentation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ Real life example from neovim

--- Store Diagnostic[] by line
---@param diagnostics Diagnostic[]: hello
---@return table<number, Diagnostic[]>

---@return my_type
local _diagnostic_lines = function(diagnostics)
end

Expand Down Expand Up @@ -495,13 +496,78 @@ end
)

==================
Using classes as types
Only a class
==================

---@class Map @table lie

---

(program (documentation_class (emmy_class (emmy_type (identifier)) (class_description))))

==================
Class with variable
==================

local Job = {}

---@class Map @table lie

---

(program
(variable_declaration (local) (variable_declarator (identifier)) (tableconstructor))
(documentation_class (emmy_class (emmy_type (identifier)) (class_description))))

==================
Class as part of header
==================

local Job = {}

--- HEADER
---@class Job @desc
---@field cmd string: comamnd
---@param o table: options
function Job:new(o)
return setmetatable(o, self)
end

---

(program
(variable_declaration
(local) (variable_declarator (identifier)) (tableconstructor))
(function_statement
(emmy_documentation
(emmy_header)
(emmy_class (emmy_type (identifier)) (class_description))
(emmy_field (identifier) (emmy_type (identifier)) (field_description))
(emmy_parameter (identifier) (emmy_type (identifier)) (parameter_description)))
(function_start)
(function_name (identifier) (table_colon) (identifier))
(function_body_paren)
(parameter_list (identifier))
(function_body_paren)
(return_statement
(function_call
(identifier)
(function_call_paren)
(function_arguments
(identifier)
(identifier))
(function_call_paren)))
(function_end)))

==================
Using classes as types
==================


---@class Map @table lie

local Job = {}

--- HEADER
---@class Job @desc
---@field cmd string: comamnd
Expand All @@ -513,8 +579,8 @@ end
---

(program
(variable_declaration (local) (variable_declarator (identifier)) (tableconstructor))
(documentation_class (emmy_class (emmy_type (identifier)) (class_description)))
(variable_declaration (local) (variable_declarator (identifier)) (tableconstructor))
(function_statement
(emmy_documentation
(emmy_header)
Expand Down
53 changes: 22 additions & 31 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = grammar({
$._documentation_brief_container,
$._documentation_tag_container,
$._documentation_config_container,
$.documentation_class,
$.documentation_class
)
),
optional(
Expand Down Expand Up @@ -466,7 +466,10 @@ module.exports = grammar({

documentation_config: ($) => $._expression,
_documentation_config_container: ($) =>
prec.right(PREC.PROGRAM, seq(/\s*---@config\s+/, $.documentation_config)),
prec.right(
PREC.PROGRAM,
seq(/\s*---@config\s+/, $.documentation_config)
),

documentation_brief: () => /[^\n]*/,
_documentation_brief_container: ($) =>
Expand All @@ -485,12 +488,12 @@ module.exports = grammar({

emmy_type_list: ($) => seq(field("type", $.emmy_type), "[]"),
emmy_type_map: ($) =>
seq(
"table<",
field("key", $.emmy_type),
",",
field("value", $.emmy_type),
">"
seq(
"table<",
field("key", $.emmy_type),
/\s*,\s*/,
field("value", $.emmy_type),
">"
),

emmy_type: ($) =>
Expand All @@ -507,28 +510,18 @@ module.exports = grammar({
seq(
/\s*---@class\s+/,
field("type", $.emmy_type),
optional(seq(/\s*:\s*/, field("parent", $.emmy_type))),
optional(
seq(
/\s*:\s*/,
field("parent", $.emmy_type)
),
),
optional(
seq(
/\s*@\s*/,
field("description", $.class_description)
)
),
/\n\s*/
),
seq(/\s*@\s*/, field("description", $.class_description))
)
),

documentation_class: ($) =>
prec.right(
PREC.PROGRAM,
seq($.emmy_class, any_amount_of($.emmy_field))
),


// Definition:
// ---@param param_name MY_TYPE[|other_type] [@comment]
//
Expand All @@ -549,8 +542,7 @@ module.exports = grammar({
/\s*:\s*/,
field("description", $.parameter_description)
)
),
/\n\s*/
)
),

// Definition:
Expand All @@ -568,14 +560,12 @@ module.exports = grammar({

// TODO: How closely should we be to emmy...
optional(
seq(
/\s*:\s*/,
field("description", $.field_description)
)
),
/\n\s*/
seq(/\s*:\s*/, field("description", $.field_description))
)
),

_single_line: (_) => /[^\n]*/,

class_description: ($) => $._multi_emmy,
field_description: ($) => $._multi_emmy,
parameter_description: ($) => $._multi_emmy,
Expand All @@ -587,7 +577,7 @@ module.exports = grammar({
field("type", list_of($.emmy_type, "|")),
// field("description", optional($.emmy_return_description))
// field("description", optional(/[^\n]+/))
field("description", $.emmy_return_description)
optional(field("description", $.emmy_return_description))
),

emmy_eval: ($) => $._expression,
Expand Down Expand Up @@ -623,6 +613,7 @@ module.exports = grammar({

// Comments {{{
comment: ($) => choice(seq("--", /.*\n/), $._multi_comment),
// comment: ($) => choice(seq("--", /[^-].*\r?\n/), $._multi_comment),
// }}}
},
});
Expand Down
40 changes: 20 additions & 20 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2202,8 +2202,8 @@
}
},
{
"type": "STRING",
"value": ","
"type": "PATTERN",
"value": "\\s*,\\s*"
},
{
"type": "FIELD",
Expand Down Expand Up @@ -2300,10 +2300,6 @@
"type": "BLANK"
}
]
},
{
"type": "PATTERN",
"value": "\\n\\s*"
}
]
},
Expand Down Expand Up @@ -2400,10 +2396,6 @@
"type": "BLANK"
}
]
},
{
"type": "PATTERN",
"value": "\\n\\s*"
}
]
},
Expand Down Expand Up @@ -2475,13 +2467,13 @@
"type": "BLANK"
}
]
},
{
"type": "PATTERN",
"value": "\\n\\s*"
}
]
},
"_single_line": {
"type": "PATTERN",
"value": "[^\\n]*"
},
"class_description": {
"type": "SYMBOL",
"name": "_multi_emmy"
Expand Down Expand Up @@ -2535,12 +2527,20 @@
}
},
{
"type": "FIELD",
"name": "description",
"content": {
"type": "SYMBOL",
"name": "emmy_return_description"
}
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "description",
"content": {
"type": "SYMBOL",
"name": "emmy_return_description"
}
},
{
"type": "BLANK"
}
]
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
"fields": {
"description": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "emmy_return_description",
Expand Down
Binary file modified src/parser.c
Binary file not shown.
2 changes: 2 additions & 0 deletions src/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ namespace {
// We've advanced as far as we're confident.
// We will check again after this.
lexer->mark_end(lexer);

if (lexer->lookahead == '\n') { break; }
}

return true;
Expand Down
52 changes: 50 additions & 2 deletions tests/documentation.scm
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,59 @@
(function_end))
)

;;; Using classes as types

;;; Only a class
; ---@class Map @table lie
(program (documentation_class (emmy_class (emmy_type (identifier)) (class_description))))

;;; Class with variable
; local Job = {}
;
; ---@class Map @table lie
(program
(variable_declaration (local) (variable_declarator (identifier)) (tableconstructor))
(documentation_class (emmy_class (emmy_type (identifier)) (class_description))))

;;; Class as part of header
; local Job = {}
;
; --- HEADER
; ---@class Job @desc
; ---@field cmd string: comamnd
; ---@param o table: options
; function Job:new(o)
; return setmetatable(o, self)
; end
(program
(variable_declaration
(local) (variable_declarator (identifier)) (tableconstructor))
(function_statement
(emmy_documentation
(emmy_header)
(emmy_class (emmy_type (identifier)) (class_description))
(emmy_field (identifier) (emmy_type (identifier)) (field_description))
(emmy_parameter (identifier) (emmy_type (identifier)) (parameter_description)))
(function_start)
(function_name (identifier) (table_colon) (identifier))
(function_body_paren)
(parameter_list (identifier))
(function_body_paren)
(return_statement
(function_call
(identifier)
(function_call_paren)
(function_arguments
(identifier)
(identifier))
(function_call_paren)))
(function_end)))

;;; Using classes as types
;
; ---@class Map @table lie
;
; local Job = {}
;
; --- HEADER
; ---@class Job @desc
; ---@field cmd string: comamnd
Expand All @@ -415,8 +463,8 @@
; return setmetatable(o, self)
; end
(program
(variable_declaration (local) (variable_declarator (identifier)) (tableconstructor))
(documentation_class (emmy_class (emmy_type (identifier)) (class_description)))
(variable_declaration (local) (variable_declarator (identifier)) (tableconstructor))
(function_statement
(emmy_documentation
(emmy_header)
Expand Down

0 comments on commit 0244e8d

Please sign in to comment.