Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#234 Added new func to std_seq.go. #240

Merged
merged 136 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from 121 commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
61b1845
#234 Added new func to std_seq.go.
ericzhang6222 May 11, 2020
dfd453e
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 11, 2020
1ca6a25
#234 Fixed issue found by CI linter.
ericzhang6222 May 11, 2020
53cd164
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 12, 2020
cedb62b
#234 Move test cases to correct place.
ericzhang6222 May 12, 2020
7ca11fb
#234 Check main body of changes.
ericzhang6222 May 12, 2020
2a6453a
#234 Check main body of changes.
ericzhang6222 May 12, 2020
0074e35
#234 Check in test case changes.
ericzhang6222 May 12, 2020
2955085
#234 Added code to implement API .
ericzhang6222 May 12, 2020
854cb2e
#234 Added code to implement API .
ericzhang6222 May 12, 2020
12c850e
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 12, 2020
605ad83
#234 Removed funcs which have been moved to seq.
ericzhang6222 May 12, 2020
ba370be
#234 Made operator join work.
ericzhang6222 May 12, 2020
0e41758
#234 Added code to implement for rel.Array.
ericzhang6222 May 12, 2020
0a90275
#234 Fixed issue found by CI linter.
ericzhang6222 May 12, 2020
6aaf621
#234 Fixed issue found by CI linter.
ericzhang6222 May 12, 2020
2da4140
#234 Fixed issue found by CI linter.
ericzhang6222 May 12, 2020
b12e57f
#234 Added some pseudo code.
ericzhang6222 May 12, 2020
6f21ca6
#234 Fixed issue found by go lint.
ericzhang6222 May 13, 2020
509fc6c
#234 Updated sample and docs as has_prefix has been moved to seq.
ericzhang6222 May 13, 2020
81aa4cf
#234 Updated test cases as func changes in str.
ericzhang6222 May 13, 2020
7d421e3
#234 Updated samples as func is moved from str tp seq.
ericzhang6222 May 13, 2020
e53492a
#234 Updated docs as func is moved from str tp seq.
ericzhang6222 May 13, 2020
04e57e3
Simplify process and code.
ericzhang6222 May 13, 2020
8ba80db
#234 Update code to support has_prefix and has_suffix.
ericzhang6222 May 13, 2020
ae67a6a
#234 Fixed code conflicts with master branch.
ericzhang6222 May 13, 2020
e1774c2
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 13, 2020
2ff9b6a
#234 Updated test case as funcs have been moved from str to seq.
ericzhang6222 May 13, 2020
36f6700
Merge branch 'refactor-str-seq' of https://github.com/arr-ai/arrai in…
ericzhang6222 May 13, 2020
205024e
#234 Fixed issue found by linter.
ericzhang6222 May 13, 2020
72b21b7
#234 Change API params order.
ericzhang6222 May 13, 2020
960fd0c
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 13, 2020
839ec9c
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 14, 2020
70d4c45
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 14, 2020
803b028
#234 Fix array match issue.
ericzhang6222 May 14, 2020
8e6b952
Merge branch 'refactor-str-seq' of https://github.com/arr-ai/arrai in…
ericzhang6222 May 14, 2020
e73afdd
#234 Fixed issue found by golabg linter.
ericzhang6222 May 14, 2020
db49821
#234 Fixed issue found by golang linter.
ericzhang6222 May 14, 2020
4d0c0cf
#234 Check in one more test case.
ericzhang6222 May 14, 2020
4d43f89
#234 Check in code to implement array substitute.
ericzhang6222 May 14, 2020
a6baa4b
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 14, 2020
e58c0c8
#234 Fixed issue found by golang linter.
ericzhang6222 May 14, 2020
f882175
Merge branch 'refactor-str-seq' of https://github.com/arr-ai/arrai in…
ericzhang6222 May 14, 2020
37b1059
#234 Fixed issue found by golang linter.
ericzhang6222 May 14, 2020
aff29e9
#234 Fixed issue found by golang linter.
ericzhang6222 May 14, 2020
d110124
#234 Check in more test cases.
ericzhang6222 May 14, 2020
698e7f8
#234 Check in more test cases.
ericzhang6222 May 14, 2020
6f59c9d
#234 Check in more test cases.
ericzhang6222 May 14, 2020
cc72e51
#230 Updated API signature to place the subject param in the last.
ericzhang6222 May 15, 2020
325b577
#230 Refactor code for API signature change.
ericzhang6222 May 15, 2020
c07d672
#234 Removed unused test case.
ericzhang6222 May 15, 2020
1c516d1
#234 Removed unused test case.
ericzhang6222 May 15, 2020
c6299c7
#234 Updated join implementation.
ericzhang6222 May 15, 2020
88802ff
#234 Fixed issue found by golang linter.
ericzhang6222 May 15, 2020
fb5a92e
#268 Change API signature.
ericzhang6222 May 17, 2020
a650c44
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 17, 2020
d427d08
#234 Fixed byte join API.
ericzhang6222 May 17, 2020
30147a2
#234 Check in one more test case for byte join.
ericzhang6222 May 17, 2020
63358e5
#234 Check bytes split test case.
ericzhang6222 May 17, 2020
b02b5b4
#234 Fixed issue found by golang linter.
ericzhang6222 May 17, 2020
333a73a
#234 Implemented array split feature.
ericzhang6222 May 17, 2020
f56532e
#234 Removed unnecessary comments.
ericzhang6222 May 17, 2020
b659c0a
#234 Updated documents.
ericzhang6222 May 17, 2020
be8e898
#234 Updated panic error messages.
ericzhang6222 May 17, 2020
6d7647c
#234 Updated method signature as review comments.
ericzhang6222 May 18, 2020
8708e89
#234 Updated method signature as review comments.
ericzhang6222 May 18, 2020
3dfdf42
#234 Updated code to make variables are meaningful as review comment.
ericzhang6222 May 18, 2020
9e12034
#234 Updated code to user IsTrue as review comment.
ericzhang6222 May 18, 2020
71601ff
#234 Updated code to user IsTrue as review comment.
ericzhang6222 May 18, 2020
8cb4fc6
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 18, 2020
3e36ad5
#234 Updated code as review comment.
ericzhang6222 May 18, 2020
93f148a
#234 Removed code flattern the array.
ericzhang6222 May 18, 2020
6def424
#234 Removed code flattern the array.
ericzhang6222 May 18, 2020
780647e
#234 Changed test case as it is not required to flatten array.
ericzhang6222 May 18, 2020
a9fc5c2
#234 Added more empty params cases.
ericzhang6222 May 18, 2020
77844ce
#234 Added more test cases.
ericzhang6222 May 18, 2020
61fbbc3
#234 Added more test cases.
ericzhang6222 May 18, 2020
7569d8e
Update syntax/std_seq_array_helper.go
ericzhang6222 May 19, 2020
7d2575e
#234 Updated method signature from arrayContain to arrayContains.
ericzhang6222 May 19, 2020
9a5114e
#234 Updated args order in helper go files to match arr.ai functions.
ericzhang6222 May 19, 2020
8be0447
#234 Used if statement replacing switch.
ericzhang6222 May 19, 2020
c7841d8
#234 Change test case result to [] for split.
ericzhang6222 May 19, 2020
df83a23
#234 Added edge test case for sub API.
ericzhang6222 May 19, 2020
f4cfb50
#234 Added edge test case for APIs.
ericzhang6222 May 19, 2020
cf9c8ff
#234 Fixed incorrect test case for APIs.
ericzhang6222 May 19, 2020
3982a2b
#234 Fixed incorrect test case for APIs.
ericzhang6222 May 19, 2020
154ba13
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 19, 2020
5473ea8
#234 Fixed incorrect test case for APIs.
ericzhang6222 May 19, 2020
9b30e3b
Merge branch 'refactor-str-seq' of https://github.com/arr-ai/arrai in…
ericzhang6222 May 19, 2020
254d09f
#234 Added more test case for API join.
ericzhang6222 May 19, 2020
26fb4e3
#234 Removed unnecessary test case.
ericzhang6222 May 19, 2020
076afd7
#234 Removed unnecessary test case.
ericzhang6222 May 19, 2020
d05356e
#234 Fixed issue found by golang CI.
ericzhang6222 May 19, 2020
1bd5176
#234 Reformat test cases as review comment.
ericzhang6222 May 19, 2020
5784161
#234 Fixed issue found by golang linter.
ericzhang6222 May 19, 2020
9ecc2d5
#234 Check in more edge test case for split API.
ericzhang6222 May 19, 2020
7835e47
#234 Fixed incorrect split API, -> .
ericzhang6222 May 19, 2020
b974610
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 19, 2020
9077692
#234 Updated to make array split algorithm more straightforward.
ericzhang6222 May 19, 2020
01d08fd
#234 Updated to make array split algorithm more straightforward.
ericzhang6222 May 19, 2020
3211949
#234 Updated panic error..
ericzhang6222 May 20, 2020
07ba2e5
#234 Updated docs and added more test cases..
ericzhang6222 May 20, 2020
520d461
#234 Updated docs.'
ericzhang6222 May 20, 2020
67bbb37
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 20, 2020
a9415a3
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 21, 2020
8cea2c4
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 21, 2020
b503c07
#234 Removed unnecessary code as review comment.
ericzhang6222 May 21, 2020
5e4fca9
Merge branch 'refactor-str-seq' of https://github.com/arr-ai/arrai in…
ericzhang6222 May 21, 2020
1cf5725
#234 Added more test case as review comment.
ericzhang6222 May 21, 2020
7d851f1
#234 Unpack args... to local variables and make code is more readable.
ericzhang6222 May 21, 2020
fd68a43
#234 Unpack args... to local variables to make code is more readable.
ericzhang6222 May 22, 2020
546acff
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 22, 2020
b230d30
#234 Make sure the param subject in array join API has array type ele…
ericzhang6222 May 22, 2020
2980a3b
#234 Added more test cases.
ericzhang6222 May 22, 2020
ea9149c
#234 Fixed issue found by golang linter.
ericzhang6222 May 22, 2020
8c81c1f
#234 Fixed issue found by golang linter.
ericzhang6222 May 22, 2020
40175e8
#234 Fixed issue found by golang linter.
ericzhang6222 May 22, 2020
3741ef4
#234 Fixed incorrect test case.
ericzhang6222 May 22, 2020
9dbc9be
#234 Changed code to make it is more readable.
ericzhang6222 May 22, 2020
a5d4bd4
#234 Corrected std-seq.md sample.
ericzhang6222 May 22, 2020
82837d6
#234 Merged latest code from master.
ericzhang6222 May 24, 2020
bf5e66e
#234 Fixed syntax error.
ericzhang6222 May 24, 2020
4f161d0
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 24, 2020
5f912d0
#234 Updated code as code review comments.
ericzhang6222 May 25, 2020
65c4b73
Merge branch 'refactor-str-seq' of https://github.com/arr-ai/arrai in…
ericzhang6222 May 25, 2020
a2b1aa3
#234 Fixed code conflicts.
ericzhang6222 May 25, 2020
c2bf772
#234 Fixed code conflicts, use new test API AssertCodeErrors.
ericzhang6222 May 25, 2020
9cf45ea
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 25, 2020
2416761
Merge branch 'master' into refactor-str-seq
ericzhang6222 May 25, 2020
d1c3334
#234 Updated code as review comments.
ericzhang6222 May 25, 2020
1b14e39
Merge branch 'refactor-str-seq' of https://github.com/arr-ai/arrai in…
ericzhang6222 May 25, 2020
9d719db
#234 Updated code as review comments.
ericzhang6222 May 25, 2020
e1997a0
Fixed final line endings with Logerfo/newline-action.
Logerfo May 25, 2020
8996b5c
#234 Updated code as review comments.
ericzhang6222 May 25, 2020
37fa011
Merge branch 'refactor-str-seq' of https://github.com/arr-ai/arrai in…
ericzhang6222 May 25, 2020
5a7c8b9
#234 Fixed issue found by golang CI.
ericzhang6222 May 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ External libraries may be accessed via package references.
1. **`//math`:** math functions and constants such as `//math.sin`
and `//math.pi`.
2. **`//str`:** string functions such as `//str.upper` and
`//str.join`.
`//seq.join`.
ericzhang6222 marked this conversation as resolved.
Show resolved Hide resolved
3. **`//fn`:** higher order functions such as `//fn.fix` and `//fn.fixt`.
See the [standard library reference](std.md) for full documentation on all packages.
2. **`//{./path}`** provides access to other arrai files relative to the current
Expand Down
92 changes: 89 additions & 3 deletions docs/std-seq.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# seq

