@bablr/language-en-c-comments
Version:
A BABLR language for C-style comments
55 lines • 2.24 kB
JavaScript
/* @macrome
* @generatedby @bablr/macrome-generator-bablr
* @generatedfrom ./grammar.macro.js#d8ca792c55f7298d938ada25cd0fd56a035e2576
* This file is autogenerated. Please do not edit it directly.
* When editing run `npx macrome watch` then change the file this is generated from.
*/
import _applyDecs from "@babel/runtime/helpers/applyDecs2305";
let _initProto, _BlockCommentDecs, _LineCommentDecs, _AnyDecs, _PunctuatorDecs;
import { re, spam as m } from '@bablr/boot';
import { eat, eatMatch } from '@bablr/helpers/grammar';
import { Node, CoveredBy, InjectFrom } from '@bablr/helpers/decorators';
import * as Shared from '@bablr/helpers/productions';
import * as Space from '@bablr/language-en-blank-space';
export const canonicalURL = 'https://bablr.org/languages/core/en/c-comments';
export const dependencies = {
Space
};
export const grammar = class CCommentsGrammar {
static {
[_initProto] = _applyDecs(this, [[_BlockCommentDecs, 2, "BlockComment"], [_LineCommentDecs, 2, "LineComment"], [Node, 2, "Content"], [_AnyDecs, 2, "Any"], [_PunctuatorDecs, 2, "Punctuator"]], []).e;
}
constructor() {
_initProto(this);
}
*[(_BlockCommentDecs = [CoveredBy('Comment'), Node], _LineCommentDecs = [CoveredBy('Comment'), Node], _AnyDecs = InjectFrom(Shared), _PunctuatorDecs = [Node, InjectFrom(Shared)], "Trivia")]() {
while ((yield eatMatch(m`#: :Space: <*Space /[ \r\n\t]+/ />`)) || (yield eatMatch(m`#: <__Comment />`)));
}
*Comment() {
yield eat(m`<_Any />`, [m`<BlockComment '/*' />`, m`<LineComment '//' />`]);
}
*BlockComment() {
yield eat(m`open: <*Punctuator '/*' { balanced: '*/', balancedSpan: 'Comment:Block' } />`);
yield eatMatch(m`content: <*Content { span: 'Comment:Block' }/>`);
yield eat(m`close: <*Punctuator '*/' { balancer: true } />`);
}
*LineComment() {
yield eat(m`start: <*Punctuator '//' />`);
yield eatMatch(m`content: <*Content { span: 'Comment:Line' } />`);
}
*Content({
state: {
span
}
}) {
if (span === 'Comment:Block') {
yield eatMatch(re`/(\*[^/]|[^*])*/`);
} else if (span === 'Comment:Line') {
yield eatMatch(re`/[^\n]*/`);
} else {
throw new Error();
}
}
*Any() {}
*Punctuator() {}
};