Skip to content

Commit

Permalink
Merge pull request #97 from fink-lang/hyphenated-idents-jsx-props
Browse files Browse the repository at this point in the history
hyphenated idents and  jsx props
  • Loading branch information
kollhof authored Jul 1, 2021
2 parents c405b68 + 5e01bfb commit b012a7e
Show file tree
Hide file tree
Showing 10 changed files with 856 additions and 789 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {

resolver: '@fink/jest/cjs/module-resolver.js',

snapshotSerializers: ['<rootDir>/build/test-helpers/snapshot.js'],
snapshotSerializers: ['<rootDir>/src/testing/snapshot.fnk'],
snapshotResolver: '@fink/jest/snapshot-resolver.js',

modulePathIgnorePatterns: ['<rootDir>/build/'],
Expand Down
1,396 changes: 698 additions & 698 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"build:fnk-cjs": "fnk --module-type cjs --src ./src --out-dir build/pkg/cjs --ignore './src/**/*.test.fnk'",
"build:files-cjs": "cp package-cjs.json ./build/pkg/cjs/package.json",
"build:files": "cp package.json ./README.md ./LICENSE ./build/pkg/",
"test": "run test:build-helpers jest",
"test:build-helpers": "fnk --module-type cjs --src ./src/testing --out-dir build/test-helpers",
"test": "run jest",
"jest": "jest --verbose --runInBand --no-cache ",
"cd": "run clean test build release",
"release": "semantic-release"
Expand Down
7 changes: 6 additions & 1 deletion src/lang/identifier/init.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ describe 'indentifiers', fn:

it 'parses a non-word', fn:
expect
parse_expr ' π '
parse_expr ' π '
to_match_snapshot

it 'parses a hyphenated', fn:
expect
parse_expr ' foo-bar '
to_match_snapshot
4 changes: 3 additions & 1 deletion src/lang/identifier/init.test.fnk.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`indentifiers parses a non-word 1`] = `ident (1:2-1:3) π`;
exports[`indentifiers parses a hyphenated 1`] = `ident (1:1-1:8) foo-bar`;

exports[`indentifiers parses a non-word 1`] = `ident (1:1-1:2) π`;

exports[`indentifiers parses a word 1`] = `ident (1:2-1:8) foobar`;
6 changes: 6 additions & 0 deletions src/lang/jsx/init.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ describe 'JSX', fn:
to_match_snapshot


it 'parses hyphenated attr: <Foobar spam_ham="ni" />', fn:
expect
parse_expr '<Foobar spam-ham="ni" />'
to_match_snapshot


it "parses self closing elem with str attr: <Foobar spam='ni' />", fn:
expect
parse_expr "<Foobar spam='ni' />"
Expand Down
8 changes: 8 additions & 0 deletions src/lang/jsx/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ jsx:elem (1:0-3:6) div
"\\n"
`;
exports[`JSX parses hyphenated attr: <Foobar spam_ham="ni" /> 1`] = `
jsx:elem (1:0-1:24) Foobar
jsx:attr (1:8-1:21)
ident (1:8-1:16) spam-ham
string " (1:17-1:21)
'ni'
`;
exports[`JSX parses self closing elem with expr attr: <Foobar spam={ni} /> 1`] = `
jsx:elem (1:0-1:20) Foobar
jsx:attr (1:8-1:17)
Expand Down
4 changes: 2 additions & 2 deletions src/lexer/tokens.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fink_lex = rx'
|(?<empty>\b_\b)

|(?<number>[0-9][\._a-fA-Fxobe+0-9-]*)
|(?<ident>[_$\p{L}][_$\p{L}\p{N}]*)
|(?<ident>[_$\p{L}][-_$\p{L}\p{N}]*)

|(?<spread>\.\.\.)
|(?<member>\.)
Expand Down Expand Up @@ -117,7 +117,7 @@ jsx_elem_lex = rx'
|(?<empty>\b_\b)