The `seq` library contains functions that are used for string manipulations.
The `seq` library contains functions that are used for manipulating sequenced data structures.
ericzhang6222 marked this conversation as resolved.
Show resolved Hide resolved

## `//seq.concat(seqs <: array) <: array` <br/> `concat(seqs <: string) <: string`
## `//seq.concat(seqs <: array) <: array` <br/> `//seq.concat(seqs <: string) <: string`

`concat` takes an array of sequences `seqs` and returns a sequence that is
the concatenation of the sequences in the array.
Expand All @@ -12,10 +12,96 @@ the concatenation of the sequences in the array.
| `//seq.concat(["ba", "na", "na"])` | `"banana"` |
| `//seq.concat([[1, 2], [3, 4, 5]])` | `[1, 2, 3, 4, 5]` |

## `//seq.repeat(n <: number, seq <: array) <: array` <br/> `repeat(n <: number, seq <: string) <: string`
## `//seq.repeat(n <: number, seq <: array) <: array` <br/> `//seq.repeat(n <: number, seq <: string) <: string`

`repeat` returns a sequence that contains `seq` repeated `n` times.

| example | equals |
|:-|:-|
| `//seq.repeat(2, "hots")` | `"hotshots"` |


## `//seq.has_prefix(prefix <: array, subject <: array) <: bool` <br/> `//seq.has_prefix(prefix <: string, subject <: string) <: bool`

