Skip to content

Commit

Permalink
chore: optimize user-defined function def scope + add complex test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-semenov committed May 3, 2024
1 parent 228f19e commit 88ac95c
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 118 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/build-packages.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
---
name: "Build Packages"
name: Build Packages

on:
push:
branches: [ main ]
paths-ignore: [ "*.md" ]
pull_request:
branches: [ main ]
workflow_run:
workflows: ["TextMate Grammar Coverage Badge"]
types:
- completed

jobs:
Build-VSIX:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/coverage-badge.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
name: "TextMate Grammar Coverage Badge"
name: TextMate Grammar Coverage Badge

on:
push:
branches: [ main ]
paths: [ "src/**", "tests/**" ]
paths-ignore: [ "*.md" ]
pull_request:
branches: [ main ]
paths: [ "src/**", "tests/**" ]
paths-ignore: [ "*.md" ]

jobs:
Compile:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "Pre-Commit"
name: Pre-Commit

on:
push:
Expand Down
55 changes: 28 additions & 27 deletions src/functions.YAML-tmLanguage.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# yamllint disable rule:line-length
---
repository:
parens: &parens_rules []
functions:
patterns:
- include: "#builtins"
Expand Down Expand Up @@ -33,30 +34,14 @@ repository:
user-defined:
patterns:
-
begin: '([[:alpha:]][[:alnum:]_]*)\b(?=\s*\(|\(\s*\{|\{\s*\()'
end: '(?<=$|=)'
begin: '([[:alpha:]][[:alnum:]_]*)\b(?=(\s*\(|\(\s*\{|\{\s*\()[^=]*=)'
end: '(?<=\=)'
beginCaptures:
1:
name: entity.name.function.user.parigp
name: meta.function.parigp
patterns:
-
begin: '(\()'
beginCaptures:
0:
name: punctuation.section.parens.begin.parigp
1:
name: punctuation.definition.parameters.begin.parigp
end: '(\))(?=\s*=)'
endCaptures:
0:
name: punctuation.section.parens.end.parigp
1:
name: punctuation.definition.parameters.end.parigp
name: meta.parameters.parigp
patterns:
- include: '#parens'
- include: '#function-vars'
- include: '#function-vars'
-
begin: '([[:alpha:]][[:alnum:]_]*)\b(?=\s*=\s*[^\->]+\s*\-\s*>)'
end: '(?<=\->)'
Expand All @@ -65,17 +50,33 @@ repository:
name: entity.name.function.user.lambda.parigp
name: meta.function.lambda.parigp
patterns:
- include: '#parens'
-
match: '(\->)'
name: keyword.operator.lambda
- include: '#function-vars'
repository:
function-vars:
patterns:
-
match: '([[:alpha:]][[:alnum:]_]*)\s*'
captures:
1:
name: variable.parameter.function.parigp
-
match: ','
name: punctuation.separator.parigp
<<: *parens_rules
patterns:
- include: '#function-vars'
- include: '#general'
- include: '#literals'
- include: '#operators'
- include: '#type-hints'
-
match: '(?<!:\s*)([[:alpha:]][[:alnum:]_]*)\s*'
name: variable.parameter.function.parigp
-
begin: '(\{)'
end: '(\})'
beginCaptures:
1:
name: meta.function.parameter.optional.begin.parigp
endCaptures:
1:
name: meta.function.parameter.optional.end.parigp
name: meta.function.parameter.optional.parigp
patterns:
- include: '#function-vars'
11 changes: 7 additions & 4 deletions src/general.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ repository:
general:
patterns:
-
match: "'?\\b[[:alpha:]][[:alnum:]_]*"
name: variable.name.parigp
match: ';'
name: markup.punctuation.statement-terminator.parigp
-
match: '[,;\.]'
name: markup.punctuation.parigp
match: ':'
name: markup.annotation.parigp
-
match: ','
name: markup.punctuation.separator.parigp
-
match: '\s'
name: constant.character.whitespace.parigp
18 changes: 14 additions & 4 deletions src/main.YAML-tmLanguage
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yamllint disable rule:hyphens
---
fileTypes:
- gp
Expand All @@ -10,7 +11,7 @@ patterns:
repository:
parens:
patterns:
-
- &parens_rules
begin: '\('
end: '\)'
beginCaptures:
Expand All @@ -21,7 +22,7 @@ repository:
name: punctuation.section.parens.end.parigp
name: meta.parens.parigp
patterns:
- include: "#code"
- include: "#parens"
braces:
patterns:
-
Expand Down Expand Up @@ -49,18 +50,27 @@ repository:
name: punctuation.section.brackets.end.parigp
name: meta.brackets.parigp
patterns:
-
match: '[,;]'
name: markup.punctuation.separator.parigp
- include: "#code"
code:
patterns:
- include: "#comments"
- include: "#parens"
-
<<: *parens_rules
patterns:
- include: "#code"
- include: "#braces"
- include: "#brackets"
- include: "#functions"
- include: "#type-hints"
- include: "#literals"
- include: "#operators"
- include: "#general"
- include: '#general'
-
match: "'?\\b[[:alpha:]][[:alnum:]_]*"
name: variable.name.parigp
scopeName: source.parigp
$schema: >-
https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json
6 changes: 3 additions & 3 deletions src/operators.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ repository:
1:
name: keyword.operator.factorial.parigp
-
match: '(&&|\|\||!\b)'
match: '(&&|\|\|)|(!)\b'
name: keyword.operator.logical.parigp
-
match: '(\->)'
name: keyword.operator.lambda
match: '(?<!&)(&)'
name: keyword.operator.pointer.parigp
-
match: '(<=|>=|<|>)'
name: keyword.operator.comparison.parigp
Expand Down
2 changes: 1 addition & 1 deletion src/type-hints.YAML-tmLanguage.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repository:
type-hints:
patterns:
-
match: '\:\s*\b({{ scopes["support.type"] | join("|") }})\b'
match: '\s*\b({{ scopes["support.type"] | join("|") }})\b'
captures:
1:
name: support.type.parigp
14 changes: 12 additions & 2 deletions tests/comments.test.gp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## SYNTAX TEST "source.parigp" "Comments"

