Skip to content

Commit

Permalink
Amass everything after ENDDOCUMENT into an end document statement.
Browse files Browse the repository at this point in the history
Everything in that gets the block comment color.  The region also folds.
The ENDDOCUMENT keyword is still highlighted the same and still can be
autocompleted.
  • Loading branch information
drgrice1 committed Oct 9, 2024
1 parent 802e0ae commit fd5d00d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openwebwork/codemirror-lang-pg",
"version": "0.0.1-beta.4",
"version": "0.0.1-beta.5",
"description": "PG language support for CodeMirror",
"author": "The WeBWorK Project",
"license": "MIT",
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const pgLanguage = LRLanguage.define({
IfStatement: continuedIndent({ except: /^\s*({|else\b|elsif\b)/ }),
Block: delimitedIndent({ closing: '}' }),
'StringSingleQuoted StringQQuoted StringDoubleQuoted StringQqQuoted': () => null,
'StatementEnd InterpolatedHeredocBody UninterpolatedHeredocBody': () => null,
'StatementEnd InterpolatedHeredocBody UninterpolatedHeredocBody EndDocument': () => null,
Statement: continuedIndent(),
'PGMLBlock PGTextBlock LaTeXImageCode': flatIndent
}),
Expand All @@ -59,7 +59,9 @@ export const pgLanguage = LRLanguage.define({
)
return { from: node.firstChild.nextSibling.from, to: node.firstChild.nextSibling.to };
return null;
}
},
'EndDocument EndDataStatement': (node) =>
node.firstChild ? { from: node.firstChild.to, to: node.to } : null
})
],
wrap: parseMixed((node) =>
Expand Down
4 changes: 2 additions & 2 deletions src/pg-highlighting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const pgHighlighting = styleTags({
'NamedUnaryOperator ListOperator Eval each grep': t.function(t.keyword),
'join keys map pop push shift sort splice time times': t.function(t.keyword),
'unpack unshift values wantarray': t.special(t.keyword),
'DOCUMENT ENDDOCUMENT PGOperator': t.special(t.function(t.operatorKeyword)),
'ENDDOCUMENT PGOperator': t.special(t.function(t.operatorKeyword)),
'BeginPG EndPG': t.keyword,
'BEGIN CHECK END INIT UNITCHECK': t.processingInstruction,
'__FILE__ __LINE__ __PACKAGE__ __SUB__': t.literal,
Expand Down Expand Up @@ -46,7 +46,7 @@ export const pgHighlighting = styleTags({
'qw QWListContent/... Pair/Identifier HashAccessVariable/Identifier Version': t.string,
'HeredocInitializer/... HeredocEndIdentifier Glob LaTeXImageCodeStart': t.string,
'm qr s tr y RegexOptions': t.special(t.string),
'PodStatement EndDataStatement/...': t.blockComment,
'PodStatement EndDataStatement/... EndDocument': t.blockComment,
EscapeSequence: t.escape,
'Comma FatComma': t.punctuation,
'( )': t.paren,
Expand Down
8 changes: 7 additions & 1 deletion src/pg-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ export const pgCompletion = (isTop = false) => {

if (
isTop &&
!inside(['InterpolatedHeredocBody', 'UninterpolatedHeredocBody']) &&
!inside([
'InterpolatedHeredocBody',
'UninterpolatedHeredocBody',
'PodStatement',
'EndDataStatement',
'EndDocument'
]) &&
((context.matchBefore(/^\s*\w*/) && context.explicit) || context.matchBefore(/^\s*B\w*/))
) {
completionOptions.push(
Expand Down
1 change: 1 addition & 0 deletions src/pg.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ statement[@isGroup=Statement] {
EmptyStatement { ~block ";" } |
PodStatement |
EndDataStatement[@dynamicPrecedence=4] { (kw<"__END__"> | kw<"__DATA__">) endDataBlock } |
EndDocument[@dynamicPrecedence=4] { kw<"ENDDOCUMENT"> endDataBlock } |
LaTeXImageCode {
(ScalarVariable | PGVariable | expression)
ArrowOperator
Expand Down
1 change: 1 addition & 0 deletions src/pg.grammar.terms.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export declare const automaticSemicolon: number,
NamedUnaryOperator: number,
ListOperator: number,
PGOperator: number,
ENDDOCUMENT: number,
HeredocStartIdentifier: number,
LaTeXImageCodeStart: number,
uninterpolatedHeredocStart: number,
Expand Down
4 changes: 3 additions & 1 deletion src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
NamedUnaryOperator,
ListOperator,
PGOperator,
ENDDOCUMENT,
HeredocStartIdentifier,
LaTeXImageCodeStart,
uninterpolatedHeredocStart,
Expand Down Expand Up @@ -421,7 +422,8 @@ const peekLCWord = (input: InputStream): [string, number] => {
export const builtinOperator = new ExternalTokenizer((input, stack) => {
if (stack.canShift(PGOperator)) {
const [word, nextChar] = peekWord(input);
if (pgOperators.has(word) && !isIdentifierChar(nextChar)) input.acceptToken(PGOperator, word.length);
if (word.startsWith('ENDDOCUMENT')) input.acceptToken(ENDDOCUMENT, 11);
else if (pgOperators.has(word) && !isIdentifierChar(nextChar)) input.acceptToken(PGOperator, word.length);
}

if (stack.canShift(NamedUnaryOperator)) {
Expand Down

0 comments on commit fd5d00d

Please sign in to comment.