Skip to content

Commit

Permalink
Merge pull request #64 from kit494way/composite-types
Browse files Browse the repository at this point in the history
Change to parse composite types
  • Loading branch information
fdncred authored Jan 5, 2024
2 parents 9c233a2 + bfa6005 commit 26bbaec
Show file tree
Hide file tree
Showing 5 changed files with 117,065 additions and 116,359 deletions.
360 changes: 360 additions & 0 deletions corpus/decl/def.nu
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,363 @@ def test [
(param_type
(flat_type))))
(block)))

======
def-019-type-list-of-list
======

def test [
x: list<list<int>>
]: nothing -> list<list<int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(list_type
(list_type
(flat_type))))))
(returns
(flat_type)
(list_type
(list_type
(flat_type))))
(block)))

======
def-020-type-list-of-record
======

def test [
x: list<record<key: string>>
]: nothing -> list<record<key: string>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(list_type
(collection_type
(identifier)
(flat_type))))))
(returns
(flat_type)
(list_type
(collection_type
(identifier)
(flat_type))))
(block)))

======
def-021-type-list-of-table
======

def test [
x: list<table<key1: string, key2: int>>
]: nothing -> list<table<key1: string, key2: int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(list_type
(collection_type
(identifier)
(flat_type)
(identifier)
(flat_type))))))
(returns
(flat_type)
(list_type
(collection_type
(identifier)
(flat_type)
(identifier)
(flat_type))))
(block)))

======
def-022-type-record-of-list
======

def test [
x: record<key: list<int>>
]: nothing -> record<key: list<int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(list_type
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(list_type
(flat_type))))
(block)))

======
def-023-type-record-of-record
======

def test [
x: record<key: list<int>>
]: nothing -> record<key: list<int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(list_type
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(list_type
(flat_type))))
(block)))

======
def-024-type-record-of-table
======

def test [
x: record<key: table<key: int>>
]: nothing -> record<key: table<key: int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(collection_type
(identifier)
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(collection_type
(identifier)
(flat_type))))
(block)))

======
def-025-type-table-of-list
======

def test [
x: table<key: list<string>>
]: nothing -> table<key: list<string>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(list_type
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(list_type
(flat_type))))
(block)))

======
def-026-type-table-of-record
======

def test [
x: table<key: record<key1: string, key2: int>>
]: nothing -> table<key: record<key1: string, key2: int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(collection_type
(identifier)
(flat_type)
(identifier)
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(collection_type
(identifier)
(flat_type)
(identifier)
(flat_type))))
(block)))

======
def-027-type-table-of-table
======

def test [
x: table<key: table<key1: string, key2: int>>
]: nothing -> table<key: table<key1: string, key2: int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(collection_type
(identifier)
(flat_type)
(identifier)
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(collection_type
(identifier)
(flat_type)
(identifier)
(flat_type))))
(block)))

======
def-028-type-one-line
======

def test [x: record<key: list<int>>]: nothing -> record<key: list<int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(list_type
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(list_type
(flat_type))))
(block)))

======
def-029-type-two-line
======

def test [x: record<key: list<int>>
]: nothing -> record<key: list<int>> {}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(list_type
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(list_type
(flat_type))))
(block)))

======
def-030-type-two-line
======

def test [x: record<key: list<int>>]: nothing -> record<key: list<int>> {
}

-----

(nu_script
(decl_def
(cmd_identifier)
(parameter_bracks
(parameter
(identifier)
(param_type
(collection_type
(identifier)
(list_type
(flat_type))))))
(returns
(flat_type)
(collection_type
(identifier)
(list_type
(flat_type))))
(block)))
8 changes: 5 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ module.exports = grammar({
_type_annotation: ($) =>
field("type", choice($.list_type, $.collection_type, $.flat_type)),

_all_type: ($) =>
field("type", choice($.list_type, $.collection_type, $.flat_type)),

flat_type: ($) => field("flat_type", FLAT_TYPES()),

collection_type: ($) => {
Expand All @@ -192,7 +195,7 @@ module.exports = grammar({
token.immediate(BRACK().open_angle),
repeat(
seq(
seq(key, optional(seq(PUNC().colon, $.flat_type))),
seq(key, optional(seq(PUNC().colon, $._all_type))),
optional(PUNC().comma),
),
),
Expand All @@ -206,7 +209,7 @@ module.exports = grammar({
"list",
seq(
token.immediate(BRACK().open_angle),
field("inner", optional($.flat_type)),
field("inner", optional($._all_type)),
BRACK().close_angle,
),
),
Expand Down Expand Up @@ -1407,7 +1410,6 @@ function SPECIAL() {

/// nushell flat types
/// taken from `nu_parser::parser::parse_shape_name()`
// i.e not composite types like list<int> or record<name: string>
function FLAT_TYPES() {
// prettier-ignore
const types = [
Expand Down
Loading

0 comments on commit 26bbaec

Please sign in to comment.