Skip to content

Commit

Permalink
🐛 Fix doc comments (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed May 18, 2024
1 parent b626aff commit f9b5ab2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/user/mcdoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ TODO
[[s-dispatch,_DispatchStatement_]]
<<s-dispatch>>::
<<s-attributes>>
<<s-prelim>>
`dispatch` <<t-res-loc>> <<s-index-body>>~pass:n[nochild: <<s-dynamic-index>>]~ <<s-type-param-block>>^?^
`to` <<s-type>>
****
Expand Down
2 changes: 1 addition & 1 deletion packages/mcdoc/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface DispatchStatementNode extends AstNode {
type: 'mcdoc:dispatch_statement'
children: (
| CommentNode
| AttributeNode
| PrelimNode
| LiteralNode
| ResourceLocationNode
| IndexBodyNode
Expand Down
39 changes: 20 additions & 19 deletions packages/mcdoc/src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,30 @@ const typeParamBlock: InfallibleParser<TypeParamBlockNode> = setType(

const noop: InfallibleParser<undefined> = () => undefined

export const docComment: Parser<CommentNode> = core.comment({
singleLinePrefixes: new Set(['///']),
includesEol: true,
})

export const docComments: InfallibleParser<DocCommentsNode> = setType(
'mcdoc:doc_comments',
repeat(docComment, (src) => {
src.skipWhitespace()
return []
}),
)

const prelim: InfallibleParser<SyntaxUtil<DocCommentsNode | AttributeNode>> =
syntax([optional(failOnEmpty(docComments)), attributes])

const optionalTypeParamBlock: InfallibleParser<TypeParamBlockNode | undefined> =
select([{ prefix: '<', parser: typeParamBlock }, { parser: noop }])

export const dispatchStatement: Parser<DispatchStatementNode> = setType(
'mcdoc:dispatch_statement',
syntax(
[
attributes,
prelim,
keyword('dispatch'),
resLoc({
category: 'mcdoc/dispatcher',
Expand All @@ -668,22 +684,6 @@ export const dispatchStatement: Parser<DispatchStatementNode> = setType(
),
)

export const docComment: Parser<CommentNode> = core.comment({
singleLinePrefixes: new Set(['///']),
includesEol: true,
})

export const docComments: InfallibleParser<DocCommentsNode> = setType(
'mcdoc:doc_comments',
repeat(docComment, (src) => {
src.skipWhitespace()
return []
}),
)

const prelim: InfallibleParser<SyntaxUtil<DocCommentsNode | AttributeNode>> =
syntax([optional(failOnEmpty(docComments)), attributes])

const enumType: InfallibleParser<LiteralNode> = literal(
['byte', 'short', 'int', 'long', 'string', 'float', 'double'],
{ colorTokenType: 'type' },
Expand Down Expand Up @@ -977,6 +977,7 @@ function typeBase<T extends string>(
{ prefix: '<', parser: typeArgBlock },
{ parser: failOnError(indexBody()) },
]),
true,
),
],
true,
Expand Down Expand Up @@ -1105,13 +1106,13 @@ export const numericType: Parser<NumericTypeNode> = typeBase(
parser: syntax([
keyword(NumericTypeFloatKinds, { colorTokenType: 'type' }),
atFloatRange,
]),
], true),
},
{
parser: syntax([
keyword(NumericTypeIntKinds, { colorTokenType: 'type' }),
atIntRange,
]),
], true),
},
]),
)
Expand Down

0 comments on commit f9b5ab2

Please sign in to comment.