|(?<number>[0-9][\._a-fA-Fxobe+0-9-]*)
|(?<ident>[_$\p{L}][_$\p{L}\p{N}]*)
|(?<ident>[_$\p{L}][-_$\p{L}\p{N}]*)

|(?<spread>\.\.\.)
|(?<member>\.)
Expand Down
12 changes: 12 additions & 0 deletions src/lexer/tokens.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ describe 'tokenizer', fn:
expect
foo '
01234567
foo_bar
foo-bar
_foo_bar
_foo_bar_123
foo bar
(shrub)
(spam ni, hi)
Expand Down Expand Up @@ -83,6 +87,14 @@ describe 'JSX tokenizer', fn:
to_match_snapshot


it 'tokenizes hyphenated attr', fn:
expect
foo '
<Foobar spam-ham />
'
to_match_snapshot


it 'tokenizes expr-attr', fn:
expect
foo '
Expand Down
203 changes: 119 additions & 84 deletions src/lexer/tokens.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ end (51-51) (7:0-7:0)
\\"\\""
`;
exports[`JSX tokenizer tokenizes hyphenated attr 1`] = `
"jsx-elem-start (0-1) (1:0-1:1)
\\"<\\"
ident (1-7) (1:1-1:7)
\\"Foobar\\"
ignorable (7-8) (1:7-1:8)
\\" \\"
ident (8-16) (1:8-1:16)
\\"spam-ham\\"
ignorable (16-17) (1:16-1:17)
\\" \\"
jsx-elem-close (17-19) (1:17-1:19)
\\"/>\\"
ignorable (19-20) (1:19-2:0)
\\"\\\\n\\"
end (20-20) (2:0-2:0)
\\"\\""
`;
exports[`JSX tokenizer tokenizes jsx 1`] = `
"jsx-elem-start (0-1) (1:0-1:1)
\\"<\\"
Expand Down Expand Up @@ -151,149 +170,165 @@ exports[`tokenizer tokenizes 1`] = `
\\"01234567\\"
ignorable (8-9) (1:8-2:0)
\\"\\\\n\\"
ident (9-12) (2:0-2:3)
ident (9-16) (2:0-2:7)
\\"foo_bar\\"
ignorable (16-17) (2:7-3:0)
\\"\\\\n\\"
ident (17-24) (3:0-3:7)
\\"foo-bar\\"
ignorable (24-25) (3:7-4:0)
\\"\\\\n\\"
ident (25-33) (4:0-4:8)
\\"_foo_bar\\"
ignorable (33-34) (4:8-5:0)
\\"\\\\n\\"
ident (34-46) (5:0-5:12)
\\"_foo_bar_123\\"
ignorable (46-47) (5:12-6:0)
\\"\\\\n\\"
ident (47-50) (6:0-6:3)
\\"foo\\"
ignorable (12-13) (2:3-2:4)
ignorable (50-51) (6:3-6:4)
\\" \\"
ident (13-16) (2:4-2:7)
ident (51-54) (6:4-6:7)
\\"bar\\"
ignorable (16-17) (2:7-3:0)
ignorable (54-55) (6:7-7:0)
\\"\\\\n\\"
( (17-18) (3:0-3:1)
ident (18-23) (3:1-3:6)
( (55-56) (7:0-7:1)
ident (56-61) (7:1-7:6)
\\"shrub\\"
) (23-24) (3:6-3:7)
ignorable (24-25) (3:7-4:0)
) (61-62) (7:6-7:7)
ignorable (62-63) (7:7-8:0)
\\"\\\\n\\"
( (25-26) (4:0-4:1)
ident (26-30) (4:1-4:5)
( (63-64) (8:0-8:1)
ident (64-68) (8:1-8:5)
\\"spam\\"
ignorable (30-31) (4:5-4:6)
ignorable (68-69) (8:5-8:6)
\\" \\"
ident (31-33) (4:6-4:8)
ident (69-71) (8:6-8:8)
\\"ni\\"
, (33-34) (4:8-4:9)
ignorable (34-35) (4:9-4:10)
, (71-72) (8:8-8:9)
ignorable (72-73) (8:9-8:10)
\\" \\"
ident (35-37) (4:10-4:12)
ident (73-75) (8:10-8:12)
\\"hi\\"
) (37-38) (4:12-4:13)
ignorable (38-39) (4:13-5:0)
) (75-76) (8:12-8:13)
ignorable (76-77) (8:13-9:0)
\\"\\\\n\\"
ident (39-40) (5:0-5:1)
ident (77-78) (9:0-9:1)
\\"a\\"
ignorable (40-41) (5:1-5:2)
ignorable (78-79) (9:1-9:2)
\\" \\"
+ (41-42) (5:2-5:3)
ignorable (42-43) (5:3-5:4)
+ (79-80) (9:2-9:3)
ignorable (80-81) (9:3-9:4)
\\" \\"
ident (43-44) (5:4-5:5)
ident (81-82) (9:4-9:5)
\\"b\\"
ignorable (44-45) (5:5-5:6)
ignorable (82-83) (9:5-9:6)
\\" \\"
- (45-46) (5:6-5:7)
ignorable (46-47) (5:7-5:8)
- (83-84) (9:6-9:7)
ignorable (84-85) (9:7-9:8)
\\" \\"
ident (47-48) (5:8-5:9)
ident (85-86) (9:8-9:9)
\\"c\\"
ignorable (48-49) (5:9-5:10)
ignorable (86-87) (9:9-9:10)
\\" \\"
* (49-50) (5:10-5:11)
ignorable (50-51) (5:11-5:12)
* (87-88) (9:10-9:11)
ignorable (88-89) (9:11-9:12)
\\" \\"
ident (51-52) (5:12-5:13)
ident (89-90) (9:12-9:13)
\\"d\\"
ignorable (52-53) (5:13-5:14)
ignorable (90-91) (9:13-9:14)
\\" \\"
/ (53-54) (5:14-5:15)
ignorable (54-55) (5:15-5:16)
/ (91-92) (9:14-9:15)
ignorable (92-93) (9:15-9:16)
\\" \\"
ident (55-56) (5:16-5:17)
ident (93-94) (9:16-9:17)
\\"f\\"
ignorable (56-57) (5:17-5:18)
ignorable (94-95) (9:17-9:18)
\\" \\"
^ (57-58) (5:18-5:19)
ignorable (58-59) (5:19-5:20)
^ (95-96) (9:18-9:19)
ignorable (96-97) (9:19-9:20)
\\" \\"
ident (59-60) (5:20-5:21)
ident (97-98) (9:20-9:21)
\\"g\\"
ignorable (60-61) (5:21-6:0)
ignorable (98-99) (9:21-10:0)
\\"\\\\n\\"
str-start (61-62) (6:0-6:1)
str-start (99-100) (10:0-10:1)
\\"\\\\\\"\\"
str-text (62-67) (6:1-6:6)
str-text (100-105) (10:1-10:6)
\\"shrub\\"
str-end (67-68) (6:6-6:7)
str-end (105-106) (10:6-10:7)
\\"\\\\\\"\\"
ignorable (68-69) (6:7-7:0)
ignorable (106-107) (10:7-11:0)
\\"\\\\n\\"
str-start (69-70) (7:0-7:1)
str-start (107-108) (11:0-11:1)
\\"\\\\\\"\\"
str-text (70-73) (7:1-7:4)
str-text (108-111) (11:1-11:4)
\\"ni \\"
str-expr-start (73-75) (7:4-7:6)
str-expr-start (111-113) (11:4-11:6)
\\"\${\\"
ident (75-78) (7:6-7:9)
ident (113-116) (11:6-11:9)
\\"ham\\"
str-expr-end (78-79) (7:9-7:10)
str-expr-end (116-117) (11:9-11:10)
\\"}\\"
str-text (79-84) (7:10-7:15)
str-text (117-122) (11:10-11:15)
\\" spam\\"
str-end (84-85) (7:15-7:16)
str-end (122-123) (11:15-11:16)
\\"\\\\\\"\\"
ignorable (85-86) (7:16-8:0)
ignorable (123-124) (11:16-12:0)
\\"\\\\n\\"
ident (86-89) (8:0-8:3)
ident (124-127) (12:0-12:3)
\\"foo\\"
. (89-90) (8:3-8:4)
ident (90-93) (8:4-8:7)
. (127-128) (12:3-12:4)
ident (128-131) (12:4-12:7)
\\"bar\\"
ignorable (93-94) (8:7-8:8)
ignorable (131-132) (12:7-12:8)
\\" \\"
... (94-97) (8:8-8:11)
ident (97-99) (8:11-8:13)
... (132-135) (12:8-12:11)
ident (135-137) (12:11-12:13)
\\"ni\\"
ignorable (99-100) (8:13-9:0)
ignorable (137-138) (12:13-13:0)
\\"\\\\n\\"
[ (100-101) (9:0-9:1)
true (101-105) (9:1-9:5)
, (105-106) (9:5-9:6)
ignorable (106-107) (9:6-9:7)
\\" \\"
false (107-112) (9:7-9:12)
] (112-113) (9:12-9:13)
ignorable (113-114) (9:13-10:0)
[ (138-139) (13:0-13:1)
true (139-143) (13:1-13:5)
, (143-144) (13:5-13:6)
ignorable (144-145) (13:6-13:7)
\\" \\"
false (145-150) (13:7-13:12)
] (150-151) (13:12-13:13)
ignorable (151-152) (13:13-14:0)
\\"\\\\n\\"
true (114-118) (10:0-10:4)
, (118-119) (10:4-10:5)
ignorable (119-120) (10:5-10:6)
true (152-156) (14:0-14:4)
, (156-157) (14:4-14:5)
ignorable (157-158) (14:5-14:6)
\\" \\"
false (120-125) (10:6-10:11)
ignorable (125-126) (10:11-11:0)
false (158-163) (14:6-14:11)
ignorable (163-164) (14:11-15:0)
\\"\\\\n\\"
ident (126-127) (11:0-11:1)
ident (164-165) (15:0-15:1)
\\"a\\"
ignorable (127-128) (11:1-11:2)
ignorable (165-166) (15:1-15:2)
\\" \\"
not (128-131) (11:2-11:5)
ignorable (131-132) (11:5-11:6)
not (166-169) (15:2-15:5)
ignorable (169-170) (15:5-15:6)
\\" \\"
ident (132-133) (11:6-11:7)
ident (170-171) (15:6-15:7)
\\"b\\"
ignorable (133-134) (11:7-12:0)
ignorable (171-172) (15:7-16:0)
\\"\\\\n\\"
ident (134-137) (12:0-12:3)
ident (172-175) (16:0-16:3)
\\"foo\\"
ignorable (137-138) (12:3-12:4)
ignorable (175-176) (16:3-16:4)
\\" \\"
in (138-140) (12:4-12:6)
ignorable (140-141) (12:6-12:7)
in (176-178) (16:4-16:6)
ignorable (178-179) (16:6-16:7)
\\" \\"
ident (141-144) (12:7-12:10)
ident (179-182) (16:7-16:10)
\\"bar\\"
ignorable (144-145) (12:10-13:0)
ignorable (182-183) (16:10-17:0)
\\"\\\\n\\"
end (145-145) (13:0-13:0)
end (183-183) (17:0-17:0)
\\"\\""
`;
Expand Down

0 comments on commit b012a7e

Please sign in to comment.