\\ one-line comment, rest of line ignored
\\ One-line comment, rest of line ignored
##^^ source.parigp punctuation.definition.comment.parigp comment.line.double-slash.parigp
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.parigp punctuation.definition.comment.parigp

Expand All @@ -11,6 +11,16 @@
Multi-line comment: Line 2
## ^^^^^^^^^^^^^^^^^^^^^^^^^^ source.parigp comment.block.parigp
/* Nested multi-line comments shouldn't confuse the parser */
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.parigp comment.block.parigp
## ^^ source.parigp comment.block.parigp comment.block.parigp punctuation.definition.comment.begin.parigp
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.parigp comment.block.parigp comment.block.parigp
## ^^ source.parigp comment.block.parigp comment.block.parigp punctuation.definition.comment.end.parigp
*/
##^^ source.parigp comment.block.parigp punctuation.definition.comment.end.parigp

(/* Comment inside expression */ 1)
##^ source.parigp meta.parens.parigp punctuation.section.parens.begin.parigp
## ^^ source.parigp meta.parens.parigp comment.block.parigp punctuation.definition.comment.begin.parigp
## ^^^^^^^^^^^^^^^^^^^^^^^^^ source.parigp meta.parens.parigp comment.block.parigp
## ^^ source.parigp meta.parens.parigp comment.block.parigp punctuation.definition.comment.end.parigp
## ^ source.parigp meta.parens.parigp constant.numeric.int.parigp
## ^ source.parigp meta.parens.parigp punctuation.section.parens.end.parigp
Loading

0 comments on commit 88ac95c

Please sign in to comment.