Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Support else, elseif, and enum (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerLeonhardt authored and rjmholt committed Jun 30, 2019
1 parent 6932081 commit 8e96797
Show file tree
Hide file tree
Showing 11 changed files with 25,268 additions and 26,301 deletions.
Binary file removed .file.ps1.swp
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
*.swp
build
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# PowerShell support for tree-sitter

## Initial goal

Parse the [big test file from EditorSyntax](https://github.com/PowerShell/EditorSyntax/blob/master/examples/TheBigTestFile.ps1) completely.

## End goal

90%+ compatibility with the PowerShell parser today.

## Getting started

1. `npm install`
1. `npm start file.ps1`

If you want to just generate the parser, run `npm run generate`.

If you want to just parse a script, run `npm run parse file.ps1`
14 changes: 0 additions & 14 deletions ex.ps1

This file was deleted.

13 changes: 12 additions & 1 deletion file.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ $sb = {

if ($y)
{
Write-Host "Hello" -Verbose
Write-Host "If" -Verbose
} elseif($foo) {

} else {
Write-Host "Else" -Verbose
}

# A comment
$d = @{
$y = 111; duck = "Hello "
'7 nice things' = 1,@{}
}

${ } = "asdf"

enum EnumName {
Foo;
Bar
}
28 changes: 0 additions & 28 deletions float.format.ps1xml

This file was deleted.

70 changes: 36 additions & 34 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,18 @@ module.exports = grammar({
enum_definition: $ => seq(
/enum/i,
repeat($._newline),
/[a-z_][a-z0-9_]+/,
/[a-zA-Z_][a-zA-Z0-9_]+/,
repeat($._newline),
'{',
repeat($._newline),
$.bareword_string,
repeat(
seq(
repeat($._newline),
$.bareword_string
$._terminator,
$.bareword_string,
)
),
repeat($._newline),
optional($._terminator),
'}'
),

Expand Down Expand Up @@ -181,40 +183,40 @@ module.exports = grammar({
),
),
'}',
repeat($.elseif_statement),
optional($.else_statement)
),

elseif_statement: $ => seq(
/elseif/i,
repeat($._newline),
'(',
repeat($._newline),
$.pipeline_statement,
repeat($._newline),
')',
repeat($._newline),
'{',
repeat(
seq(
/elseif/i,
repeat($._newline),
'(',
repeat($._newline),
$.pipeline_statement,
repeat($._newline),
')',
repeat($._newline),
'{',
repeat(
seq(
$._statement,
$._terminator
),
),
'}'
)
$._statement,
$._terminator
),
),
optional(
'}'
),

else_statement: $ => seq(
/else/i,
repeat($._newline),
'{',
repeat(
seq(
/else/i,
repeat($._newline),
'{',
repeat(
seq(
$._statement,
$._terminator
),
),
'}'
)
)
$._statement,
$._terminator
),
),
'}'
),

while_statement: $ => seq(
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"generate": "tree-sitter generate",
"test": "tree-sitter test",
"parse": "tree-sitter parse",
"parse-debug": "tree-sitter parse -d",
"start": "npm run generate && npm run parse"
},
"author": "",
"license": "ISC",
Expand Down
Loading

0 comments on commit 8e96797

Please sign in to comment.