mirror of
https://github.com/We-Dont-Byte/Mind_Reader.git
synced 2024-11-15 03:35:59 +00:00
Name improvements, new tokens, new behavior.
Name improvements: - runLineContext changed to "Get Line Scope". - runCursorContext changed to "Get Words Under Cursor". New tokens: - STATEMENT: Replaces INDENT. Stores entire line of python statement, not including comments, in attr. - COMMENT: Stores entire comment line in attr. - INVALID: Invalid token, used when parser can't figure out a line. Should never be seen. New behavior: - Get Line Scope now reads out the comment your cursor is in. - Implemented fractional indentation notifications (disabled)
This commit is contained in:
parent
f86f2cb6b9
commit
34d89386ea
12
package.json
12
package.json
@ -4,7 +4,7 @@
|
|||||||
"repository": "https://github.com/We-Dont-Byte/Mind_Reader",
|
"repository": "https://github.com/We-Dont-Byte/Mind_Reader",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.60.0"
|
"vscode": "^1.66.0"
|
||||||
},
|
},
|
||||||
"categories": [
|
"categories": [
|
||||||
"Other"
|
"Other"
|
||||||
@ -60,13 +60,13 @@
|
|||||||
"category": "Mind Reader"
|
"category": "Mind Reader"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "mind-reader.runLineContext",
|
"command": "mind-reader.getLineScope",
|
||||||
"title": "Get the Context of the Current Line",
|
"title": "Get Scope of the Current Line",
|
||||||
"category": "Mind Reader"
|
"category": "Mind Reader"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "mind-reader.runCursorContext",
|
"command": "mind-reader.getWordsUnderCursor",
|
||||||
"title": "Get the Context of Text Under Cursor",
|
"title": "Get Words Under the Cursor",
|
||||||
"category": "Mind Reader"
|
"category": "Mind Reader"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -215,7 +215,7 @@
|
|||||||
"when": "editorTextFocus"
|
"when": "editorTextFocus"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"command": "mind-reader.runLineContext",
|
"command": "mind-reader.getLineScope",
|
||||||
"key": "Ctrl+Shift+/ C",
|
"key": "Ctrl+Shift+/ C",
|
||||||
"mac": "Cmd+Shift+[Slash] C",
|
"mac": "Cmd+Shift+[Slash] C",
|
||||||
"when": "editorTextFocus && editorLangId == python"
|
"when": "editorTextFocus && editorLangId == python"
|
||||||
|
@ -19,11 +19,11 @@ export const textCommands: CommandEntry[] = [
|
|||||||
callback: getLeadingSpaces,
|
callback: getLeadingSpaces,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'mind-reader.runLineContext',
|
name: 'mind-reader.getLineScope',
|
||||||
callback: runLineContext,
|
callback: runLineContext,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'mind-reader.runCursorContext',
|
name: 'mind-reader.getWordsUnderCursor',
|
||||||
callback: runCursorContext
|
callback: runCursorContext
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@ -168,16 +168,16 @@ function createContextString(context: pl.LexNode[], line: number): string {
|
|||||||
// Print the current line
|
// Print the current line
|
||||||
if (context[0].token && context[0].token.attr) {
|
if (context[0].token && context[0].token.attr) {
|
||||||
let tokenTypeString: string = `${context[0].token.type.toString()}`;
|
let tokenTypeString: string = `${context[0].token.type.toString()}`;
|
||||||
contextString += `: ${tokenTypeString !== 'INDENT'?tokenTypeString:""
|
contextString += `: ${tokenTypeString !== pl.PylexSymbol.STATEMENT?tokenTypeString:""
|
||||||
} ${context[0].token.attr.toString()}`;
|
} ${context[0].token.attr.toString()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i: number = 1; i < context.length; i++) {
|
for (let i: number = 1; i < context.length; i++) {
|
||||||
const node: pl.LexNode = context[i];
|
const node: pl.LexNode = context[i];
|
||||||
const inside: string = "in";
|
const inside: string = "inside";
|
||||||
// Node contains information relevant to the current line
|
// Node contains information relevant to the current line
|
||||||
if (node.token && node.token.type !== pl.PylexSymbol.EMPTY &&
|
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()}`;
|
contextString += ` ${inside} ${node.token.type.toString()}`;
|
||||||
if (node.token.attr) {
|
if (node.token.attr) {
|
||||||
contextString += ` ${node.token.attr.toString()}`;
|
contextString += ` ${node.token.attr.toString()}`;
|
||||||
|
@ -57,12 +57,16 @@ const rules: Rule[] = [
|
|||||||
type: Symbol.WITH
|
type: Symbol.WITH
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /^\s*(#.*)?$/,
|
pattern: /^\s*#+\s*(?<attr>.*)\s*$/,
|
||||||
|
type: Symbol.COMMENT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: /^\s*$/,
|
||||||
type: Symbol.EMPTY
|
type: Symbol.EMPTY
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pattern: /\s*(?<attr>[^#]+)?$/,
|
pattern: /^\s*(?<attr>[^#]+)+\s*$/,
|
||||||
type: Symbol.INDENT
|
type: Symbol.STATEMENT
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -151,7 +155,7 @@ export default class Lexer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// No rules matched
|
// No rules matched
|
||||||
token = new LineToken(Symbol.EMPTY, this.pos, 999999);
|
token = new LineToken(Symbol.INVALID, this.pos, 999999);
|
||||||
this._currToken = token;
|
this._currToken = token;
|
||||||
this.pos++;
|
this.pos++;
|
||||||
|
|
||||||
@ -218,7 +222,8 @@ export default class Lexer {
|
|||||||
indent = leadingSpace;
|
indent = leadingSpace;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// use spaces
|
// used spaces
|
||||||
|
//? indent = Math.round(leadingSpace / tabFmt.size! * 10) / 10; // fractional indentation support?
|
||||||
indent = Math.ceil(leadingSpace / tabFmt.size!);
|
indent = Math.ceil(leadingSpace / tabFmt.size!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +74,9 @@ export default class Parser {
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lexer.currToken().type === Symbol.INDENT ||
|
if (this.lexer.currToken().type === Symbol.STATEMENT ||
|
||||||
this.lexer.currToken().type === Symbol.EMPTY) {
|
this.lexer.currToken().type === Symbol.EMPTY ||
|
||||||
|
this.lexer.currToken().type === Symbol.INVALID) {
|
||||||
const label = this.lexer.currToken().type;
|
const label = this.lexer.currToken().type;
|
||||||
// regular code, advance and stay in same block
|
// regular code, advance and stay in same block
|
||||||
children.push(new LexNode(
|
children.push(new LexNode(
|
||||||
|
@ -16,8 +16,10 @@ export enum Symbol {
|
|||||||
EXCEPT = "except",
|
EXCEPT = "except",
|
||||||
FINALLY = "finally",
|
FINALLY = "finally",
|
||||||
WITH = "with",
|
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
|
EMPTY = "EMPTY", // empty line, used only to associate with the previous line
|
||||||
|
INVALID = "INVALID",
|
||||||
EOF = "EOF"
|
EOF = "EOF"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user