Skip to content

Commit d21af44

Browse files
committed
impl lexer
1 parent b9e07c1 commit d21af44

File tree

8 files changed

+334
-428
lines changed

8 files changed

+334
-428
lines changed

masm-tasm/.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
{
66
"version": "0.2.0",
77
"configurations": [
8+
{
9+
"name": "Run Extension ",
10+
"type": "extensionHost",
11+
"debugWebWorkerHost": true,
12+
"request": "launch",
13+
"args": [
14+
"--extensionDevelopmentPath=${workspaceFolder}",
15+
"${workspaceFolder}/samples"
16+
],
17+
"outFiles": [
18+
"${workspaceFolder}/dist/**/*.js"
19+
],
20+
"preLaunchTask": "${defaultBuildTask}"
21+
},
822
{
923
"name": "Run Web Extension ",
1024
"type": "extensionHost",

masm-tasm/src/language/Hover.ts

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -48,58 +48,64 @@ export class AsmHoverProvider implements vscode.HoverProvider {
4848
const docinfo = DocInfo.getDocInfo(document); //scan the document
4949
const line = docinfo.lines[position.line];
5050

51-
const text=document.getText();
52-
const {tokens, errors}=ast.tokenize(text);
53-
const pos=ast.lineAndColumnToPosition(text,position.line,position.character);
54-
for(const token of tokens){
55-
if(pos>token.position && pos<token.value.length+token.position){
56-
return new vscode.Hover(JSON.stringify(token));
57-
}
58-
}
59-
60-
if (range) {
61-
const wordGet = document.getText(range);
62-
const wordLowCase = wordGet.toLowerCase();
63-
64-
if (line && line.operator?.includes(wordGet)) {
65-
const h = await this.getHover(wordGet, [keywordType.instruction]);
66-
if (h) { return h; }
67-
}
68-
69-
if (line && line.operand?.includes(wordGet)) {
51+
const text = document.getText();
52+
const lexer = new ast.AssemblyLexer(text);
7053

71-
const md = new MarkdownString();
72-
if (info.isNumberStr(wordLowCase)) {
73-
md.appendMarkdown(info.getNumMsg(wordLowCase));
74-
return new vscode.Hover(md);
75-
}
76-
54+
const tokens = lexer.tokenize();
7755

78-
//hover for char
79-
let wordGet2=wordGet;
80-
if(range.start.character>0 && range.end.character-range.start.character===1){
81-
const range2=new vscode.Range(range.start.line,range.start.character-1,range.end.line,range.end.character+1);
82-
wordGet2=document.getText(range2);
83-
}
84-
const char = /['"](.)['"]/.exec(wordGet2);
85-
if (char && line.operand?.includes(wordGet2)) {
86-
md.appendMarkdown(info.getcharMsg(char[1]));
87-
return new vscode.Hover(md);
56+
for (const token of tokens) {
57+
if (token.line - 1 == position.line) {
58+
if (position.character+1 >= token.column && position.character+1 < token.column + token.value.length) {
59+
const str = `${token.value} ${token.column} ${position.character} ${token.type}`;
60+
return new vscode.Hover(str);
8861
}
89-
90-
const h = await this.getHover(wordGet, [keywordType.operator, keywordType.register, keywordType.symbol]);
91-
if (h) { return h; }
9262
}
63+
}
9364

94-
const asmsymbol = docinfo.findSymbol(wordGet); //the word is a symbol?
95-
if (asmsymbol) {
96-
return new vscode.Hover(asmsymbol.markdown());
97-
}
9865

99-
const h = await this.getHover(wordGet, [keywordType.other, keywordType.directive, keywordType.register]);
100-
if (h) { return h; }
101-
}
102-
return undefined;
66+
// if (range) {
67+
// const wordGet = document.getText(range);
68+
// const wordLowCase = wordGet.toLowerCase();
69+
70+
// if (line && line.operator?.includes(wordGet)) {
71+
// const h = await this.getHover(wordGet, [keywordType.instruction]);
72+
// if (h) { return h; }
73+
// }
74+
75+
// if (line && line.operand?.includes(wordGet)) {
76+
77+
// const md = new MarkdownString();
78+
// if (info.isNumberStr(wordLowCase)) {
79+
// md.appendMarkdown(info.getNumMsg(wordLowCase));
80+
// return new vscode.Hover(md);
81+
// }
82+
83+
84+
// //hover for char
85+
// let wordGet2=wordGet;
86+
// if(range.start.character>0 && range.end.character-range.start.character===1){
87+
// const range2=new vscode.Range(range.start.line,range.start.character-1,range.end.line,range.end.character+1);
88+
// wordGet2=document.getText(range2);
89+
// }
90+
// const char = /['"](.)['"]/.exec(wordGet2);
91+
// if (char && line.operand?.includes(wordGet2)) {
92+
// md.appendMarkdown(info.getcharMsg(char[1]));
93+
// return new vscode.Hover(md);
94+
// }
95+
96+
// const h = await this.getHover(wordGet, [keywordType.operator, keywordType.register, keywordType.symbol]);
97+
// if (h) { return h; }
98+
// }
99+
100+
// const asmsymbol = docinfo.findSymbol(wordGet); //the word is a symbol?
101+
// if (asmsymbol) {
102+
// return new vscode.Hover(asmsymbol.markdown());
103+
// }
104+
105+
// const h = await this.getHover(wordGet, [keywordType.other, keywordType.directive, keywordType.register]);
106+
// if (h) { return h; }
107+
// }
108+
// return undefined;
103109
}
104110

105111
public async getHover(word: string, types: keywordType[]): Promise<vscode.Hover | undefined> {

masm-tasm/src/language/ast.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

masm-tasm/src/language/ast/ast.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Define token types
22
export type TokenType =
3+
| 'COMMENT'
34
| 'INSTRUCTION'
45
| 'REGISTER'
56
| 'NUMBER'

0 commit comments

Comments
 (0)