`has_prefix` checks whether the sequence `subject` is prefixed by sequence `prefix`. It returns a boolean.
ericzhang6222 marked this conversation as resolved.
Show resolved Hide resolved

Usage:

| example | equals |
|:-|:-|
| `//seq.has_prefix("I'm", "I'm running out of stuff to write")` | `true` |
| `//seq.has_prefix("to write", "I'm running out of stuff to write")` | `{}` which is equal to `false` |
ericzhang6222 marked this conversation as resolved.
Show resolved Hide resolved
ericzhang6222 marked this conversation as resolved.
Show resolved Hide resolved
| `//seq.has_prefix(['A'],['A','B','C'])` | `true` |
| `//seq.has_prefix([1, 2],[1, 2, 3])` | `true` |
| `//seq.has_prefix([[1, 2]],[[1, 2], [3]])` | `true` |


## `//seq.has_suffix(suffix <: array, subject <: array) <: bool` <br/> `//seq.has_suffix(suffix <: string, subject <: string) <: bool`

`has_suffix` checks whether the sequence `subject` is suffixed by sequence `suffix`. It returns a boolean.
ericzhang6222 marked this conversation as resolved.
Show resolved Hide resolved

Usage:

| example | equals |
|:-|:-|
| `//seq.has_suffix("I'm", "I'm running out of stuff to write")` | `{}` which is equal to `false` |
| `//seq.has_suffix("to write", "I'm running out of stuff to write")` | `true` |
| `//seq.has_suffix(['E'],['A','B','C','D','E'])` | `true` |
| `//seq.has_suffix([[3, 4]],[[1 ,2], [3, 4]])` | `true` |

