Skip to content

Commit

Permalink
Release 0.2.2
Browse files Browse the repository at this point in the history
- see change log
  • Loading branch information
babyraging committed Apr 30, 2020
1 parent ea86d14 commit f890555
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 71 deletions.
12 changes: 7 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## UnReleased

## Release

## 0.2.2

### Added
Expand All @@ -18,15 +20,15 @@

### Changed
- Change dollars syntax scope naming
- Simple refactoring, add common files

### Bug fixes
- Fixed unable to detect int name[100]; variable name pattern.

## Release
- Fixed unable to detect int name[100]; variable name pattern. (yacc)
- Fixed a missing case for start state scope detection (lex)

## 0.2.1
### Added
- Added support for initial state scope (lex)
- Added support for start state scope (lex)

### Changed
- Now uses a parser to parse the %union types instead of regex (yacc)
Expand Down Expand Up @@ -97,7 +99,7 @@
## 0.0.7
### Added
- Added comment highlight (lex)
- Added multi initial states <a, b, c, d> highlight (lex)
- Added multi start states <a, b, c, d> highlight (lex)
- Added basic hover and goto definition support (lex/yacc)
- Added new keywords, nonassoc|pure-parser|name-prefix|locations (yacc)
- Added multiline token definitions detection (yacc)
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Up @@ -2,7 +2,7 @@
"name": "yash",
"displayName": "Yash",
"description": "Yet another syntax highlighter for lex/yacc & flex/bison.",
"version": "0.2.1",
"version": "0.2.2",
"engines": {
"vscode": "^1.44.0"
},
Expand Down
19 changes: 19 additions & 0 deletions src/languages/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export enum ProblemType {
Information,
Warning,
Error
};

export interface ProblemRelated {
readonly message: string;
readonly offset: number;
readonly end: number;
};

export interface Problem {
readonly message: string;
readonly offset: number;
readonly end: number;
readonly type: ProblemType;
readonly related?: ProblemRelated;
};
20 changes: 0 additions & 20 deletions src/languages/lexLanguageTypes.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
export enum ProblemType {
Information,
Warning,
Error
};

export interface ProblemRelated {
readonly message: string;
readonly offset: number;
readonly end: number;
};

export interface Problem {
readonly message: string;
readonly offset: number;
readonly end: number;
readonly type: ProblemType;
readonly related?: ProblemRelated;
};

export enum TokenType {
Word,
Literal,
Expand Down
15 changes: 12 additions & 3 deletions src/languages/parser/lexParser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createScanner } from "./lexScanner";
import { TokenType, ProblemType, ProblemRelated } from "../lexLanguageTypes";
import { TokenType } from "../lexLanguageTypes";
import { binarySearch } from "./utils";
import { Problem } from "../lexLanguageTypes";
import { Problem, ProblemType, ProblemRelated } from "../common";

const _CHX = 'x'.charCodeAt(0);
const _CHS = 's'.charCodeAt(0);
Expand Down Expand Up @@ -112,6 +112,7 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
let tokenText = '';
let acceptingStates = false;
let lastToken = token;
let isConditionScope = false;
while (end < 0 && token !== TokenType.EOS) {
offset = scanner.getTokenOffset();
switch (token) {
Expand Down Expand Up @@ -141,6 +142,8 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
switch (token) {
case TokenType.Word:
addSymbol(document.defines, scanner.getTokenText(), scanner.getTokenOffset(), scanner.getTokenEnd());

// this is stops counting regex pattern like [{] as action opener
scanner.disableMultiLineBrackets();
state = ParserState.WaitingDef;
break;
Expand Down Expand Up @@ -219,6 +222,9 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
});
}
break;
case TokenType.StartAction:
isConditionScope = lastToken === TokenType.EndStates;
break;
case TokenType.Action: // found using user defined definition
tokenText = scanner.getTokenText();
if (/^\w+$/.test(tokenText)) { // if {word}
Expand All @@ -231,7 +237,7 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
definition: [-1, -1],
references: [[offset, scanner.getTokenEnd()]]
});
} else {
} else if (isConditionScope) {
/**
* If initial state scope
* <state>{
Expand All @@ -241,6 +247,7 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
*
* }
*/
console.log("condition scope");
const recursive = parse(tokenText, ParserState.WaitingRule);
recursive.components.forEach(c => {
c.offset += offset;
Expand All @@ -254,6 +261,8 @@ export function parse(text: string, state: ParserState = ParserState.WaitingDecl
code.end += offset;
document.embedded.push(code);
});
} else {
addProblem("Invalid definition pattern.", scanner.getTokenOffset(), scanner.getTokenEnd(), ProblemType.Error);
}
break;
case TokenType.Divider:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/parser/yaccParser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { binarySearch } from './utils';
import { createScanner } from './yaccScanner';
import { parse as parseUnion, YYType } from './unionParser';
import { TokenType, ProblemType, Problem, ProblemRelated } from '../yaccLanguageTypes';
import { TokenType } from '../yaccLanguageTypes';
import { ProblemType, Problem, ProblemRelated } from '../common';
import { SemanticTokenData, SemanticTokenModifier, SemanticTokenType } from '../semanticTokens';
import { Position } from 'vscode';

Expand Down
2 changes: 1 addition & 1 deletion src/languages/services/lexDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextDocument, Position, Definition, Location, Range } from 'vscode';
import { LexDocument, ISymbol } from "../parser/lexParser";
import { LexDocument, ISymbol } from '../parser/lexParser';

export function doLEXFindDefinition(document: TextDocument, position: Position, lexDocument: LexDocument): Definition | null {
const offset = document.offsetAt(position);
Expand Down
4 changes: 2 additions & 2 deletions src/languages/services/lexHover.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextDocument, Hover, Position, MarkdownString } from 'vscode';
import { LexDocument, ISymbol } from "../parser/lexParser";
import { createMarkedCodeString } from "./utils";
import { LexDocument, ISymbol } from '../parser/lexParser';
import { createMarkedCodeString } from './utils';

