diff --git a/package.json b/package.json index 993fd07..3d48b19 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "repository": "https://github.com/We-Dont-Byte/Mind_Reader", "version": "1.0.0", "engines": { - "vscode": "^1.60.0" + "vscode": "^1.66.0" }, "categories": [ "Other" @@ -60,13 +60,13 @@ "category": "Mind Reader" }, { - "command": "mind-reader.runLineContext", - "title": "Get the Context of the Current Line", + "command": "mind-reader.getLineScope", + "title": "Get Scope of the Current Line", "category": "Mind Reader" }, { - "command": "mind-reader.runCursorContext", - "title": "Get the Context of Text Under Cursor", + "command": "mind-reader.getWordsUnderCursor", + "title": "Get Words Under the Cursor", "category": "Mind Reader" }, { @@ -215,7 +215,7 @@ "when": "editorTextFocus" }, { - "command": "mind-reader.runLineContext", + "command": "mind-reader.getLineScope", "key": "Ctrl+Shift+/ C", "mac": "Cmd+Shift+[Slash] C", "when": "editorTextFocus && editorLangId == python" diff --git a/src/commands/text.ts b/src/commands/text.ts index 7cf5306..abdbc30 100755 --- a/src/commands/text.ts +++ b/src/commands/text.ts @@ -19,11 +19,11 @@ export const textCommands: CommandEntry[] = [ callback: getLeadingSpaces, }, { - name: 'mind-reader.runLineContext', + name: 'mind-reader.getLineScope', callback: runLineContext, }, { - name: 'mind-reader.runCursorContext', + name: 'mind-reader.getWordsUnderCursor', callback: runCursorContext } ]; @@ -168,16 +168,16 @@ function createContextString(context: pl.LexNode[], line: number): string { // Print the current line if (context[0].token && context[0].token.attr) { let tokenTypeString: string = `${context[0].token.type.toString()}`; - contextString += `: ${tokenTypeString !== 'INDENT'?tokenTypeString:"" + contextString += `: ${tokenTypeString !== pl.PylexSymbol.STATEMENT?tokenTypeString:"" } ${context[0].token.attr.toString()}`; } for (let i: number = 1; i < context.length; i++) { const node: pl.LexNode = context[i]; - const inside: string = "in"; + const inside: string = "inside"; // Node contains information relevant to the current line if (node.token && node.token.type !== pl.PylexSymbol.EMPTY && - node.token.type !== pl.PylexSymbol.INDENT) { + node.token.type !== pl.PylexSymbol.STATEMENT) { contextString += ` ${inside} ${node.token.type.toString()}`; if (node.token.attr) { contextString += ` ${node.token.attr.toString()}`; diff --git a/src/pylex/lexer.ts b/src/pylex/lexer.ts index 92e48ea..89a17b6 100644 --- a/src/pylex/lexer.ts +++ b/src/pylex/lexer.ts @@ -57,12 +57,16 @@ const rules: Rule[] = [ type: Symbol.WITH }, { - pattern: /^\s*(#.*)?$/, + pattern: /^\s*#+\s*(?.*)\s*$/, + type: Symbol.COMMENT + }, + { + pattern: /^\s*$/, type: Symbol.EMPTY }, { - pattern: /\s*(?[^#]+)?$/, - type: Symbol.INDENT + pattern: /^\s*(?[^#]+)+\s*$/, + type: Symbol.STATEMENT } ]; @@ -151,7 +155,7 @@ export default class Lexer { } } // No rules matched - token = new LineToken(Symbol.EMPTY, this.pos, 999999); + token = new LineToken(Symbol.INVALID, this.pos, 999999); this._currToken = token; this.pos++; @@ -218,7 +222,8 @@ export default class Lexer { indent = leadingSpace; } else { - // use spaces + // used spaces + //? indent = Math.round(leadingSpace / tabFmt.size! * 10) / 10; // fractional indentation support? indent = Math.ceil(leadingSpace / tabFmt.size!); } diff --git a/src/pylex/parser.ts b/src/pylex/parser.ts index 9a2fb18..d6771a8 100644 --- a/src/pylex/parser.ts +++ b/src/pylex/parser.ts @@ -74,8 +74,9 @@ export default class Parser { return children; } - if (this.lexer.currToken().type === Symbol.INDENT || - this.lexer.currToken().type === Symbol.EMPTY) { + if (this.lexer.currToken().type === Symbol.STATEMENT || + this.lexer.currToken().type === Symbol.EMPTY || + this.lexer.currToken().type === Symbol.INVALID) { const label = this.lexer.currToken().type; // regular code, advance and stay in same block children.push(new LexNode( diff --git a/src/pylex/token.ts b/src/pylex/token.ts index 54e62be..9d9a457 100644 --- a/src/pylex/token.ts +++ b/src/pylex/token.ts @@ -16,8 +16,10 @@ export enum Symbol { EXCEPT = "except", FINALLY = "finally", WITH = "with", - INDENT = "INDENT", // Indent token, default if not EOF, only contains indent information + STATEMENT = "statement", // Indent token, contains non-empty code lines + COMMENT = "comment", EMPTY = "EMPTY", // empty line, used only to associate with the previous line + INVALID = "INVALID", EOF = "EOF" }