## `//seq.join(joiner <: array, subject <: array) <: array` <br/> `//seq.join(joiner <: string, subject <: array_of_string) <: string`

`join` returns a concatenated sequence with each member of sequence `subject` delimited by sequence `joiner`

Usage:

| example | equals |
|:-|:-|
| `//seq.join(", ", ["pew", "another pew", "and more pews"])` | `"pew, another pew, and more pews"` |
| `//seq.join(" ", ["this", "is", "a", "sentence"])` | `"this is a sentence"` |
| `//seq.join(["", "this", "is", "a", "sentence"])` | `"thisisasentence"` |
| `//seq.join([0], [[1, 2], [3, 4], [5, 6]]` | `[1, 2, 0, 3, 4, 0, 5, 6]`
| `//seq.join([0], [[2, [3, 4]], [5, 6]])` | `[2, [3, 4], 0, 5, 6]` |
| `//seq.join([[0],[1]], [[[1, 2], [3, 4]],[[5, 6],[7, 8]]])` | `[[1, 2], [3, 4], [0], [1], [5, 6], [7, 8]]` |

## `//seq.contains(sub <: array, subject <: array) <: bool` <br/> `//seq.contains(sub <: string, subject <: string) <: bool`

`contains` checks whether sequence `sub` is contained in sequence `subject`. It returns a boolean.
ericzhang6222 marked this conversation as resolved.
Show resolved Hide resolved

