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

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmholt committed Jun 14, 2019
0 parents commit 360308f
Show file tree
Hide file tree
Showing 14 changed files with 8,893 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
18 changes: 18 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"targets": [
{
"target_name": "tree_sitter_PowerShell_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
],
"sources": [
"src/parser.c",
"src/binding.cc"
],
"cflags_c": [
"-std=c99",
]
}
]
}
14 changes: 14 additions & 0 deletions ex.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<#
Function Get-Magic{
<#
.SYNOPSIS
Really great function
#>
Param(
[Parameter(Position = 1, Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]$firstParameter
)
Test-ValidCommand
}
#>
18 changes: 18 additions & 0 deletions file.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
param(
[Parameter()]
[string]
$Greeting
)

$y = "$Greeting Jim!"
$z = 7,2.34e3ulkb,'banana',[system.collections.generic.dictionary[string, system.datetime][]]

$sb = {
$y = 7
}

# A comment
$d = @{
$y = 111; duck = "Hello "
'7 nice things' = 1,@{}
}
28 changes: 28 additions & 0 deletions float.format.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<View>
<Name>Microsoft.PowerShell.Commands.GenericMeasureInfo</Name>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Width>16</Width>
</TableColumnHeader>
<TableColumnHeader>
<Width>16</Width>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<PropertyName>LCID</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>Name</PropertyName>
</TableColumnItem>
<TableColumnItem>
<PropertyName>DisplayName</PropertyName>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
309 changes: 309 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,309 @@
module.exports = grammar({
name: 'PowerShell',

extras: $ => [
$.comment,
/`?\s/,
],

rules: {
source_file: $ => seq(
optional($.param_block),
seq(
$._statement,
repeat(
seq(
$._terminator,
$._statement
)
),
optional($._terminator)
),
),

scriptblock: $ => seq(
'{',
optional($.param_block),
seq(
$._statement,
repeat(
seq(
$._terminator,
$._statement
)
),
optional($._terminator)
),
'}'
),

param_block: $ => seq(
/(p|P)(a|A)(r|R)(a|A)(m|M)/,
'(',
optional(
seq(
$.param_block_variable,
repeat(
seq(
',',
$.param_block_variable
)
),
optional(',')
)
),
')'
),

param_block_variable: $ => seq(
repeat(
seq(
$._attribute,
optional($._newlines)
)
),
$.variable
),

_statement: $ => choice(
$.pipeline_statement
),

_newline: $ => choice(
'\r\n',
'\n'
),

_newlines: $ => repeat1($._newline),

_terminator: $ => choice(
';',
$._newline
),

pipeline_statement: $ => seq(
optional(
seq(
$._attributed_variable,
'=',
optional($._newlines)
)
),
$._pipeline_expression,
repeat(
seq(
'|',
optional($._newline),
$.command_expression
)
)
),

command_expression: $ => seq(
choice(
$.bareword_string,
seq('&', $.property_name)
)
),

parameter: $ => seq(
/-[a-zA-Z_][a-zA-Z0-9_]*/,
optional(
seq(
':',
$._expression
)
)
),

_non_array_expression: $ => choice(
$.number_expr,
$._string_expr,
$._attributed_variable,
$.scriptblock,
$.type_expr,
$.flat_array_expression,
$.hashtable_expression,
$.scriptblock,
seq('(', $._pipeline_expression, ')'),
seq('$(', $.pipeline_statement, ')')
),

_expression: $ => choice(
$._non_array_expression,
$.array_expression
),

_pipeline_expression: $ => choice(
$._expression,
$.command_expression
),

array_expression: $ => seq(
optional($._non_array_expression),
repeat1(
seq(
',',
$._non_array_expression
)
)
),

flat_array_expression: $ => seq(
'@(',
repeat($._terminator),
optional(
seq(
$._expression,
repeat(
seq(
repeat1($._terminator),
$._expression
)
),
repeat($._terminator)
)
),
')'
),

hashtable_expression: $ => seq(
'@{',
optional($._newlines),
optional(
seq(
$.hashtable_entry,
repeat(
seq(
repeat1($._terminator),
$.hashtable_entry
)
),
optional($._terminator)
)
),
'}'
),

hashtable_entry: $ => seq(
$.property_name,
'=',
optional($._newlines),
$._expression
),

property_name: $ => choice(
$._string_expr,
$.bareword_string,
$.variable
),

_attributed_variable: $ => seq(
repeat($._attribute),
$.variable
),

variable: $ => seq(
'$',
choice(
$._varname_simple,
$._varname_braced,
$._varname_special
)
),

_varname_simple: $ => /[a-zA-Z0-9_]+/,

_varname_braced: $ => /{[^}]+}/,

_varname_special: $ => choice(
'$',
'^',
'?'
),

type_expr: $ => seq(
'[',
$._typename,
']'
),

_typename: $ => choice(
$._typename_simple,
$._typename_array,
$._typename_generic
),

_typename_simple: $ => /[A-Za-z_][A-Za-z0-9_.]*/,

_typename_array: $ => seq(
$._typename,
'[]'
),

_typename_generic: $ => seq(
$._typename,
'[',
$._typename,
repeat(
seq(
',',
$._typename
)
),
']'
),

non_type_attribute: $ => seq(
'[',
$._typename_simple,
'(',
optional(
seq(
$._non_array_expression,
repeat(
seq(',', $._non_array_expression)
)
)
),
')',
']'
),

_attribute: $ => choice(
$.type_expr,
$.non_type_attribute
),

number_expr: $ => /(\d+|\d*\.\d+((e|E)\d+))(u|U)?(l|L)?((k|K|m|M|g|G|t|T)(b|B))?/,

_string_expr: $ => choice(
$.single_quote_string,
$.double_quote_string
),

single_quote_string: $ => /'[^']*'/,

double_quote_string: $ => choice(
'""',
seq(
'"',
repeat(
choice(
/[^"$]+/,
$.variable
)
),
optional('$'),
'"'
)
),

bareword_string: $ => /[^0-9'"$^`*&()\[\]@!-+%{}\s][^'"$^`*&()\[\]@!+%{}\s]*/,

comment: $ => token(choice(
/#.*/,
/<#.*#>/
))
},
});
Loading

0 comments on commit 360308f

Please sign in to comment.