Skip to content

Commit aa1e9cb

Browse files
authored
Merge pull request #846 from refaktor/dotwords
testing and improving a no_peg parser
2 parents 3e67483 + 60427b0 commit aa1e9cb

16 files changed

Lines changed: 1496 additions & 66 deletions

internal/parsing/01-words.rye

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
; Parser tests for word types
2+
print "## Word Types"
3+
4+
; Basic word
5+
assert\display "word" {
6+
type? first { word }
7+
} 'word
8+
9+
; Set-word (word:)
10+
assert\display "set-word" {
11+
type? first { word: }
12+
} 'setword
13+
14+
; Left set-word (:word)
15+
assert\display "lset-word" {
16+
type? first { :word }
17+
} 'lsetword
18+
19+
; Mod-word (word::)
20+
assert\display "mod-word" {
21+
type? first { word:: }
22+
} 'modword
23+
24+
; Left mod-word (::word)
25+
assert\display "lmod-word" {
26+
type? first { ::word }
27+
} 'lmodword
28+
29+
; Get-word (?word)
30+
assert\display "get-word" {
31+
type? first { ?word }
32+
} 'getword
33+
34+
; Tag-word ('word)
35+
assert\display "tag-word" {
36+
type? first { 'word }
37+
} 'tagword
38+
39+
; Words with special chars
40+
assert\display "word with hyphen" {
41+
type? first { my-word }
42+
} 'word
43+
44+
assert\display "word with question mark" {
45+
type? first { empty? }
46+
} 'word
47+
48+
assert\display "word with exclamation" {
49+
type? first { inc! }
50+
} 'word
51+
52+
; Words starting with underscore
53+
assert\display "word starting with underscore" {
54+
type? first { _private }
55+
} 'word
56+
57+
; Words with numbers
58+
assert\display "word with numbers" {
59+
type? first { var1 }
60+
} 'word
61+
62+
print ""

internal/parsing/02-opwords.rye

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
; Parser tests for op-words (operators)
2+
print "## Op-words (Operators)"
3+
4+
; Single character operators
5+
assert\display "plus operator" {
6+
type? first { + }
7+
} 'opword
8+
9+
assert\display "minus operator" {
10+
type? first { - }
11+
} 'opword
12+
13+
assert\display "multiply operator" {
14+
type? first { * }
15+
} 'opword
16+
17+
assert\display "divide operator" {
18+
type? first { / }
19+
} 'opword
20+
21+
assert\display "less than operator" {
22+
type? first { < }
23+
} 'opword
24+
25+
assert\display "greater than operator" {
26+
type? first { > }
27+
} 'opword
28+
29+
assert\display "equals operator" {
30+
type? first { = }
31+
} 'opword
32+
33+
assert\display "percent operator" {
34+
type? first { % }
35+
} 'opword
36+
37+
assert\display "tilde operator" {
38+
type? first { ~ }
39+
} 'opword
40+
41+
assert\display "exclamation operator" {
42+
type? first { ! }
43+
} 'opword
44+
45+
; Multi-character comparison operators
46+
assert\display "not-equal operator !=" {
47+
type? first { != }
48+
} 'opword
49+
50+
assert\display "double-equals operator ==" {
51+
type? first { == }
52+
} 'opword
53+
54+
assert\display "less-or-equal operator <=" {
55+
type? first { <= }
56+
} 'opword
57+
58+
assert\display "greater-or-equal operator >=" {
59+
type? first { >= }
60+
} 'opword
61+
62+
assert\display "not-equal operator <>" {
63+
type? first { <> }
64+
} 'opword
65+
66+
; Arrow operators
67+
assert\display "right arrow ->" {
68+
type? first { -> }
69+
} 'opword
70+
71+
assert\display "left arrow <-" {
72+
type? first { <- }
73+
} 'opword
74+
75+
assert\display "fat arrow =>" {
76+
type? first { => }
77+
} 'opword
78+
79+
assert\display "tilde arrow ~>" {
80+
type? first { ~> }
81+
} 'opword
82+
83+
assert\display "left tilde arrow <~" {
84+
type? first { <~ }
85+
} 'opword
86+
87+
; Other multi-char operators
88+
assert\display "range operator .." {
89+
type? first { .. }
90+
} 'opword
91+
92+
assert\display "increment operator ++" {
93+
type? first { ++ }
94+
} 'opword
95+
96+
assert\display "decrement operator --" {
97+
type? first { -- }
98+
} 'opword
99+
100+
assert\display "double slash //" {
101+
type? first { // }
102+
} 'opword
103+
104+
assert\display "shift left <<" {
105+
type? first { << }
106+
} 'opword
107+
108+
assert\display "shift right >>" {
109+
type? first { >> }
110+
} 'opword
111+
112+
print ""

internal/parsing/03-dotwords.rye

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
; Parser tests for dot-words
2+
print "## Dot-words"
3+
4+
; Basic dotword
5+
assert\display "basic dotword .word" {
6+
type? first { .word }
7+
} 'dotword
8+
9+
assert\display "dotword with hyphen .my-word" {
10+
type? first { .my-word }
11+
} 'dotword
12+
13+
assert\display "dotword .upper" {
14+
type? first { .upper }
15+
} 'dotword
16+
17+
assert\display "dotword .concat" {
18+
type? first { .concat }
19+
} 'dotword
20+
21+
; Dotwords with single-char operators
22+
assert\display "dotword .+" {
23+
type? first { .+ }
24+
} 'dotword
25+
26+
assert\display "dotword .*" {
27+
type? first { .* }
28+
} 'dotword
29+
30+
assert\display "dotword .>" {
31+
type? first { .> }
32+
} 'dotword
33+
34+
assert\display "dotword .<" {
35+
type? first { .< }
36+
} 'dotword
37+
38+
assert\display "dotword .=" {
39+
type? first { .= }
40+
} 'dotword
41+
42+
assert\display "dotword .!" {
43+
type? first { .! }
44+
} 'dotword
45+
46+
assert\display "dotword .?" {
47+
type? first { .? }
48+
} 'dotword
49+
50+
assert\display "dotword .%" {
51+
type? first { .% }
52+
} 'dotword
53+
54+
assert\display "dotword .-" {
55+
type? first { .- }
56+
} 'dotword
57+
58+
; Dotword with force modifier (*)
59+
assert\display "dotword with force .word*" {
60+
type? first { .word* }
61+
} 'dotword
62+
63+
; Single letter dotword
64+
assert\display "single letter dotword .x" {
65+
type? first { .x }
66+
} 'dotword
67+
68+
; Double dot is opword not dotword
69+
assert\display "double dot .. is opword" {
70+
type? first { .. }
71+
} 'opword
72+
73+
print ""

internal/parsing/04-pipewords.rye

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; Parser tests for pipe-words
2+
print "## Pipe-words"
3+
4+
; Basic pipeword
5+
assert\display "basic pipeword |word" {
6+
type? first { |word }
7+
} 'pipeword
8+
9+
assert\display "pipeword with hyphen |my-word" {
10+
type? first { |my-word }
11+
} 'pipeword
12+
13+
assert\display "pipeword |print" {
14+
type? first { |print }
15+
} 'pipeword
16+
17+
assert\display "pipeword |concat" {
18+
type? first { |concat }
19+
} 'pipeword
20+
21+
; Pipewords with single-char operators
22+
assert\display "pipeword |+" {
23+
type? first { |+ }
24+
} 'pipeword
25+
26+
assert\display "pipeword |*" {
27+
type? first { |* }
28+
} 'pipeword
29+
30+
assert\display "pipeword |-" {
31+
type? first { |- }
32+
} 'pipeword
33+
34+
; Note: |/ is ambiguous - / is context path separator, so |/ starts a pipe-cpath
35+
; assert\display "pipeword |/" { type? first { |/ } } 'pipeword
36+
37+
assert\display "pipeword |>" {
38+
type? first { |> }
39+
} 'pipeword
40+
41+
assert\display "pipeword |<" {
42+
type? first { |< }
43+
} 'pipeword
44+
45+
assert\display "pipeword |=" {
46+
type? first { |= }
47+
} 'pipeword
48+
49+
; Pipeword with force modifier (*)
50+
assert\display "pipeword with force |word*" {
51+
type? first { |word* }
52+
} 'pipeword
53+
54+
; Single letter pipeword
55+
assert\display "single letter pipeword |x" {
56+
type? first { |x }
57+
} 'pipeword
58+
59+
; Multi-char pipewords
60+
assert\display "pipeword |++" {
61+
type? first { |++ }
62+
} 'pipeword
63+
64+
print ""

internal/parsing/05-literals.rye

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
; Parser tests for literal values
2+
print "## Literals"
3+
4+
; Integers
5+
assert\display "positive integer" {
6+
type? first { 123 }
7+
} 'integer
8+
9+
assert\display "negative integer" {
10+
type? first { -456 }
11+
} 'integer
12+
13+
assert\display "zero" {
14+
type? first { 0 }
15+
} 'integer
16+
17+
assert\display "large integer" {
18+
type? first { 999999999 }
19+
} 'integer
20+
21+
; Decimals
22+
assert\display "decimal number" {
23+
type? first { 3.14 }
24+
} 'decimal
25+
26+
assert\display "negative decimal" {
27+
type? first { -2.718 }
28+
} 'decimal
29+
30+
assert\display "decimal with leading zero" {
31+
type? first { 0.5 }
32+
} 'decimal
33+
34+
; Strings
35+
assert\display "double-quoted string" {
36+
type? first { "hello" }
37+
} 'string
38+
39+
assert\display "string with spaces" {
40+
type? first { "hello world" }
41+
} 'string
42+
43+
assert\display "empty string" {
44+
type? first { "" }
45+
} 'string
46+
47+
assert\display "backtick string" {
48+
type? first { `hello` }
49+
} 'string
50+
51+
; String value check
52+
assert\display "string value" {
53+
first { "hello" }
54+
} "hello"
55+
56+
assert\display "string with escape" {
57+
first { "line1\nline2" }
58+
} "line1\nline2"
59+
60+
; Void
61+
assert\display "void" {
62+
type? first { _ }
63+
} 'void
64+
65+
; Comma
66+
assert\display "comma" {
67+
type? first { , }
68+
} 'comma
69+
70+
print ""

0 commit comments

Comments
 (0)