Skip to content

Commit

Permalink
Merge pull request #1171 from totvs/embeddedLanguages
Browse files Browse the repository at this point in the history
Embedded languages
  • Loading branch information
lwtnb-wrk authored Dec 7, 2023
2 parents df67990 + 7cc49c0 commit 7bbb048
Show file tree
Hide file tree
Showing 24 changed files with 714 additions and 93 deletions.
3 changes: 2 additions & 1 deletion .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"indent": 4
},
"MD013": {
"line_length": 200,
"line_length": 1024,
"heading_line_length": 120
},
"MD024": false,
"MD033": {
"allowed_elements": [
"a"
Expand Down
3 changes: 1 addition & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"pflannery.vscode-versionlens",
"naumovs.color-highlight",
"compulim.vscode-mocha",
"streetsidesoftware.code-spell-checker",
"streetsidesoftware.code-spell-checker-portuguese-brazilian"
"pedro-w.tmlanguage"
]
}
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## Versão [2.0.0-next]

### Melhoria

#### Comando ``BeginContent`` passa a aceitar o tipo de conteúdo

```
beginComment var myVar [as <language: javascript | JS | html | json | xml | css | typeScript | TS>]
```

Essa informação é utilizada apenas para fins visuais não sendo efetuado nenhum tipo de validação.

## Versão [2.0.0]

> Interoperabilidade entre sistemas operacionais
Expand Down Expand Up @@ -1102,7 +1114,7 @@ Detalhes em

- Corrigido apresentação da estrutura de fontes 4GL na visão `Outline`.

#### Correção na compilação 4GL quando há comando "globals <arquivo>"
#### Correção na compilação 4GL quando há comando "globals \<arquivo\>"

- Resolução do chamado interno [DTCLIENT01-2015](https://jiraproducao.totvs.com.br/browse/DTCLIENT01-2015). Requer atualização do _appServer_.

Expand Down
36 changes: 35 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"tmp": "^0.2.1",
"typescript": "^4.8.3",
"vscode-languageclient": "^8.0.2",
"vscode-languageserver-types": "^3.17.5",
"windows-1251": "^1.1.0",
"windows-1252": "^1.1.0"
},
Expand Down Expand Up @@ -303,7 +304,16 @@
{
"language": "advpl",
"scopeName": "source.advpl",
"path": "./syntaxes/advpl_language.tmLanguage.json"
"path": "./syntaxes/advpl_language.tmLanguage.json",
"embeddedLanguages": {
"source.sql": "sql",
"source.js": "javascript",
"text.html": "html",
"source.json": "json",
"text.xml": "xml",
"source.ts": "typescript",
"source.css": "css"
}
},
{
"language": "4gl",
Expand Down Expand Up @@ -332,6 +342,16 @@
"embeddedLanguages": {
"meta.embedded.block.advpl": "advpl"
}
},
{
"scopeName": "sql.advpl.codeblock",
"path": "./syntaxes/advpl_sql.tmLanguage.json",
"injectTo": [
"source.advpl"
],
"embeddedLanguages": {
"meta.embedded.block.advpl.sql": "sql"
}
}
],
"snippets": [
Expand Down Expand Up @@ -368,6 +388,20 @@
"files.eol": "\r\n",
"editor.formatOnSaveMode": "file",
"editor.semanticHighlighting.enabled": true
},
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": [
"variable.parameter.advpl",
"punctuation.variable.parameter.advpl"
],
"settings": {
"foreground": "#868c18",
"fontStyle": "italic bold"
}
}
]
}
},
"configuration": {
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export function activate(context: ExtensionContext) {
() => tdsReplayLauncherConfig.show(context)
);

//inicialliza items da barra de status.
//inicializa items da barra de status.
initStatusBarItems(context);

context.subscriptions.push(
Expand Down
15 changes: 15 additions & 0 deletions src/formatter/advplFormattingRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,21 @@ export class AdvplFormattingRules extends RulesFormatting {
decrement: false,
reset: false,
},
{
id: 'begin content block',
expression: /^(\s*)(beginContent)(\s+)(var)/i,
increment: false,
decrement: false,
reset: false,
ignore_at: 'end content block',
},
{
id: 'end content block',
expression: /^(\s*)(endContent)/i,
increment: false,
decrement: false,
reset: false,
},
];
}
}
114 changes: 57 additions & 57 deletions src/formatter/formattingRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,63 @@ export interface RuleMatch {
}

export abstract class RulesFormatting {
private lastMatch: RuleMatch | null = null;
private customRules: IndentationRule[] = null;
private rulesExpressions: IndentationRule[] = null;

constructor() {
this.rulesExpressions = this.loadRulesExpressions();
this.customRules = this.loadCustomRules();
}

private instanceOfRule(object: any): object is IndentationRule {
return 'expression' in object;
}

public match(line: string): boolean {
if (line.trim().length === 0) {
return false;
}

line += '\n';
let finddedRule: RuleMatch | null = null;

this.getRules().every((rule: IndentationRule) => {
if (this.instanceOfRule(rule)) {
if (line.match(rule.expression)) {
finddedRule = { rule: rule };
}
}

return finddedRule === null;
});

if (finddedRule !== null) {
this.lastMatch = finddedRule;
return true;
}

return false;
}

public getLastMatch(): RuleMatch | null {
return this.lastMatch;
}

public getRules(): IndentationRule[] {
return [...this.rulesExpressions, ...this.customRules];
}

// marcadores regexp utilizados
// (\s+) = um ou mais whitespaces
// (\w+) = uma ou mais letras/digitos => palavra
// (constante) = constante (palavra chave)
// (.*) = qualquer coisa
// ? = 0 ou mais ocorrências
// ^ = inicio da linha
// /i = ignorar caixa
protected abstract loadCustomRules(): IndentationRule[];
protected abstract loadRulesExpressions(): IndentationRule[];
private lastMatch: RuleMatch | null = null;
private customRules: IndentationRule[] = null;
private rulesExpressions: IndentationRule[] = null;

constructor() {
this.rulesExpressions = this.loadRulesExpressions();
this.customRules = this.loadCustomRules();
}

private instanceOfRule(object: any): object is IndentationRule {
return 'expression' in object;
}

public match(line: string): boolean {
if (line.trim().length === 0) {
return false;
}

line += '\n';
let ruleFound: RuleMatch | null = null;

this.getRules().every((rule: IndentationRule) => {
if (this.instanceOfRule(rule)) {
if (line.match(rule.expression)) {
ruleFound = { rule: rule };
}
}

return ruleFound === null;
});

if (ruleFound !== null) {
this.lastMatch = ruleFound;
return true;
}

return false;
}

public getLastMatch(): RuleMatch | null {
return this.lastMatch;
}

public getRules(): IndentationRule[] {
return [...this.rulesExpressions, ...this.customRules];
}

// marcadores regexp utilizados
// (\s+) = um ou mais whitespaces
// (\w+) = uma ou mais letras/digitos => palavra
// (constante) = constante (palavra chave)
// (.*) = qualquer coisa
// ? = 0 ou mais ocorrências
// ^ = inicio da linha
// /i = ignorar caixa
protected abstract loadCustomRules(): IndentationRule[];
protected abstract loadRulesExpressions(): IndentationRule[];
}

/*
Expand Down
Loading

0 comments on commit 7bbb048

Please sign in to comment.