Usage:

| example | equals |
|:-|:-|
| `//seq.contains("substring", "the full string which has substring")` | `true` |
| `//seq.contains("microwave", "just some random sentence")` | `{}` which is equal to `false` |
| `//seq.contains([1,2,3,4,5], [1,2,3,4,5])` | `true` |
| `//seq.contains([['B','C']],[['A', 'B'], ['B','C'],['D','E']])` | `true` |


## `//seq.sub(old <: array, new <: array, subject <: array) <: array` <br/> `//seq.sub(old <: string, new <: string, subject <: string) <: string`

`sub` replaces occurrences of sequence `old` in sequence `subject` with sequence `new`. It returns the modified sequence.

Usage:

| example | equals |
|:-|:-|
| `//seq.sub("old string", "new sentence", "this is the old string")` | `"this is the new sentence"` |
| `//seq.sub("string", "stuff", "just another sentence")` | `"just another sentence"` |
| `//seq.sub([1], [2], [1, 2, 3])` | `[2, 2, 3]` |
| `//seq.sub([[2,2]], [[4,4]], [[1,1], [2,2], [3,3]])`| `[[1,1], [4,4], [3,3]]` |

## `//seq.split(delimiter <: array, subject <: array) <: array` <br/> `//seq.split(delimiter <: string, subject <: string) <: array of string`

`split` splits sequence `subject` based on the provided sequence `delimiter`. It returns an array of sequence which are split from the sequence `subject`.

Usage:

| example | equals |
|:-|:-|
| `//seq.split(" ", "deliberately adding spaces to demonstrate the split function")` | `["deliberately", "adding", "spaces", "to", "demonstrate", "the", "split", "function"]` |
| `//seq.split("random stuff", "this is just a random sentence")` | `["this is just a random sentence"]` |
| `//seq.split([1],[1, 2, 3])` | `[[],[2,3]]` |
| `//seq.split([3],[1, 2, 3])` | `[[1,2],[]]` |
| `//seq.split(['A'],['B', 'A', 'C', 'A', 'D', 'E'])` | `[['B'],['C'], ['D', 'E']]` |
| `//seq.split([['C','D'],['E','F']],[['A','B'], ['C','D'], ['E','F'], ['G']])`) | `[[['A','B']], [['G']]]` |
69 changes: 0 additions & 69 deletions docs/std-str.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,6 @@

The `str` library contains functions that are used for string manipulations.

## `//str.contains(str <: string, substr <: string) <: bool`

`contains` checks whether `substr` is contained in `str`. It returns a
boolean.

Usage:

| example | equals |
|:-|:-|
| `//str.contains("the full string which has substring", "substring")` | `true` |
| `//str.contains("just some random sentence", "microwave")` | `{}` which is equal to `false` |

## `//str.sub(s <: string, old <: string, new <: string) <: string`

`sub` replaces occurrences of `old` in `s` with `new`. It returns the modified string.

Usage:

| example | equals |
|:-|:-|
| `//str.sub("this is the old string", "old string", "new sentence")` | `"this is the new sentence"` |
| `//str.sub("just another sentence", "string", "stuff")` | `"just another sentence"` |

## `//str.split(s <: string, delimiter <: string) <: array of string`

`split` splits the string `s` based on the provided `delimiter`. It returns an array of strings
which are split from the string `s`.

Usage:

| example | equals |
|:-|:-|
| `//str.split("deliberately adding spaces to demonstrate the split function", " ")` | `["deliberately", "adding", "spaces", "to", "demonstrate", "the", "split", "function"]` |
| `//str.split("this is just a random sentence", "random stuff")` | `["this is just a random sentence"]` |

## `//str.lower(s <: string) <: string`

`lower` returns the string `s` with all of the character converted to lowercase.
Expand Down Expand Up @@ -72,37 +37,3 @@ Usage:
|:-|:-|
| `//str.title("laser noises pew pew pew")` | `"Laser Noises Pew Pew Pew"` |
| `//str.title("pew")` | `"Pew"` |

## `//str.has_prefix(s <: string, prefix <: string) <: bool`