export function doLEXHover(document: TextDocument, position: Position, lexDocument: LexDocument): Hover | null {
const offset = document.offsetAt(position);
Expand Down
2 changes: 1 addition & 1 deletion src/languages/services/lexReferences.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextDocument, Position, Location, Range } from 'vscode';
import { LexDocument, ISymbol } from "../parser/lexParser";
import { LexDocument, ISymbol } from '../parser/lexParser';

export function doLEXFindReferences(document: TextDocument, position: Position, lexDocument: LexDocument): Location[] {
const offset = document.offsetAt(position);
Expand Down
4 changes: 2 additions & 2 deletions src/languages/services/lexRename.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextDocument, Position, Range, WorkspaceEdit, TextEdit } from 'vscode';
import { LexDocument, ISymbol } from "../parser/lexParser"
import { TextDocument, Position, Range, WorkspaceEdit } from 'vscode';
import { LexDocument, ISymbol } from '../parser/lexParser'

export function doLEXRename(document: TextDocument, position: Position, newName: string, lexDocument: LexDocument): WorkspaceEdit | null {
const offset = document.offsetAt(position);
Expand Down
6 changes: 3 additions & 3 deletions src/languages/services/lexValidation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextDocument, Diagnostic, Range, DiagnosticSeverity, DiagnosticRelatedInformation, Location } from "vscode";
import { ProblemType } from "../yaccLanguageTypes";
import { LexDocument } from "../parser/lexParser";
import { TextDocument, Diagnostic, Range, DiagnosticSeverity, DiagnosticRelatedInformation, Location } from 'vscode';
import { ProblemType } from '../common';
import { LexDocument } from '../parser/lexParser';

export function doLEXValidation(document: TextDocument, lexDocument: LexDocument): Diagnostic[] {
const diags: Diagnostic[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/languages/services/yaccDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextDocument, Position, Definition, Location, Range } from 'vscode';
import { YACCDocument, ISymbol } from "../parser/yaccParser";
import { YACCDocument, ISymbol } from '../parser/yaccParser';

export function doYACCFindDefinition(document: TextDocument, position: Position, yaccDocument: YACCDocument): Definition | null {
const offset = document.offsetAt(position);
Expand Down
6 changes: 3 additions & 3 deletions src/languages/services/yaccHover.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextDocument, Hover, Position, MarkedString, MarkdownString } from 'vscode';
import { YACCDocument, ISymbol, NodeType } from "../parser/yaccParser";
import { createMarkedCodeString } from "./utils";
import { TextDocument, Hover, Position, MarkdownString } from 'vscode';
import { YACCDocument, ISymbol } from '../parser/yaccParser';
import { createMarkedCodeString } from './utils';

export function doYACCHover(document: TextDocument, position: Position, yaccDocument: YACCDocument): Hover | null {
const offset = document.offsetAt(position);
Expand Down
2 changes: 1 addition & 1 deletion src/languages/services/yaccReferences.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextDocument, Position, Location, Range } from 'vscode';
import { YACCDocument, ISymbol } from "../parser/yaccParser";
import { YACCDocument, ISymbol } from '../parser/yaccParser';

export function doYACCFindReferences(document: TextDocument, position: Position, yaccDocument: YACCDocument): Location[] {
const offset = document.offsetAt(position);
Expand Down
2 changes: 1 addition & 1 deletion src/languages/services/yaccRename.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextDocument, Position, Range, WorkspaceEdit, TextEdit } from 'vscode';
import { YACCDocument, ISymbol } from "../parser/yaccParser";
import { YACCDocument, ISymbol } from '../parser/yaccParser';

export function doYACCRename(document: TextDocument, position: Position, newName: string, yaccDocument: YACCDocument): WorkspaceEdit | null {
const offset = document.offsetAt(position);
Expand Down
2 changes: 1 addition & 1 deletion src/languages/services/yaccTypeDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TextDocument, Position, Definition, Location, Range } from 'vscode';
import { YACCDocument, ISymbol } from "../parser/yaccParser";
import { YACCDocument, ISymbol } from '../parser/yaccParser';

export function doYACCFindTypeDefinition(document: TextDocument, position: Position, yaccDocument: YACCDocument): Definition | null {
const offset = document.offsetAt(position);
Expand Down
6 changes: 3 additions & 3 deletions src/languages/services/yaccValidation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextDocument, Diagnostic, Range, DiagnosticSeverity, DiagnosticRelatedInformation, Location } from "vscode";
import { YACCDocument } from "../parser/yaccParser";
import { ProblemType } from "../yaccLanguageTypes";
import { TextDocument, Diagnostic, Range, DiagnosticSeverity, DiagnosticRelatedInformation, Location } from 'vscode';
import { YACCDocument } from '../parser/yaccParser';
import { ProblemType } from '../common';

export function doYACCValidation(document: TextDocument, yaccDocument: YACCDocument): Diagnostic[] {
const diags: Diagnostic[] = [];
Expand Down
21 changes: 0 additions & 21 deletions src/languages/yaccLanguageTypes.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import { SemanticTokenType, SemanticTokenModifier } from "./semanticTokens";

export enum ProblemType {
Information,
Warning,
Error
};

export interface ProblemRelated {
readonly message: string;
readonly offset: number;
readonly end: number;
};

export interface Problem {
readonly message: string;
readonly offset: number;
readonly end: number;
readonly type: ProblemType;
readonly related?: ProblemRelated;
};

export enum TokenType {
Word,
Literal,
Expand Down

0 comments on commit f890555

Please # to comment.