Skip to content

Commit

Permalink
Merge pull request #36 from doxygen/master
Browse files Browse the repository at this point in the history
Various fixes to better support doxygen's lexer files
  • Loading branch information
babyraging authored Nov 12, 2024
2 parents b20c71d + 8a11c4f commit 04de4de
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/languages/lexLanguageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export enum TokenType {
Unknown,
Divider,
Escape,
CharRange,
EOL,
EOS
}
Expand Down
21 changes: 18 additions & 3 deletions src/languages/parser/lexParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createScanner } from "./lexScanner";
import { TokenType } from "../lexLanguageTypes";
import { ScannerState, TokenType } from "../lexLanguageTypes";
import { binarySearch } from "./utils";
import { Problem, ProblemType, ProblemRelated } from "../common";

Expand Down Expand Up @@ -114,9 +114,10 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
let codeOffset = 0;
let tokenText = '';
let acceptingStates = false;
let lastToken = token;
let isConditionScope = false;
let lastToken = TokenType.Invalid;
while (end < 0 && token !== TokenType.EOS) {
//console.log('parse(type='+TokenType[token]+',token='+scanner.getTokenText()+',state='+ParserState[state]+')');
offset = scanner.getTokenOffset();
switch (token) {
case TokenType.StartCode:
Expand Down Expand Up @@ -203,6 +204,7 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
case ParserState.WaitingRule:
switch (token) {
case TokenType.Literal:
case TokenType.CharRange:
case TokenType.Word:
break;
case TokenType.Predefined:
Expand Down Expand Up @@ -294,6 +296,19 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
end: scanner.getTokenEnd()
});
break;
case TokenType.Action:
tokenText = scanner.getTokenText();
if (/^[a-zA-Z]\w*$/.test(tokenText))
document.components.push({
name: tokenText,
offset: offset,
length: scanner.getTokenLength(),
end: scanner.getTokenEnd(),
used: true,
definition: [-1, -1],
references: [[offset, scanner.getTokenEnd()]]
});
break;
}
break;
}
Expand Down Expand Up @@ -346,4 +361,4 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
});

return document;
}
}
33 changes: 31 additions & 2 deletions src/languages/parser/lexScanner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TokenType, ScannerState, Scanner } from '../lexLanguageTypes'
import { MultiLineStream, _FSL, _AST, _NWL, _PCS, _BOP, _LAN, _BAR, _WSP, _DQO, _SQO, _BCL, _RAN, _BSL } from './utils';
import { MultiLineStream, _FSL, _AST, _NWL, _PCS, _BOP, _LAN, _BAR, _WSP, _DQO, _SQO, _BCL, _RAN, _BSL, _SBO } from './utils';

export function createScanner(input: string, initialOffset = 0, initialState: ScannerState = ScannerState.WithinContent): Scanner {
const stream = new MultiLineStream(input, initialOffset);
Expand All @@ -17,6 +17,10 @@ export function createScanner(input: string, initialOffset = 0, initialState: Sc
return stream.advanceIfRegExp(/^("(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')/);
}

function nextCharacterRange(): string {
return stream.advanceIfRegExp(/^((?<!\\\\)\[(.*?)(?<!\\\\)\])/);
}

function finishToken(offset: number, type: TokenType, errorMessage?: string): TokenType {
tokenType = type;
tokenOffset = offset;
Expand All @@ -41,6 +45,8 @@ export function createScanner(input: string, initialOffset = 0, initialState: Sc
stream.advance(1);
return finishToken(offset, TokenType.Unknown);
}
//console.log('scan('+stream.getSource().substring(tokenOffset, stream.pos())+
// ',state='+ScannerState[state]+',oldState='+ScannerState[oldState]+')');
return token;
}

Expand All @@ -62,7 +68,19 @@ export function createScanner(input: string, initialOffset = 0, initialState: Sc
}

if (white) {
return finishToken(offset, TokenType.Divider);
// only allow comments to start after white space at the start of a line
if (stream.peekChar(0)==_FSL && (stream.peekChar(1)==_AST || stream.peekChar(1)==_FSL)) {
if (stream.peekChar(1)==_AST) { // /*
state = ScannerState.WithinComment;
return finishToken(offset, TokenType.StartComment);
} else { // //
stream.advanceUntilChar(_NWL);
stream.advance(1);
return finishToken(offset, TokenType.Comment);
}
} else {
return finishToken(offset, TokenType.Divider);
}
}

switch (state) {
Expand Down Expand Up @@ -105,6 +123,9 @@ export function createScanner(input: string, initialOffset = 0, initialState: Sc
case _BOP: // {
state = ScannerState.WithinAction;
return finishToken(offset, TokenType.StartAction);
case _BCL: // }
state = ScannerState.WithinContent;
break;
case _WSP: // ' '
stream.advanceUntilChar(_NWL);
return finishToken(offset, TokenType.Invalid);
Expand All @@ -122,6 +143,14 @@ export function createScanner(input: string, initialOffset = 0, initialState: Sc
case _BSL: // \
stream.advance(1); // include the next escaped character
return finishToken(offset, TokenType.Escape);
case _SBO: // [
stream.goBack(1);
const charRange = nextCharacterRange()
if (charRange.length > 0) {
return finishToken(offset, TokenType.CharRange);
}
stream.advance(1);
return finishToken(offset, TokenType.Unknown);
}

stream.goBack(1);
Expand Down
2 changes: 1 addition & 1 deletion src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ export function runSafe<T>(func: () => T, errorVal: T, errorMessage: string, tok

function cancelValue<E>() {
console.log("Request cancelled...");
return undefined;
return undefined as unknown as E;
}
22 changes: 21 additions & 1 deletion syntaxes/lex.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
{
"include": "#comments"
},
{
"include": "#comment"
},
{
"include": "#strings"
}
Expand All @@ -58,6 +61,9 @@
{
"include": "#comments"
},
{
"include": "#comment"
},
{
"include": "#brackets"
},
Expand Down Expand Up @@ -178,7 +184,7 @@
},
"startcondition_block": {
"name": "entity.startcondition.lex",
"begin": "<[a-zA-Z0-9_,]+>[ ]*{(?=$)",
"begin": "<[a-zA-Z0-9_,]+>\\s*{\\s*(?=($|//|/\\*))",
"end": "^}",
"beginCaptures": {
"0": {
Expand All @@ -195,6 +201,9 @@
"include": "#comments"
},
{
"include": "#comment"
},
{
"include": "#strings"
},
{
Expand Down Expand Up @@ -247,6 +256,9 @@
{
"include": "#comments"
},
{
"include": "#comment"
},
{
"name": "constant.numeric.lex",
"match": "."
Expand All @@ -265,6 +277,9 @@
{
"include": "#comments"
},
{
"include": "#comment"
},
{
"include": "#user-define"
},
Expand Down Expand Up @@ -321,6 +336,11 @@
"name": "comment.block.yacc",
"begin": "/\\*",
"end": "\\*/"
},
"comment": {
"name": "comment.single.yacc",
"begin": "//",
"end": "$"
}
},
"scopeName": "source.l"
Expand Down

0 comments on commit 04de4de

Please # to comment.