`has_prefix` checks whether the string `s` is prefixed by `prefix`. It returns a boolean.

Usage:

| example | equals |
|:-|:-|
| `//str.has_prefix("I'm running out of stuff to write", "I'm")` | `true` |
| `//str.has_prefix("I'm running out of stuff to write", "to write")` | `{}` which is equal to `false` |

## `//str.has_suffix(s <: string, suffix <: string) <: bool`

`has_suffix` checks whether the string `s` is suffixed by `suffix`. It returns a boolean.

Usage:

| example | equals |
|:-|:-|
| `//str.has_suffix("I'm running out of stuff to write", "I'm")` | `{}` which is equal to `false` |
| `//str.has_suffix("I'm running out of stuff to write", "to write")` | `true` |

## `//str.join(s <: array_of_string, delimiter <: string) <: string`

`join` returns a concatenated string with each member of `s` delimited by `delimiter`

Usage:

| example | equals |
|:-|:-|
| `//str.join(["pew", "another pew", "and more pews"], ", ")` | `"pew, another pew, and more pews"` |
| `//str.join(["this", "is", "a", "sentence"], " ")` | `"this is a sentence"` |
| `//str.join(["this", "is", "a", "sentence"], "")` | `"thisisasentence"` |
12 changes: 6 additions & 6 deletions examples/grpc/grpc-proto.arrai
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
let grpc = //{./grpc};
let wrap = "wrap" <: app.attrs.patterns;
let proto = //{./proto-util}(wrap);
let endpoints = app.endpoints where !//str.has_prefix(.@item.name, "enum ");
let endpoints = app.endpoints where !//seq.has_prefix("enum ", .@item.name);
//archive.tar.tar({
app.name + ".proto": $`
// THIS IS AUTOGENERATED BY sysl //
Expand All @@ -24,8 +24,8 @@ let endpoints = app.endpoints where !//str.has_prefix(.@item.name, "enum ");
${cond (app.endpoints: $`
${//rel.union((endpoints >> (.params >>
cond (
//str.contains(grpc.type(.), "google.protobuf"): $`
import "${//str.sub(grpc.type(.), ".", "/")}.proto";`,
//seq.contains("google.protobuf", grpc.type(.)): $`
import "${//seq.sub(".", "/", grpc.type(.))}.proto";`,
) => .@item
)) => .@item)::\i:\n}
service ${app.name} {
Expand All @@ -37,14 +37,14 @@ let endpoints = app.endpoints where !//str.has_prefix(.@item.name, "enum ");
}`:::\n}
${endpoints >> proto.wrapSequence(.).grpcType::\i}
${cond (wrap: endpoints) >>
let retTokens = //str.split(ep.ret("ok"), " ");
let retName = //str.sub(//seq.concat(retTokens -- {"sequence", "of"}), ".", "");
let retTokens = //seq.split(" ", ep.ret("ok"));
let retName = //seq.sub(".", "", //seq.concat(retTokens -- {"sequence", "of"}));
let attr = ep.attrs(retName + "_rpcId");
let epi = proto.endpointInfo(ep);
$`
message ${epi.paramName} {
${ep.params >>
let name = //str.sub(.name, "-", "");
let name = //seq.sub("-", "", .name);
$`${grpc.type(.)} req${name} = ${.attrs(name + "_rpcId")};`
::\i}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc/grpc.arrai
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
),
'sequence': 'repeated ' + type(t.sequence)
*: cond (
//str.contains(t.type_ref, "google-protobuf"): //str.sub(t.type_ref, "-", "."),
//seq.contains("google-protobuf", t.type_ref): //seq.sub("-", ".", t.type_ref),
*: t.type_ref,
),
),
Expand Down
14 changes: 7 additions & 7 deletions examples/grpc/proto-util.arrai
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
let grpc = //{./grpc};

\wrap (
field: \. $`${grpc.type(.)} ${//str.sub(.key, "-", "")} = ${.attrs.rpcId};`,
field: \. $`${grpc.type(.)} ${//seq.sub("-", "", .key)} = ${.attrs.rpcId};`,

imports: \fields
fields where(//str.contains(grpc.type(.@item), "google.protobuf")) >>
$`import "${//str.sub(grpc.type(.), ".", "/")}.proto";`,
fields where(//seq.contains("google.protobuf", grpc.type(.@item))) >>
$`import "${//seq.sub(".", "/", grpc.type(.))}.proto";`,

endpointInfo: \ep
let method = //str.sub(//str.title(//str.lower(ep.name)), "-", "");
let method = //seq.sub("-", "", //str.title(//str.lower(ep.name)));
let paramName = cond (
wrap: method + "Request",
*: $"${ep.params >> grpc.type(.)::, }",
);
let streamRes = cond (
ep.attrs.stream: //str.sub(ep.ret("ok"), "sequence of", "stream"),
*: //str.sub(ep.ret("ok"), "sequence of ", "") + "s",
ep.attrs.stream: //seq.sub("sequence of", "stream", ep.ret("ok")),
*: //seq.sub("sequence of ", "", ep.ret("ok")) + "s",
);
let responseName = cond (wrap: method + "Response", *: streamRes);
(
Expand All @@ -26,7 +26,7 @@ let grpc = //{./grpc};
),

wrapSequence: \ep
let type = //str.sub(ep.ret("ok"), "sequence of ", "");
let type = //seq.sub("sequence of ", "", ep.ret("ok"));
let wrapType = type + "s";
let name = //str.lower(type) + "s";
(
Expand Down
2 changes: 1 addition & 1 deletion internal/shell/shell_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestIsCommand(t *testing.T) {
t.Parallel()

assert.True(t, isCommand("/hi"))
assert.False(t, isCommand("//str.join"))
assert.False(t, isCommand("//seq.join"))
}

func TestTryRunCommand(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions internal/shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ func TestGetLastToken(t *testing.T) {
assert.Equal(t, "//str", getLastToken([]rune("//str")))
assert.Equal(t, "//", getLastToken([]rune("//")))
assert.Equal(t, "///", getLastToken([]rune("///")))
assert.Equal(t, "//", getLastToken([]rune("//str.contains(//")))
assert.Equal(t, "//arch", getLastToken([]rune("//str.contains(//arch")))
assert.Equal(t, "tuple.", getLastToken([]rune("//str.contains(tuple.")))
assert.Equal(t, "//", getLastToken([]rune("//seq.contains(//")))
assert.Equal(t, "//arch", getLastToken([]rune("//seq.contains(//arch")))
assert.Equal(t, "tuple.", getLastToken([]rune("//seq.contains(tuple.")))
assert.Equal(t, "x.", getLastToken([]rune("x.")))
assert.Equal(t, "x", getLastToken([]rune("x")))
assert.Equal(t, "", getLastToken([]rune("//str.contains(")))
assert.Equal(t, "", getLastToken([]rune("//seq.contains(")))
assert.Equal(t, "", getLastToken([]rune("")))
}

Expand All @@ -166,14 +166,14 @@ func TestTabCompletionStdlib(t *testing.T) {
stdlibNames := stdlib.Names().OrderedNames()

assertTabCompletion(t, append(stdlibNames, "{"), 0, "//\t", nil)
assertTabCompletion(t, append(stdlibNames, "{"), 0, "//str.contains(//\t", nil)
assertTabCompletion(t, append(stdlibNames, "{"), 0, "//seq.contains(//\t", nil)
prefix := "s"

assertTabCompletionWithPrefix(t, prefix, stdlibNames, "//%s\t", nil)
assertTabCompletionWithPrefix(t, prefix, stdlibNames, "x(//%s\t", nil)
assertTabCompletionWithPrefix(t, prefix, stdlibNames, "x(//%s\t + random)", nil)

lib := "str"
lib := "seq"
strlib := stdlib.MustGet(lib).(rel.Tuple).Names().OrderedNames()
assertTabCompletionWithPrefix(t, prefix, strlib, "//"+lib+".%s\t", nil)
for i := 0; i < len(strlib); i++ {
Expand Down
6 changes: 5 additions & 1 deletion rel/value_set_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ func (a Array) Kind() int {
return arrayKind
}

// Bool returns true iff the tuple has attributes.
// IsTrue returns true if the tuple has attributes.
func (a Array) IsTrue() bool {
<<<<<<< HEAD
return len(a.values) > 0
=======
return a.count > 0
>>>>>>> master
}

// Less returns true iff v is not a number or tuple, or v is a tuple and t
Expand Down
Loading