From f9b5ab219d8db91641c4a1f8da0fdb49bdaa4403 Mon Sep 17 00:00:00 2001 From: Misode Date: Sat, 18 May 2024 05:11:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20doc=20comments=20(#1171)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/user/mcdoc/index.adoc | 2 +- packages/mcdoc/src/node/index.ts | 2 +- packages/mcdoc/src/parser/index.ts | 39 +++++++++++++++--------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/docs/user/mcdoc/index.adoc b/docs/user/mcdoc/index.adoc index 56121e466..304a287d3 100644 --- a/docs/user/mcdoc/index.adoc +++ b/docs/user/mcdoc/index.adoc @@ -1077,7 +1077,7 @@ TODO [[s-dispatch,_DispatchStatement_]] <>:: - <> + <> `dispatch` <> <>~pass:n[nochild: <>]~ <>^?^ `to` <> **** diff --git a/packages/mcdoc/src/node/index.ts b/packages/mcdoc/src/node/index.ts index 344f77ada..6959102cf 100644 --- a/packages/mcdoc/src/node/index.ts +++ b/packages/mcdoc/src/node/index.ts @@ -48,7 +48,7 @@ export interface DispatchStatementNode extends AstNode { type: 'mcdoc:dispatch_statement' children: ( | CommentNode - | AttributeNode + | PrelimNode | LiteralNode | ResourceLocationNode | IndexBodyNode diff --git a/packages/mcdoc/src/parser/index.ts b/packages/mcdoc/src/parser/index.ts index 6afef4807..26ed29ea7 100644 --- a/packages/mcdoc/src/parser/index.ts +++ b/packages/mcdoc/src/parser/index.ts @@ -646,6 +646,22 @@ const typeParamBlock: InfallibleParser = setType( const noop: InfallibleParser = () => undefined +export const docComment: Parser = core.comment({ + singleLinePrefixes: new Set(['///']), + includesEol: true, +}) + +export const docComments: InfallibleParser = setType( + 'mcdoc:doc_comments', + repeat(docComment, (src) => { + src.skipWhitespace() + return [] + }), +) + +const prelim: InfallibleParser> = + syntax([optional(failOnEmpty(docComments)), attributes]) + const optionalTypeParamBlock: InfallibleParser = select([{ prefix: '<', parser: typeParamBlock }, { parser: noop }]) @@ -653,7 +669,7 @@ export const dispatchStatement: Parser = setType( 'mcdoc:dispatch_statement', syntax( [ - attributes, + prelim, keyword('dispatch'), resLoc({ category: 'mcdoc/dispatcher', @@ -668,22 +684,6 @@ export const dispatchStatement: Parser = setType( ), ) -export const docComment: Parser = core.comment({ - singleLinePrefixes: new Set(['///']), - includesEol: true, -}) - -export const docComments: InfallibleParser = setType( - 'mcdoc:doc_comments', - repeat(docComment, (src) => { - src.skipWhitespace() - return [] - }), -) - -const prelim: InfallibleParser> = - syntax([optional(failOnEmpty(docComments)), attributes]) - const enumType: InfallibleParser = literal( ['byte', 'short', 'int', 'long', 'string', 'float', 'double'], { colorTokenType: 'type' }, @@ -977,6 +977,7 @@ function typeBase( { prefix: '<', parser: typeArgBlock }, { parser: failOnError(indexBody()) }, ]), + true, ), ], true, @@ -1105,13 +1106,13 @@ export const numericType: Parser = typeBase( parser: syntax([ keyword(NumericTypeFloatKinds, { colorTokenType: 'type' }), atFloatRange, - ]), + ], true), }, { parser: syntax([ keyword(NumericTypeIntKinds, { colorTokenType: 'type' }), atIntRange, - ]), + ], true), }, ]), )