Skip to content

Commit

Permalink
parsing strings
Browse files Browse the repository at this point in the history
  • Loading branch information
azizghuloum committed Nov 25, 2024
1 parent a2fff5d commit 9a318a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/AST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type atom_tag =
| "regex_pattern"
| "type_identifier"
| "jsx_text"
| "string_fragment"
| "string"
| "ERROR"
| "other";

Expand All @@ -19,9 +19,9 @@ export const id_tags: { [k in atom_tag]: boolean } = {
shorthand_property_identifier: true,
jsx_text: false,
number: false,
string: false,
other: false,
regex_pattern: false,
string_fragment: false,
ERROR: false,
};

Expand All @@ -39,7 +39,7 @@ export type list_tag =
| "statement_block"
| "empty_statement"
| "array"
| "string"
| "required_parameter"
| "member_expression"
| "parenthesized_expression"
| "ternary_expression"
Expand Down Expand Up @@ -73,7 +73,7 @@ export const list_tags: { [k in list_tag]: list_tag } = {
empty_statement: "empty_statement",
slice: "slice",
array: "array",
string: "string",
required_parameter: "required_parameter",
member_expression: "member_expression",
parenthesized_expression: "parenthesized_expression",
ternary_expression: "ternary_expression",
Expand Down
12 changes: 8 additions & 4 deletions src/parser-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function absurdly(node: Parser.SyntaxNode): AST {
case "type_identifier":
case "shorthand_property_identifier":
case "property_identifier":
case "string_fragment":
case "ERROR": {
return { type: "atom", tag: node.type, content: node.text };
}
Expand All @@ -52,6 +51,9 @@ function absurdly(node: Parser.SyntaxNode): AST {
}
}
} else {
if (node.type === "string") {
return { type: "atom", tag: "string", content: node.text };
}
const ls = children.filter((x) => x.type !== "comment").map(absurdly);
switch (node.type) {
case "expression_statement": {
Expand All @@ -67,9 +69,11 @@ function absurdly(node: Parser.SyntaxNode): AST {
}
}
case "required_parameter": {
assert(ls.length === 1);
const x = ls[0];
return x;
if (ls.length === 1) {
return ls[0];
} else {
return { type: "list", tag: "required_parameter", content: array_to_ll(ls) };
}
}
case "arrow_function": {
if (ls.length === 3) {
Expand Down

0 comments on commit 9a318a2

Please sign in to comment.