Add language feature: document symbols

This commit is contained in:
全卓 2022-10-31 20:07:12 +08:00
parent 299d9c35b0
commit 30742da449
8 changed files with 526 additions and 215 deletions

3
.gitignore vendored
View File

@ -6,3 +6,6 @@ node_modules
syntaxes/*.json
tsconfig.tsbuildinfo
server/src/*.d.ts
.antlr/
*.interp
*.tokens

122
server/antlr/CMake.g4 Normal file
View File

@ -0,0 +1,122 @@
grammar CMake;
@lexer::members {
this.nesting = 0;
this.newLineCount = 1;
}
file
: (command NL) * EOF // every command except the last must be terminated with newline
;
command
: 'if' '(' argument* ')' # IfCmd
| 'elseif' '(' argument* ')' # ElseIfCmd
| 'else' '(' argument* ')' # ElseCmd
| 'endif' '(' argument* ')' # EndIfCmd
| 'foreach' '(' argument+ ')' # ForeachCmd
| 'endforeach' '(' argument* ')' # EndForeachCmd
| 'while' '(' argument+ ')' # WhileCmd
| 'endwhile' '(' argument* ')' # EndWhileCmd
| 'break' '(' ')' # BreakCmd
| 'continue' '(' ')' # ContinueCmd
| 'function' '(' argument+ ')' # FunctionCmd
| 'endfunction' '(' argument* ')' # EndFunctionCmd
| 'macro' '(' argument+ ')' # MacroCmd
| 'endmacro' '(' argument* ')' # EndMacroCmd
| 'set' '(' argument+ ')' # SetCmd
| ID '(' argument * ')' # OtherCmd
;
argument
: QuotedArgument
| BracketArgument
| UnquotedArgument
| ID
| '(' argument* ')'
;
ID : [a-zA-Z_] [a-zA-Z0-9_]*
;
BracketArgument
: '[' BracketNested ']'
;
QuotedArgument
: '"' QuotedElement* '"'
;
UnquotedArgument
: (UnquotedElement)+
;
BracketComment
: '#[' BracketNested ']' -> channel(HIDDEN)
;
LineComment
: '#' ~[\r\n]* -> channel(HIDDEN)
;
// NL should be ignored in the following two cases
// 1. NL between '(' and ')'
// 2. NL between command invocations
IgnoreNLBetweenArgs
: '\r'? '\n' { this.nesting > 0 }? -> skip
;
IgnoreExtraNLBetweenCmds
: '\r'? '\n' { this.newLineCount > 0 }? -> skip
;
NL : {this.newLineCount++;} '\r'? '\n'
;
// all whitespace should be ignored by lexer
WS : [ \t]+ -> skip
;
LParen
: '(' {this.nesting++;}
;
RParen
: ')' {this.nesting--; this.newLineCount = 0;}
;
Escape
: EscapeIdentity | EscapeEncoded | EscapeSemi
;
fragment
EscapeIdentity
: '\\' ~[a-zA-Z0-9;]
;
fragment
EscapeEncoded
: '\\t' | '\\r' | '\\n'
;
fragment
EscapeSemi
: '\\;'
;
fragment
BracketNested
: '=' BracketNested '='
| '[' .*? ']'
;
fragment
QuotedElement
: ~[\\"] | Escape | '\\' NL
;
fragment
UnquotedElement
: ~[ \t\r\n()#"\\] | Escape
;

View File

@ -463,6 +463,24 @@ export class FormatListener extends CMakeListener {
this.addCommentsAfterSeprator(nlIndex);
}
enterSetCmd(ctx: any): void {
const index: number = ctx.LParen().getSymbol().tokenIndex;
this._formatted += this.getTextBeforeFirstArg("set", index);
}
exitSetCmd(ctx: any): void {
const index: number = ctx.RParen().getSymbol().tokenIndex;
const text: string = this.getTextAfterLastArg(index);
this._formatted += text;
// append a newline as command seprator
this._formatted += "\n";
// comments after the newline
const nlIndex: number = text === ")" ? index + 1 : index + 2;
this.addCommentsAfterSeprator(nlIndex);
}
enterArgument(ctx: any): void {
const count: number = ctx.getChildCount();
if (count === 1) {

View File

@ -3,100 +3,102 @@
import antlr4 from './antlr4/index.js';
const serializedATN = [4,0,27,293,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,
const serializedATN = [4,0,28,299,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,
4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,
12,2,13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,
2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,26,7,26,2,
27,7,27,2,28,7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,32,1,0,1,0,1,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,1,3,1,3,1,
4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,
5,1,6,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,8,1,8,1,
8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,
10,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,
1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,
13,1,13,1,13,1,14,1,14,5,14,176,8,14,10,14,12,14,179,9,14,1,15,1,15,1,15,
1,15,1,16,1,16,5,16,187,8,16,10,16,12,16,190,9,16,1,16,1,16,1,17,4,17,195,
8,17,11,17,12,17,196,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,18,1,19,1,19,5,
19,209,8,19,10,19,12,19,212,9,19,1,19,1,19,1,20,3,20,217,8,20,1,20,1,20,
1,20,1,20,1,20,1,21,3,21,225,8,21,1,21,1,21,1,21,1,21,1,21,1,22,1,22,3,22,
234,8,22,1,22,1,22,1,23,4,23,239,8,23,11,23,12,23,240,1,23,1,23,1,24,1,24,
1,24,1,25,1,25,1,25,1,26,1,26,1,26,3,26,254,8,26,1,27,1,27,1,27,1,28,1,28,
1,28,1,28,1,28,1,28,3,28,265,8,28,1,29,1,29,1,29,1,30,1,30,1,30,1,30,1,30,
1,30,5,30,276,8,30,10,30,12,30,279,9,30,1,30,3,30,282,8,30,1,31,1,31,1,31,
1,31,3,31,288,8,31,1,32,1,32,3,32,292,8,32,1,277,0,33,1,1,3,2,5,3,7,4,9,
5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,
18,37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26,53,27,55,0,57,0,59,0,
61,0,63,0,65,0,1,0,7,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,
2,0,10,10,13,13,2,0,9,9,32,32,4,0,48,57,59,59,65,90,97,122,2,0,34,34,92,
92,6,0,9,10,13,13,32,32,34,35,40,41,92,92,303,0,1,1,0,0,0,0,3,1,0,0,0,0,
5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,
0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,
0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,
39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,1,0,0,0,0,49,1,0,
0,0,0,51,1,0,0,0,0,53,1,0,0,0,1,67,1,0,0,0,3,70,1,0,0,0,5,77,1,0,0,0,7,82,
1,0,0,0,9,88,1,0,0,0,11,96,1,0,0,0,13,107,1,0,0,0,15,113,1,0,0,0,17,122,
1,0,0,0,19,128,1,0,0,0,21,137,1,0,0,0,23,146,1,0,0,0,25,158,1,0,0,0,27,164,
1,0,0,0,29,173,1,0,0,0,31,180,1,0,0,0,33,184,1,0,0,0,35,194,1,0,0,0,37,198,
1,0,0,0,39,206,1,0,0,0,41,216,1,0,0,0,43,224,1,0,0,0,45,231,1,0,0,0,47,238,
1,0,0,0,49,244,1,0,0,0,51,247,1,0,0,0,53,253,1,0,0,0,55,255,1,0,0,0,57,264,
1,0,0,0,59,266,1,0,0,0,61,281,1,0,0,0,63,287,1,0,0,0,65,291,1,0,0,0,67,68,
5,105,0,0,68,69,5,102,0,0,69,2,1,0,0,0,70,71,5,101,0,0,71,72,5,108,0,0,72,
73,5,115,0,0,73,74,5,101,0,0,74,75,5,105,0,0,75,76,5,102,0,0,76,4,1,0,0,
0,77,78,5,101,0,0,78,79,5,108,0,0,79,80,5,115,0,0,80,81,5,101,0,0,81,6,1,
0,0,0,82,83,5,101,0,0,83,84,5,110,0,0,84,85,5,100,0,0,85,86,5,105,0,0,86,
87,5,102,0,0,87,8,1,0,0,0,88,89,5,102,0,0,89,90,5,111,0,0,90,91,5,114,0,
0,91,92,5,101,0,0,92,93,5,97,0,0,93,94,5,99,0,0,94,95,5,104,0,0,95,10,1,
0,0,0,96,97,5,101,0,0,97,98,5,110,0,0,98,99,5,100,0,0,99,100,5,102,0,0,100,
101,5,111,0,0,101,102,5,114,0,0,102,103,5,101,0,0,103,104,5,97,0,0,104,105,
5,99,0,0,105,106,5,104,0,0,106,12,1,0,0,0,107,108,5,119,0,0,108,109,5,104,
0,0,109,110,5,105,0,0,110,111,5,108,0,0,111,112,5,101,0,0,112,14,1,0,0,0,
113,114,5,101,0,0,114,115,5,110,0,0,115,116,5,100,0,0,116,117,5,119,0,0,
117,118,5,104,0,0,118,119,5,105,0,0,119,120,5,108,0,0,120,121,5,101,0,0,
121,16,1,0,0,0,122,123,5,98,0,0,123,124,5,114,0,0,124,125,5,101,0,0,125,
126,5,97,0,0,126,127,5,107,0,0,127,18,1,0,0,0,128,129,5,99,0,0,129,130,5,
111,0,0,130,131,5,110,0,0,131,132,5,116,0,0,132,133,5,105,0,0,133,134,5,
110,0,0,134,135,5,117,0,0,135,136,5,101,0,0,136,20,1,0,0,0,137,138,5,102,
0,0,138,139,5,117,0,0,139,140,5,110,0,0,140,141,5,99,0,0,141,142,5,116,0,
0,142,143,5,105,0,0,143,144,5,111,0,0,144,145,5,110,0,0,145,22,1,0,0,0,146,
147,5,101,0,0,147,148,5,110,0,0,148,149,5,100,0,0,149,150,5,102,0,0,150,
151,5,117,0,0,151,152,5,110,0,0,152,153,5,99,0,0,153,154,5,116,0,0,154,155,
5,105,0,0,155,156,5,111,0,0,156,157,5,110,0,0,157,24,1,0,0,0,158,159,5,109,
0,0,159,160,5,97,0,0,160,161,5,99,0,0,161,162,5,114,0,0,162,163,5,111,0,
0,163,26,1,0,0,0,164,165,5,101,0,0,165,166,5,110,0,0,166,167,5,100,0,0,167,
168,5,109,0,0,168,169,5,97,0,0,169,170,5,99,0,0,170,171,5,114,0,0,171,172,
5,111,0,0,172,28,1,0,0,0,173,177,7,0,0,0,174,176,7,1,0,0,175,174,1,0,0,0,
176,179,1,0,0,0,177,175,1,0,0,0,177,178,1,0,0,0,178,30,1,0,0,0,179,177,1,
0,0,0,180,181,5,91,0,0,181,182,3,61,30,0,182,183,5,93,0,0,183,32,1,0,0,0,
184,188,5,34,0,0,185,187,3,63,31,0,186,185,1,0,0,0,187,190,1,0,0,0,188,186,
1,0,0,0,188,189,1,0,0,0,189,191,1,0,0,0,190,188,1,0,0,0,191,192,5,34,0,0,
192,34,1,0,0,0,193,195,3,65,32,0,194,193,1,0,0,0,195,196,1,0,0,0,196,194,
1,0,0,0,196,197,1,0,0,0,197,36,1,0,0,0,198,199,5,35,0,0,199,200,5,91,0,0,
200,201,1,0,0,0,201,202,3,61,30,0,202,203,5,93,0,0,203,204,1,0,0,0,204,205,
6,18,0,0,205,38,1,0,0,0,206,210,5,35,0,0,207,209,8,2,0,0,208,207,1,0,0,0,
209,212,1,0,0,0,210,208,1,0,0,0,210,211,1,0,0,0,211,213,1,0,0,0,212,210,
1,0,0,0,213,214,6,19,0,0,214,40,1,0,0,0,215,217,5,13,0,0,216,215,1,0,0,0,
216,217,1,0,0,0,217,218,1,0,0,0,218,219,5,10,0,0,219,220,4,20,0,0,220,221,
1,0,0,0,221,222,6,20,1,0,222,42,1,0,0,0,223,225,5,13,0,0,224,223,1,0,0,0,
224,225,1,0,0,0,225,226,1,0,0,0,226,227,5,10,0,0,227,228,4,21,1,0,228,229,
1,0,0,0,229,230,6,21,1,0,230,44,1,0,0,0,231,233,6,22,2,0,232,234,5,13,0,
0,233,232,1,0,0,0,233,234,1,0,0,0,234,235,1,0,0,0,235,236,5,10,0,0,236,46,
1,0,0,0,237,239,7,3,0,0,238,237,1,0,0,0,239,240,1,0,0,0,240,238,1,0,0,0,
240,241,1,0,0,0,241,242,1,0,0,0,242,243,6,23,1,0,243,48,1,0,0,0,244,245,
5,40,0,0,245,246,6,24,3,0,246,50,1,0,0,0,247,248,5,41,0,0,248,249,6,25,4,
0,249,52,1,0,0,0,250,254,3,55,27,0,251,254,3,57,28,0,252,254,3,59,29,0,253,
250,1,0,0,0,253,251,1,0,0,0,253,252,1,0,0,0,254,54,1,0,0,0,255,256,5,92,
0,0,256,257,8,4,0,0,257,56,1,0,0,0,258,259,5,92,0,0,259,265,5,116,0,0,260,
261,5,92,0,0,261,265,5,114,0,0,262,263,5,92,0,0,263,265,5,110,0,0,264,258,
1,0,0,0,264,260,1,0,0,0,264,262,1,0,0,0,265,58,1,0,0,0,266,267,5,92,0,0,
267,268,5,59,0,0,268,60,1,0,0,0,269,270,5,61,0,0,270,271,3,61,30,0,271,272,
5,61,0,0,272,282,1,0,0,0,273,277,5,91,0,0,274,276,9,0,0,0,275,274,1,0,0,
0,276,279,1,0,0,0,277,278,1,0,0,0,277,275,1,0,0,0,278,280,1,0,0,0,279,277,
1,0,0,0,280,282,5,93,0,0,281,269,1,0,0,0,281,273,1,0,0,0,282,62,1,0,0,0,
283,288,8,5,0,0,284,288,3,53,26,0,285,286,5,92,0,0,286,288,3,45,22,0,287,
283,1,0,0,0,287,284,1,0,0,0,287,285,1,0,0,0,288,64,1,0,0,0,289,292,8,6,0,
0,290,292,3,53,26,0,291,289,1,0,0,0,291,290,1,0,0,0,292,66,1,0,0,0,15,0,
177,188,196,210,216,224,233,240,253,264,277,281,287,291,5,0,1,0,6,0,0,1,
22,0,1,24,1,1,25,2];
27,7,27,2,28,7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,32,2,33,7,33,1,0,
1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,2,1,3,1,3,1,3,1,3,
1,3,1,3,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,
1,5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,
1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1,10,1,
10,1,10,1,10,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,11,1,11,1,11,1,11,1,11,
1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,
13,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,15,1,15,5,15,182,8,15,10,15,
12,15,185,9,15,1,16,1,16,1,16,1,16,1,17,1,17,5,17,193,8,17,10,17,12,17,196,
9,17,1,17,1,17,1,18,4,18,201,8,18,11,18,12,18,202,1,19,1,19,1,19,1,19,1,
19,1,19,1,19,1,19,1,20,1,20,5,20,215,8,20,10,20,12,20,218,9,20,1,20,1,20,
1,21,3,21,223,8,21,1,21,1,21,1,21,1,21,1,21,1,22,3,22,231,8,22,1,22,1,22,
1,22,1,22,1,22,1,23,1,23,3,23,240,8,23,1,23,1,23,1,24,4,24,245,8,24,11,24,
12,24,246,1,24,1,24,1,25,1,25,1,25,1,26,1,26,1,26,1,27,1,27,1,27,3,27,260,
8,27,1,28,1,28,1,28,1,29,1,29,1,29,1,29,1,29,1,29,3,29,271,8,29,1,30,1,30,
1,30,1,31,1,31,1,31,1,31,1,31,1,31,5,31,282,8,31,10,31,12,31,285,9,31,1,
31,3,31,288,8,31,1,32,1,32,1,32,1,32,3,32,294,8,32,1,33,1,33,3,33,298,8,
33,1,283,0,34,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,
25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,
49,25,51,26,53,27,55,28,57,0,59,0,61,0,63,0,65,0,67,0,1,0,7,3,0,65,90,95,
95,97,122,4,0,48,57,65,90,95,95,97,122,2,0,10,10,13,13,2,0,9,9,32,32,4,0,
48,57,59,59,65,90,97,122,2,0,34,34,92,92,6,0,9,10,13,13,32,32,34,35,40,41,
92,92,309,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,
11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,
0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,
1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,
0,45,1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,
0,0,0,1,69,1,0,0,0,3,72,1,0,0,0,5,79,1,0,0,0,7,84,1,0,0,0,9,90,1,0,0,0,11,
98,1,0,0,0,13,109,1,0,0,0,15,115,1,0,0,0,17,124,1,0,0,0,19,130,1,0,0,0,21,
139,1,0,0,0,23,148,1,0,0,0,25,160,1,0,0,0,27,166,1,0,0,0,29,175,1,0,0,0,
31,179,1,0,0,0,33,186,1,0,0,0,35,190,1,0,0,0,37,200,1,0,0,0,39,204,1,0,0,
0,41,212,1,0,0,0,43,222,1,0,0,0,45,230,1,0,0,0,47,237,1,0,0,0,49,244,1,0,
0,0,51,250,1,0,0,0,53,253,1,0,0,0,55,259,1,0,0,0,57,261,1,0,0,0,59,270,1,
0,0,0,61,272,1,0,0,0,63,287,1,0,0,0,65,293,1,0,0,0,67,297,1,0,0,0,69,70,
5,105,0,0,70,71,5,102,0,0,71,2,1,0,0,0,72,73,5,101,0,0,73,74,5,108,0,0,74,
75,5,115,0,0,75,76,5,101,0,0,76,77,5,105,0,0,77,78,5,102,0,0,78,4,1,0,0,
0,79,80,5,101,0,0,80,81,5,108,0,0,81,82,5,115,0,0,82,83,5,101,0,0,83,6,1,
0,0,0,84,85,5,101,0,0,85,86,5,110,0,0,86,87,5,100,0,0,87,88,5,105,0,0,88,
89,5,102,0,0,89,8,1,0,0,0,90,91,5,102,0,0,91,92,5,111,0,0,92,93,5,114,0,
0,93,94,5,101,0,0,94,95,5,97,0,0,95,96,5,99,0,0,96,97,5,104,0,0,97,10,1,
0,0,0,98,99,5,101,0,0,99,100,5,110,0,0,100,101,5,100,0,0,101,102,5,102,0,
0,102,103,5,111,0,0,103,104,5,114,0,0,104,105,5,101,0,0,105,106,5,97,0,0,
106,107,5,99,0,0,107,108,5,104,0,0,108,12,1,0,0,0,109,110,5,119,0,0,110,
111,5,104,0,0,111,112,5,105,0,0,112,113,5,108,0,0,113,114,5,101,0,0,114,
14,1,0,0,0,115,116,5,101,0,0,116,117,5,110,0,0,117,118,5,100,0,0,118,119,
5,119,0,0,119,120,5,104,0,0,120,121,5,105,0,0,121,122,5,108,0,0,122,123,
5,101,0,0,123,16,1,0,0,0,124,125,5,98,0,0,125,126,5,114,0,0,126,127,5,101,
0,0,127,128,5,97,0,0,128,129,5,107,0,0,129,18,1,0,0,0,130,131,5,99,0,0,131,
132,5,111,0,0,132,133,5,110,0,0,133,134,5,116,0,0,134,135,5,105,0,0,135,
136,5,110,0,0,136,137,5,117,0,0,137,138,5,101,0,0,138,20,1,0,0,0,139,140,
5,102,0,0,140,141,5,117,0,0,141,142,5,110,0,0,142,143,5,99,0,0,143,144,5,
116,0,0,144,145,5,105,0,0,145,146,5,111,0,0,146,147,5,110,0,0,147,22,1,0,
0,0,148,149,5,101,0,0,149,150,5,110,0,0,150,151,5,100,0,0,151,152,5,102,
0,0,152,153,5,117,0,0,153,154,5,110,0,0,154,155,5,99,0,0,155,156,5,116,0,
0,156,157,5,105,0,0,157,158,5,111,0,0,158,159,5,110,0,0,159,24,1,0,0,0,160,
161,5,109,0,0,161,162,5,97,0,0,162,163,5,99,0,0,163,164,5,114,0,0,164,165,
5,111,0,0,165,26,1,0,0,0,166,167,5,101,0,0,167,168,5,110,0,0,168,169,5,100,
0,0,169,170,5,109,0,0,170,171,5,97,0,0,171,172,5,99,0,0,172,173,5,114,0,
0,173,174,5,111,0,0,174,28,1,0,0,0,175,176,5,115,0,0,176,177,5,101,0,0,177,
178,5,116,0,0,178,30,1,0,0,0,179,183,7,0,0,0,180,182,7,1,0,0,181,180,1,0,
0,0,182,185,1,0,0,0,183,181,1,0,0,0,183,184,1,0,0,0,184,32,1,0,0,0,185,183,
1,0,0,0,186,187,5,91,0,0,187,188,3,63,31,0,188,189,5,93,0,0,189,34,1,0,0,
0,190,194,5,34,0,0,191,193,3,65,32,0,192,191,1,0,0,0,193,196,1,0,0,0,194,
192,1,0,0,0,194,195,1,0,0,0,195,197,1,0,0,0,196,194,1,0,0,0,197,198,5,34,
0,0,198,36,1,0,0,0,199,201,3,67,33,0,200,199,1,0,0,0,201,202,1,0,0,0,202,
200,1,0,0,0,202,203,1,0,0,0,203,38,1,0,0,0,204,205,5,35,0,0,205,206,5,91,
0,0,206,207,1,0,0,0,207,208,3,63,31,0,208,209,5,93,0,0,209,210,1,0,0,0,210,
211,6,19,0,0,211,40,1,0,0,0,212,216,5,35,0,0,213,215,8,2,0,0,214,213,1,0,
0,0,215,218,1,0,0,0,216,214,1,0,0,0,216,217,1,0,0,0,217,219,1,0,0,0,218,
216,1,0,0,0,219,220,6,20,0,0,220,42,1,0,0,0,221,223,5,13,0,0,222,221,1,0,
0,0,222,223,1,0,0,0,223,224,1,0,0,0,224,225,5,10,0,0,225,226,4,21,0,0,226,
227,1,0,0,0,227,228,6,21,1,0,228,44,1,0,0,0,229,231,5,13,0,0,230,229,1,0,
0,0,230,231,1,0,0,0,231,232,1,0,0,0,232,233,5,10,0,0,233,234,4,22,1,0,234,
235,1,0,0,0,235,236,6,22,1,0,236,46,1,0,0,0,237,239,6,23,2,0,238,240,5,13,
0,0,239,238,1,0,0,0,239,240,1,0,0,0,240,241,1,0,0,0,241,242,5,10,0,0,242,
48,1,0,0,0,243,245,7,3,0,0,244,243,1,0,0,0,245,246,1,0,0,0,246,244,1,0,0,
0,246,247,1,0,0,0,247,248,1,0,0,0,248,249,6,24,1,0,249,50,1,0,0,0,250,251,
5,40,0,0,251,252,6,25,3,0,252,52,1,0,0,0,253,254,5,41,0,0,254,255,6,26,4,
0,255,54,1,0,0,0,256,260,3,57,28,0,257,260,3,59,29,0,258,260,3,61,30,0,259,
256,1,0,0,0,259,257,1,0,0,0,259,258,1,0,0,0,260,56,1,0,0,0,261,262,5,92,
0,0,262,263,8,4,0,0,263,58,1,0,0,0,264,265,5,92,0,0,265,271,5,116,0,0,266,
267,5,92,0,0,267,271,5,114,0,0,268,269,5,92,0,0,269,271,5,110,0,0,270,264,
1,0,0,0,270,266,1,0,0,0,270,268,1,0,0,0,271,60,1,0,0,0,272,273,5,92,0,0,
273,274,5,59,0,0,274,62,1,0,0,0,275,276,5,61,0,0,276,277,3,63,31,0,277,278,
5,61,0,0,278,288,1,0,0,0,279,283,5,91,0,0,280,282,9,0,0,0,281,280,1,0,0,
0,282,285,1,0,0,0,283,284,1,0,0,0,283,281,1,0,0,0,284,286,1,0,0,0,285,283,
1,0,0,0,286,288,5,93,0,0,287,275,1,0,0,0,287,279,1,0,0,0,288,64,1,0,0,0,
289,294,8,5,0,0,290,294,3,55,27,0,291,292,5,92,0,0,292,294,3,47,23,0,293,
289,1,0,0,0,293,290,1,0,0,0,293,291,1,0,0,0,294,66,1,0,0,0,295,298,8,6,0,
0,296,298,3,55,27,0,297,295,1,0,0,0,297,296,1,0,0,0,298,68,1,0,0,0,15,0,
183,194,202,216,222,230,239,246,259,270,283,287,293,297,5,0,1,0,6,0,0,1,
23,0,1,25,1,1,26,2];
const atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN);
@ -111,17 +113,18 @@ export default class CMakeLexer extends antlr4.Lexer {
static literalNames = [ null, "'if'", "'elseif'", "'else'", "'endif'",
"'foreach'", "'endforeach'", "'while'", "'endwhile'",
"'break'", "'continue'", "'function'", "'endfunction'",
"'macro'", "'endmacro'", null, null, null, null,
null, null, null, null, null, null, "'('", "')'" ];
"'macro'", "'endmacro'", "'set'", null, null, null,
null, null, null, null, null, null, null, "'('",
"')'" ];
static symbolicNames = [ null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, "ID",
"BracketArgument", "QuotedArgument", "UnquotedArgument",
null, null, null, null, null, null, null, null,
"ID", "BracketArgument", "QuotedArgument", "UnquotedArgument",
"BracketComment", "LineComment", "IgnoreNLBetweenArgs",
"IgnoreExtraNLBetweenCmds", "NL", "WS", "LParen",
"RParen", "Escape" ];
static ruleNames = [ "T__0", "T__1", "T__2", "T__3", "T__4", "T__5", "T__6",
"T__7", "T__8", "T__9", "T__10", "T__11", "T__12",
"T__13", "ID", "BracketArgument", "QuotedArgument",
"T__13", "T__14", "ID", "BracketArgument", "QuotedArgument",
"UnquotedArgument", "BracketComment", "LineComment",
"IgnoreNLBetweenArgs", "IgnoreExtraNLBetweenCmds",
"NL", "WS", "LParen", "RParen", "Escape", "EscapeIdentity",
@ -157,29 +160,30 @@ CMakeLexer.T__10 = 11;
CMakeLexer.T__11 = 12;
CMakeLexer.T__12 = 13;
CMakeLexer.T__13 = 14;
CMakeLexer.ID = 15;
CMakeLexer.BracketArgument = 16;
CMakeLexer.QuotedArgument = 17;
CMakeLexer.UnquotedArgument = 18;
CMakeLexer.BracketComment = 19;
CMakeLexer.LineComment = 20;
CMakeLexer.IgnoreNLBetweenArgs = 21;
CMakeLexer.IgnoreExtraNLBetweenCmds = 22;
CMakeLexer.NL = 23;
CMakeLexer.WS = 24;
CMakeLexer.LParen = 25;
CMakeLexer.RParen = 26;
CMakeLexer.Escape = 27;
CMakeLexer.T__14 = 15;
CMakeLexer.ID = 16;
CMakeLexer.BracketArgument = 17;
CMakeLexer.QuotedArgument = 18;
CMakeLexer.UnquotedArgument = 19;
CMakeLexer.BracketComment = 20;
CMakeLexer.LineComment = 21;
CMakeLexer.IgnoreNLBetweenArgs = 22;
CMakeLexer.IgnoreExtraNLBetweenCmds = 23;
CMakeLexer.NL = 24;
CMakeLexer.WS = 25;
CMakeLexer.LParen = 26;
CMakeLexer.RParen = 27;
CMakeLexer.Escape = 28;
CMakeLexer.prototype.action = function(localctx, ruleIndex, actionIndex) {
switch (ruleIndex) {
case 22:
case 23:
this.NL_action(localctx, actionIndex);
break;
case 24:
case 25:
this.LParen_action(localctx, actionIndex);
break;
case 25:
case 26:
this.RParen_action(localctx, actionIndex);
break;
default:
@ -219,9 +223,9 @@ CMakeLexer.prototype.RParen_action = function(localctx , actionIndex) {
};
CMakeLexer.prototype.sempred = function(localctx, ruleIndex, predIndex) {
switch (ruleIndex) {
case 20:
return this.IgnoreNLBetweenArgs_sempred(localctx, predIndex);
case 21:
return this.IgnoreNLBetweenArgs_sempred(localctx, predIndex);
case 22:
return this.IgnoreExtraNLBetweenCmds_sempred(localctx, predIndex);
default:
throw "No registered predicate for:" + ruleIndex;

View File

@ -140,6 +140,15 @@ export default class CMakeListener extends antlr4.tree.ParseTreeListener {
}
// Enter a parse tree produced by CMakeParser#SetCmd.
enterSetCmd(ctx) {
}
// Exit a parse tree produced by CMakeParser#SetCmd.
exitSetCmd(ctx) {
}
// Enter a parse tree produced by CMakeParser#OtherCmd.
enterOtherCmd(ctx) {
}

View File

@ -2,7 +2,7 @@
// jshint ignore: start
import antlr4 from './antlr4/index.js';
import CMakeListener from './CMakeListener.js';
const serializedATN = [4,1,27,156,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,5,
const serializedATN = [4,1,28,165,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,5,
0,10,8,0,10,0,12,0,13,9,0,1,0,1,0,1,1,1,1,1,1,5,1,20,8,1,10,1,12,1,23,9,
1,1,1,1,1,1,1,1,1,5,1,29,8,1,10,1,12,1,32,9,1,1,1,1,1,1,1,1,1,5,1,38,8,1,
10,1,12,1,41,9,1,1,1,1,1,1,1,1,1,5,1,47,8,1,10,1,12,1,50,9,1,1,1,1,1,1,1,
@ -11,48 +11,51 @@ const serializedATN = [4,1,27,156,2,0,7,0,2,1,7,1,2,2,7,2,1,0,1,0,1,0,5,
1,10,1,12,1,86,9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,4,1,98,8,1,11,
1,12,1,99,1,1,1,1,1,1,1,1,1,1,5,1,107,8,1,10,1,12,1,110,9,1,1,1,1,1,1,1,
1,1,4,1,116,8,1,11,1,12,1,117,1,1,1,1,1,1,1,1,1,1,5,1,125,8,1,10,1,12,1,
128,9,1,1,1,1,1,1,1,1,1,5,1,134,8,1,10,1,12,1,137,9,1,1,1,3,1,140,8,1,1,
2,1,2,1,2,1,2,1,2,1,2,5,2,148,8,2,10,2,12,2,151,9,2,1,2,3,2,154,8,2,1,2,
0,0,3,0,2,4,0,0,185,0,11,1,0,0,0,2,139,1,0,0,0,4,153,1,0,0,0,6,7,3,2,1,0,
7,8,5,23,0,0,8,10,1,0,0,0,9,6,1,0,0,0,10,13,1,0,0,0,11,9,1,0,0,0,11,12,1,
0,0,0,12,14,1,0,0,0,13,11,1,0,0,0,14,15,5,0,0,1,15,1,1,0,0,0,16,17,5,1,0,
0,17,21,5,25,0,0,18,20,3,4,2,0,19,18,1,0,0,0,20,23,1,0,0,0,21,19,1,0,0,0,
21,22,1,0,0,0,22,24,1,0,0,0,23,21,1,0,0,0,24,140,5,26,0,0,25,26,5,2,0,0,
26,30,5,25,0,0,27,29,3,4,2,0,28,27,1,0,0,0,29,32,1,0,0,0,30,28,1,0,0,0,30,
31,1,0,0,0,31,33,1,0,0,0,32,30,1,0,0,0,33,140,5,26,0,0,34,35,5,3,0,0,35,
39,5,25,0,0,36,38,3,4,2,0,37,36,1,0,0,0,38,41,1,0,0,0,39,37,1,0,0,0,39,40,
1,0,0,0,40,42,1,0,0,0,41,39,1,0,0,0,42,140,5,26,0,0,43,44,5,4,0,0,44,48,
5,25,0,0,45,47,3,4,2,0,46,45,1,0,0,0,47,50,1,0,0,0,48,46,1,0,0,0,48,49,1,
0,0,0,49,51,1,0,0,0,50,48,1,0,0,0,51,140,5,26,0,0,52,53,5,5,0,0,53,55,5,
25,0,0,54,56,3,4,2,0,55,54,1,0,0,0,56,57,1,0,0,0,57,55,1,0,0,0,57,58,1,0,
0,0,58,59,1,0,0,0,59,60,5,26,0,0,60,140,1,0,0,0,61,62,5,6,0,0,62,66,5,25,
0,0,63,65,3,4,2,0,64,63,1,0,0,0,65,68,1,0,0,0,66,64,1,0,0,0,66,67,1,0,0,
0,67,69,1,0,0,0,68,66,1,0,0,0,69,140,5,26,0,0,70,71,5,7,0,0,71,73,5,25,0,
0,72,74,3,4,2,0,73,72,1,0,0,0,74,75,1,0,0,0,75,73,1,0,0,0,75,76,1,0,0,0,
76,77,1,0,0,0,77,78,5,26,0,0,78,140,1,0,0,0,79,80,5,8,0,0,80,84,5,25,0,0,
81,83,3,4,2,0,82,81,1,0,0,0,83,86,1,0,0,0,84,82,1,0,0,0,84,85,1,0,0,0,85,
87,1,0,0,0,86,84,1,0,0,0,87,140,5,26,0,0,88,89,5,9,0,0,89,90,5,25,0,0,90,
140,5,26,0,0,91,92,5,10,0,0,92,93,5,25,0,0,93,140,5,26,0,0,94,95,5,11,0,
0,95,97,5,25,0,0,96,98,3,4,2,0,97,96,1,0,0,0,98,99,1,0,0,0,99,97,1,0,0,0,
99,100,1,0,0,0,100,101,1,0,0,0,101,102,5,26,0,0,102,140,1,0,0,0,103,104,
5,12,0,0,104,108,5,25,0,0,105,107,3,4,2,0,106,105,1,0,0,0,107,110,1,0,0,
0,108,106,1,0,0,0,108,109,1,0,0,0,109,111,1,0,0,0,110,108,1,0,0,0,111,140,
5,26,0,0,112,113,5,13,0,0,113,115,5,25,0,0,114,116,3,4,2,0,115,114,1,0,0,
0,116,117,1,0,0,0,117,115,1,0,0,0,117,118,1,0,0,0,118,119,1,0,0,0,119,120,
5,26,0,0,120,140,1,0,0,0,121,122,5,14,0,0,122,126,5,25,0,0,123,125,3,4,2,
0,124,123,1,0,0,0,125,128,1,0,0,0,126,124,1,0,0,0,126,127,1,0,0,0,127,129,
1,0,0,0,128,126,1,0,0,0,129,140,5,26,0,0,130,131,5,15,0,0,131,135,5,25,0,
0,132,134,3,4,2,0,133,132,1,0,0,0,134,137,1,0,0,0,135,133,1,0,0,0,135,136,
1,0,0,0,136,138,1,0,0,0,137,135,1,0,0,0,138,140,5,26,0,0,139,16,1,0,0,0,
139,25,1,0,0,0,139,34,1,0,0,0,139,43,1,0,0,0,139,52,1,0,0,0,139,61,1,0,0,
0,139,70,1,0,0,0,139,79,1,0,0,0,139,88,1,0,0,0,139,91,1,0,0,0,139,94,1,0,
0,0,139,103,1,0,0,0,139,112,1,0,0,0,139,121,1,0,0,0,139,130,1,0,0,0,140,
3,1,0,0,0,141,154,5,17,0,0,142,154,5,16,0,0,143,154,5,18,0,0,144,154,5,15,
0,0,145,149,5,25,0,0,146,148,3,4,2,0,147,146,1,0,0,0,148,151,1,0,0,0,149,
147,1,0,0,0,149,150,1,0,0,0,150,152,1,0,0,0,151,149,1,0,0,0,152,154,5,26,
0,0,153,141,1,0,0,0,153,142,1,0,0,0,153,143,1,0,0,0,153,144,1,0,0,0,153,
145,1,0,0,0,154,5,1,0,0,0,17,11,21,30,39,48,57,66,75,84,99,108,117,126,135,
139,149,153];
128,9,1,1,1,1,1,1,1,1,1,4,1,134,8,1,11,1,12,1,135,1,1,1,1,1,1,1,1,1,1,5,
1,143,8,1,10,1,12,1,146,9,1,1,1,3,1,149,8,1,1,2,1,2,1,2,1,2,1,2,1,2,5,2,
157,8,2,10,2,12,2,160,9,2,1,2,3,2,163,8,2,1,2,0,0,3,0,2,4,0,0,196,0,11,1,
0,0,0,2,148,1,0,0,0,4,162,1,0,0,0,6,7,3,2,1,0,7,8,5,24,0,0,8,10,1,0,0,0,
9,6,1,0,0,0,10,13,1,0,0,0,11,9,1,0,0,0,11,12,1,0,0,0,12,14,1,0,0,0,13,11,
1,0,0,0,14,15,5,0,0,1,15,1,1,0,0,0,16,17,5,1,0,0,17,21,5,26,0,0,18,20,3,
4,2,0,19,18,1,0,0,0,20,23,1,0,0,0,21,19,1,0,0,0,21,22,1,0,0,0,22,24,1,0,
0,0,23,21,1,0,0,0,24,149,5,27,0,0,25,26,5,2,0,0,26,30,5,26,0,0,27,29,3,4,
2,0,28,27,1,0,0,0,29,32,1,0,0,0,30,28,1,0,0,0,30,31,1,0,0,0,31,33,1,0,0,
0,32,30,1,0,0,0,33,149,5,27,0,0,34,35,5,3,0,0,35,39,5,26,0,0,36,38,3,4,2,
0,37,36,1,0,0,0,38,41,1,0,0,0,39,37,1,0,0,0,39,40,1,0,0,0,40,42,1,0,0,0,
41,39,1,0,0,0,42,149,5,27,0,0,43,44,5,4,0,0,44,48,5,26,0,0,45,47,3,4,2,0,
46,45,1,0,0,0,47,50,1,0,0,0,48,46,1,0,0,0,48,49,1,0,0,0,49,51,1,0,0,0,50,
48,1,0,0,0,51,149,5,27,0,0,52,53,5,5,0,0,53,55,5,26,0,0,54,56,3,4,2,0,55,
54,1,0,0,0,56,57,1,0,0,0,57,55,1,0,0,0,57,58,1,0,0,0,58,59,1,0,0,0,59,60,
5,27,0,0,60,149,1,0,0,0,61,62,5,6,0,0,62,66,5,26,0,0,63,65,3,4,2,0,64,63,
1,0,0,0,65,68,1,0,0,0,66,64,1,0,0,0,66,67,1,0,0,0,67,69,1,0,0,0,68,66,1,
0,0,0,69,149,5,27,0,0,70,71,5,7,0,0,71,73,5,26,0,0,72,74,3,4,2,0,73,72,1,
0,0,0,74,75,1,0,0,0,75,73,1,0,0,0,75,76,1,0,0,0,76,77,1,0,0,0,77,78,5,27,
0,0,78,149,1,0,0,0,79,80,5,8,0,0,80,84,5,26,0,0,81,83,3,4,2,0,82,81,1,0,
0,0,83,86,1,0,0,0,84,82,1,0,0,0,84,85,1,0,0,0,85,87,1,0,0,0,86,84,1,0,0,
0,87,149,5,27,0,0,88,89,5,9,0,0,89,90,5,26,0,0,90,149,5,27,0,0,91,92,5,10,
0,0,92,93,5,26,0,0,93,149,5,27,0,0,94,95,5,11,0,0,95,97,5,26,0,0,96,98,3,
4,2,0,97,96,1,0,0,0,98,99,1,0,0,0,99,97,1,0,0,0,99,100,1,0,0,0,100,101,1,
0,0,0,101,102,5,27,0,0,102,149,1,0,0,0,103,104,5,12,0,0,104,108,5,26,0,0,
105,107,3,4,2,0,106,105,1,0,0,0,107,110,1,0,0,0,108,106,1,0,0,0,108,109,
1,0,0,0,109,111,1,0,0,0,110,108,1,0,0,0,111,149,5,27,0,0,112,113,5,13,0,
0,113,115,5,26,0,0,114,116,3,4,2,0,115,114,1,0,0,0,116,117,1,0,0,0,117,115,
1,0,0,0,117,118,1,0,0,0,118,119,1,0,0,0,119,120,5,27,0,0,120,149,1,0,0,0,
121,122,5,14,0,0,122,126,5,26,0,0,123,125,3,4,2,0,124,123,1,0,0,0,125,128,
1,0,0,0,126,124,1,0,0,0,126,127,1,0,0,0,127,129,1,0,0,0,128,126,1,0,0,0,
129,149,5,27,0,0,130,131,5,15,0,0,131,133,5,26,0,0,132,134,3,4,2,0,133,132,
1,0,0,0,134,135,1,0,0,0,135,133,1,0,0,0,135,136,1,0,0,0,136,137,1,0,0,0,
137,138,5,27,0,0,138,149,1,0,0,0,139,140,5,16,0,0,140,144,5,26,0,0,141,143,
3,4,2,0,142,141,1,0,0,0,143,146,1,0,0,0,144,142,1,0,0,0,144,145,1,0,0,0,
145,147,1,0,0,0,146,144,1,0,0,0,147,149,5,27,0,0,148,16,1,0,0,0,148,25,1,
0,0,0,148,34,1,0,0,0,148,43,1,0,0,0,148,52,1,0,0,0,148,61,1,0,0,0,148,70,
1,0,0,0,148,79,1,0,0,0,148,88,1,0,0,0,148,91,1,0,0,0,148,94,1,0,0,0,148,
103,1,0,0,0,148,112,1,0,0,0,148,121,1,0,0,0,148,130,1,0,0,0,148,139,1,0,
0,0,149,3,1,0,0,0,150,163,5,18,0,0,151,163,5,17,0,0,152,163,5,19,0,0,153,
163,5,16,0,0,154,158,5,26,0,0,155,157,3,4,2,0,156,155,1,0,0,0,157,160,1,
0,0,0,158,156,1,0,0,0,158,159,1,0,0,0,159,161,1,0,0,0,160,158,1,0,0,0,161,
163,5,27,0,0,162,150,1,0,0,0,162,151,1,0,0,0,162,152,1,0,0,0,162,153,1,0,
0,0,162,154,1,0,0,0,163,5,1,0,0,0,18,11,21,30,39,48,57,66,75,84,99,108,117,
126,135,144,148,158,162];
const atn = new antlr4.atn.ATNDeserializer().deserialize(serializedATN);
@ -67,14 +70,15 @@ export default class CMakeParser extends antlr4.Parser {
static literalNames = [ null, "'if'", "'elseif'", "'else'", "'endif'",
"'foreach'", "'endforeach'", "'while'", "'endwhile'",
"'break'", "'continue'", "'function'", "'endfunction'",
"'macro'", "'endmacro'", null, null, null, null,
null, null, null, null, null, null, "'('", "')'" ];
"'macro'", "'endmacro'", "'set'", null, null,
null, null, null, null, null, null, null, null,
"'('", "')'" ];
static symbolicNames = [ null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null, "ID",
"BracketArgument", "QuotedArgument", "UnquotedArgument",
"BracketComment", "LineComment", "IgnoreNLBetweenArgs",
"IgnoreExtraNLBetweenCmds", "NL", "WS", "LParen",
"RParen", "Escape" ];
null, null, null, null, null, null, null, null,
"ID", "BracketArgument", "QuotedArgument",
"UnquotedArgument", "BracketComment", "LineComment",
"IgnoreNLBetweenArgs", "IgnoreExtraNLBetweenCmds",
"NL", "WS", "LParen", "RParen", "Escape" ];
static ruleNames = [ "file", "command", "argument" ];
constructor(input) {
@ -100,7 +104,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 11;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 65534) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 131070) !== 0)) {
this.state = 6;
this.command();
this.state = 7;
@ -132,7 +136,7 @@ export default class CMakeParser extends antlr4.Parser {
this.enterRule(localctx, 2, CMakeParser.RULE_command);
var _la = 0; // Token type
try {
this.state = 139;
this.state = 148;
this._errHandler.sync(this);
switch(this._input.LA(1)) {
case 1:
@ -145,7 +149,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 21;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 18;
this.argument();
this.state = 23;
@ -165,7 +169,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 30;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 27;
this.argument();
this.state = 32;
@ -185,7 +189,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 39;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 36;
this.argument();
this.state = 41;
@ -205,7 +209,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 48;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 45;
this.argument();
this.state = 50;
@ -231,7 +235,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 57;
this._errHandler.sync(this);
_la = this._input.LA(1);
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0));
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0));
this.state = 59;
this.match(CMakeParser.RParen);
break;
@ -245,7 +249,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 66;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 63;
this.argument();
this.state = 68;
@ -271,7 +275,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 75;
this._errHandler.sync(this);
_la = this._input.LA(1);
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0));
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0));
this.state = 77;
this.match(CMakeParser.RParen);
break;
@ -285,7 +289,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 84;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 81;
this.argument();
this.state = 86;
@ -331,7 +335,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 99;
this._errHandler.sync(this);
_la = this._input.LA(1);
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0));
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0));
this.state = 101;
this.match(CMakeParser.RParen);
break;
@ -345,7 +349,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 108;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 105;
this.argument();
this.state = 110;
@ -371,7 +375,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 117;
this._errHandler.sync(this);
_la = this._input.LA(1);
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0));
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0));
this.state = 119;
this.match(CMakeParser.RParen);
break;
@ -385,7 +389,7 @@ export default class CMakeParser extends antlr4.Parser {
this.state = 126;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 123;
this.argument();
this.state = 128;
@ -396,23 +400,43 @@ export default class CMakeParser extends antlr4.Parser {
this.match(CMakeParser.RParen);
break;
case 15:
localctx = new OtherCmdContext(this, localctx);
localctx = new SetCmdContext(this, localctx);
this.enterOuterAlt(localctx, 15);
this.state = 130;
this.match(CMakeParser.ID);
this.match(CMakeParser.T__14);
this.state = 131;
this.match(CMakeParser.LParen);
this.state = 135;
this.state = 133;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
do {
this.state = 132;
this.argument();
this.state = 137;
this.state = 135;
this._errHandler.sync(this);
_la = this._input.LA(1);
} while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0));
this.state = 137;
this.match(CMakeParser.RParen);
break;
case 16:
localctx = new OtherCmdContext(this, localctx);
this.enterOuterAlt(localctx, 16);
this.state = 139;
this.match(CMakeParser.ID);
this.state = 140;
this.match(CMakeParser.LParen);
this.state = 144;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 141;
this.argument();
this.state = 146;
this._errHandler.sync(this);
_la = this._input.LA(1);
}
this.state = 138;
this.state = 147;
this.match(CMakeParser.RParen);
break;
default:
@ -439,44 +463,44 @@ export default class CMakeParser extends antlr4.Parser {
this.enterRule(localctx, 4, CMakeParser.RULE_argument);
var _la = 0; // Token type
try {
this.state = 153;
this.state = 162;
this._errHandler.sync(this);
switch(this._input.LA(1)) {
case 17:
case 18:
this.enterOuterAlt(localctx, 1);
this.state = 141;
this.state = 150;
this.match(CMakeParser.QuotedArgument);
break;
case 16:
case 17:
this.enterOuterAlt(localctx, 2);
this.state = 142;
this.state = 151;
this.match(CMakeParser.BracketArgument);
break;
case 18:
case 19:
this.enterOuterAlt(localctx, 3);
this.state = 143;
this.state = 152;
this.match(CMakeParser.UnquotedArgument);
break;
case 15:
case 16:
this.enterOuterAlt(localctx, 4);
this.state = 144;
this.state = 153;
this.match(CMakeParser.ID);
break;
case 25:
case 26:
this.enterOuterAlt(localctx, 5);
this.state = 145;
this.state = 154;
this.match(CMakeParser.LParen);
this.state = 149;
this.state = 158;
this._errHandler.sync(this);
_la = this._input.LA(1);
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 34045952) !== 0)) {
this.state = 146;
while((((_la) & ~0x1f) == 0 && ((1 << _la) & 68091904) !== 0)) {
this.state = 155;
this.argument();
this.state = 151;
this.state = 160;
this._errHandler.sync(this);
_la = this._input.LA(1);
}
this.state = 152;
this.state = 161;
this.match(CMakeParser.RParen);
break;
default:
@ -514,19 +538,20 @@ CMakeParser.T__10 = 11;
CMakeParser.T__11 = 12;
CMakeParser.T__12 = 13;
CMakeParser.T__13 = 14;
CMakeParser.ID = 15;
CMakeParser.BracketArgument = 16;
CMakeParser.QuotedArgument = 17;
CMakeParser.UnquotedArgument = 18;
CMakeParser.BracketComment = 19;
CMakeParser.LineComment = 20;
CMakeParser.IgnoreNLBetweenArgs = 21;
CMakeParser.IgnoreExtraNLBetweenCmds = 22;
CMakeParser.NL = 23;
CMakeParser.WS = 24;
CMakeParser.LParen = 25;
CMakeParser.RParen = 26;
CMakeParser.Escape = 27;
CMakeParser.T__14 = 15;
CMakeParser.ID = 16;
CMakeParser.BracketArgument = 17;
CMakeParser.QuotedArgument = 18;
CMakeParser.UnquotedArgument = 19;
CMakeParser.BracketComment = 20;
CMakeParser.LineComment = 21;
CMakeParser.IgnoreNLBetweenArgs = 22;
CMakeParser.IgnoreExtraNLBetweenCmds = 23;
CMakeParser.NL = 24;
CMakeParser.WS = 25;
CMakeParser.LParen = 26;
CMakeParser.RParen = 27;
CMakeParser.Escape = 28;
CMakeParser.RULE_file = 0;
CMakeParser.RULE_command = 1;
@ -1240,6 +1265,49 @@ class ElseCmdContext extends CommandContext {
CMakeParser.ElseCmdContext = ElseCmdContext;
class SetCmdContext extends CommandContext {
constructor(parser, ctx) {
super(parser);
super.copyFrom(ctx);
}
LParen() {
return this.getToken(CMakeParser.LParen, 0);
};
RParen() {
return this.getToken(CMakeParser.RParen, 0);
};
argument = function(i) {
if(i===undefined) {
i = null;
}
if(i===null) {
return this.getTypedRuleContexts(ArgumentContext);
} else {
return this.getTypedRuleContext(ArgumentContext,i);
}
};
enterRule(listener) {
if(listener instanceof CMakeListener ) {
listener.enterSetCmd(this);
}
}
exitRule(listener) {
if(listener instanceof CMakeListener ) {
listener.exitSetCmd(this);
}
}
}
CMakeParser.SetCmdContext = SetCmdContext;
class ArgumentContext extends antlr4.ParserRuleContext {
constructor(parser, parent, invokingState) {

View File

@ -3,7 +3,10 @@ import {
ProposedFeatures, SignatureHelpParams, TextDocuments, TextDocumentSyncKind
} from 'vscode-languageserver/node';
import { CompletionItemKind, CompletionParams, DocumentFormattingParams } from 'vscode-languageserver-protocol';
import {
CompletionItemKind, CompletionParams, DocumentFormattingParams,
DocumentSymbolParams
} from 'vscode-languageserver-protocol';
import { Range, TextDocument } from 'vscode-languageserver-textdocument';
import { CompletionItem, CompletionItemTag, Position } from 'vscode-languageserver-types';
@ -14,6 +17,7 @@ import antlr4 from './parser/antlr4/index.js';
import CMakeLexer from './parser/CMakeLexer.js';
import CMakeParser from './parser/CMakeParser.js';
import { Entries, getBuiltinEntries } from './utils';
import { SymbolListener } from './symbols';
const entries: Entries = getBuiltinEntries();
const modules = entries[0].split('\n');
@ -38,7 +42,8 @@ connection.onInitialize((params: InitializeParams) => {
retriggerCharacters: [' ']
},
completionProvider: {},
documentFormattingProvider: true
documentFormattingProvider: true,
documentSymbolProvider: true
},
serverInfo: {
name: 'cmakels',
@ -156,6 +161,20 @@ connection.onDocumentFormatting((params: DocumentFormattingParams) => {
});
});
connection.onDocumentSymbol((params: DocumentSymbolParams) => {
const document = documents.get(params.textDocument.uri);
return new Promise((resolve, reject) => {
const input = antlr4.CharStreams.fromString(document.getText());
const lexer = new CMakeLexer(input);
const tokenStream = new antlr4.CommonTokenStream(lexer);
const parser = new CMakeParser(tokenStream);
const tree = parser.file();
const symbolListener = new SymbolListener();
antlr4.tree.ParseTreeWalker.DEFAULT.walk(symbolListener, tree);
resolve(symbolListener.getSymbols());
});
});
// The content of a text document has changed. This event is emitted
// when the text document first opened or when its content has changed.
documents.onDidChangeContent(change => {

68
server/src/symbols.ts Normal file
View File

@ -0,0 +1,68 @@
import CMakeListener from "./parser/CMakeListener";
import { DocumentSymbol, SymbolKind } from "vscode-languageserver-protocol";
export class SymbolListener extends CMakeListener {
private _symbols: DocumentSymbol[] = [];
private _inFunction: boolean = false;
private _functionSymbol: DocumentSymbol;
private makeSymbol(token: any, kind: SymbolKind): DocumentSymbol {
return {
name: token.text,
kind: kind,
range: {
start: {
line: token.line - 1,
character: token.column
},
end: {
line: token.line - 1,
character: token.column + token.text.length
}
},
selectionRange: {
start: {
line: token.line - 1,
character: token.column
},
end: {
line: token.line - 1,
character: token.column + token.text.length
}
}
};
}
enterSetCmd(ctx: any): void {
const argumentCtx = ctx.argument(0);
if (this._inFunction) {
this._functionSymbol.children.push(this.makeSymbol(argumentCtx.start, SymbolKind.Variable));
} else {
this._symbols.push(this.makeSymbol(argumentCtx.start, SymbolKind.Variable));
}
}
enterFunctionCmd(ctx: any): void {
this._inFunction = true;
const argumentCtx = ctx.argument(0);
this._functionSymbol = this.makeSymbol(argumentCtx.start, SymbolKind.Function);
this._functionSymbol.children = [];
}
enterEndFunctionCmd(ctx: any): void {
this._inFunction = false;
this._symbols.push(this._functionSymbol);
}
enterMacroCmd(ctx: any): void {
this.enterFunctionCmd(ctx);
}
enterEndMacroCmd(ctx: any): void {
this.enterEndFunctionCmd(ctx);
}
getSymbols(): DocumentSymbol[] {
return this._symbols;
}
}