| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -712,6 +712,31 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> { | |
| => | ||
| (argument name_node: (identifier #{lbl})? value: {val}) | ||
| ), | ||
| // An additional labeled trailing closure, such as the `c: { ... }` in | ||
| // `foo { 42 } c: { ... }`, is turned into an argument to the function. | ||
| rule!( | ||
| (multipleTrailingClosureElement label: @@label closure: @closure) | ||
| => | ||
| (argument name_node: (identifier #{label}) value: {closure}) | ||
| ), | ||
| rule!( | ||
| (macroExpansionExpr | ||
| macroName: @@name | ||
| genericArgumentClause: (genericArgumentClause arguments: (genericArgument argument: @type_args)*)? | ||
|
Comment thread
Comment on lines
+724
to
+725
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWe're not handling moduleSelector anywhere yet, so this is consistent.
Sorry, something went wrong.
All reactions
|
||
| arguments: _* @args | ||
| trailingClosure: _? @trailing | ||
| additionalTrailingClosures: _* @additional) | ||
| => | ||
| macro_call_expr { | ||
| let mut arguments = args; | ||
| arguments.extend(trailing.into_iter().map(|trailing| tree!((argument value: {trailing})))); | ||
| arguments.extend(additional); | ||
| tree!((macro_call_expr | ||
| macro_name_node: (identifier #{name}) | ||
| type_argument: {type_args} | ||
| argument: {arguments})) | ||
| } | ||
| ), | ||
| // Member access (`list.append`). The `declName` is itself a | ||
| // `declReferenceExpr`; pull its `baseName` out as the member identifier. | ||
| // A leading-dot access (`.foo`) has no explicit base — the base is an | ||
| Expand Down Expand Up | @@ -1196,10 +1221,6 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> { | |
| } | ||
| } | ||
| ), | ||
| // Selector expression: `#selector(inner)` -- not yet supported | ||
| // (swift-syntax represents `#selector`/`#keyPath` and other macro | ||
| // expansions uniformly as a `macroExpansionExpr`). | ||
| rule!((macroExpansionExpr) => (unsupported_node)), | ||
| // A nominal type's `inheritanceClause` (`: Base, Proto`) becomes a list | ||
| // of `base_type`s, one per inherited type. Each declaration keyword | ||
| // gets its own rule; the bodies are identical but for the keyword. | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| #expect(value == 42) | ||
|
|
||
| #custom<Int>(value) { | ||
| value | ||
| } completion: { | ||
| value | ||
| } | ||
|
|
||
| #Preview { | ||
| let previewValue = 42 | ||
| previewValue | ||
| } | ||
|
|
||
| --- | ||
|
|
||
| sourceFile | ||
| endOfFileToken: endOfFile | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| macroExpansionExpr | ||
| leftParen: ( | ||
| rightParen: ) | ||
| arguments: | ||
| labeledExpr | ||
| expression: | ||
| infixOperatorExpr | ||
| operator: | ||
| binaryOperatorExpr | ||
| operator: binaryOperator "==" | ||
| leftOperand: | ||
| declReferenceExpr | ||
| baseName: identifier "value" | ||
| rightOperand: | ||
| integerLiteralExpr | ||
| literal: integerLiteral "42" | ||
| additionalTrailingClosures: | ||
| macroName: identifier "expect" | ||
| pound: # | ||
| codeBlockItem | ||
| item: | ||
| macroExpansionExpr | ||
| leftParen: ( | ||
| rightParen: ) | ||
| arguments: | ||
| labeledExpr | ||
| expression: | ||
| declReferenceExpr | ||
| baseName: identifier "value" | ||
| additionalTrailingClosures: | ||
| multipleTrailingClosureElement | ||
| colon: : | ||
| label: identifier "completion" | ||
| closure: | ||
| closureExpr | ||
| leftBrace: { | ||
| rightBrace: } | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| declReferenceExpr | ||
| baseName: identifier "value" | ||
| trailingClosure: | ||
| closureExpr | ||
| leftBrace: { | ||
| rightBrace: } | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| declReferenceExpr | ||
| baseName: identifier "value" | ||
| genericArgumentClause: | ||
| genericArgumentClause | ||
| arguments: | ||
| genericArgument | ||
| argument: | ||
| identifierType | ||
| name: identifier "Int" | ||
| leftAngle: < | ||
| rightAngle: > | ||
| macroName: identifier "custom" | ||
| pound: # | ||
| codeBlockItem | ||
| item: | ||
| macroExpansionExpr | ||
| arguments: | ||
| additionalTrailingClosures: | ||
| trailingClosure: | ||
| closureExpr | ||
| leftBrace: { | ||
| rightBrace: } | ||
| statements: | ||
| codeBlockItem | ||
| item: | ||
| variableDecl | ||
| attributes: | ||
| modifiers: | ||
| bindingSpecifier: let | ||
| bindings: | ||
| patternBinding | ||
| initializer: | ||
| initializerClause | ||
| equal: = | ||
| value: | ||
| integerLiteralExpr | ||
| literal: integerLiteral "42" | ||
| pattern: | ||
| identifierPattern | ||
| identifier: identifier "previewValue" | ||
| codeBlockItem | ||
| item: | ||
| declReferenceExpr | ||
| baseName: identifier "previewValue" | ||
| macroName: identifier "Preview" | ||
| pound: # | ||
|
|
||
| --- | ||
|
|
||
| top_level source="⟨body⟩" | ||
| body: | ||
| block source="⟨stmt⟩\n\n⟨stmt⟩\n\n⟨stmt⟩" | ||
| stmt: | ||
| macro_call_expr source="#⟨macro_name_node⟩(⟨argument⟩)" | ||
| macro_name_node: identifier "expect" source="expect" | ||
| argument: | ||
| argument source="⟨value⟩" | ||
| value: | ||
| binary_expr source="⟨left⟩ ⟨operator⟩ ⟨right⟩" | ||
| left: identifier "value" source="value" | ||
| operator: infix_operator "==" source="==" | ||
| right: int_literal "42" source="42" | ||
| macro_call_expr source="#⟨macro_name_node⟩<⟨type_argument⟩>(⟨argument⟩) ⟨argument⟩ ⟨argument⟩" | ||
| macro_name_node: identifier "custom" source="custom" | ||
| type_argument: identifier "Int" source="Int" | ||
| argument: | ||
| argument source="⟨value⟩" | ||
| value: identifier "value" source="value" | ||
| argument source="⟨value⟩" | ||
| value: | ||
| function_expr source="{\n ⟨body⟩\n}" | ||
| body: | ||
| block source="⟨stmt⟩" | ||
| stmt: identifier "value" source="value" | ||
| argument source="⟨name_node⟩: ⟨value⟩" | ||
| name_node: identifier "completion" source="completion" | ||
| value: | ||
| function_expr source="{\n ⟨body⟩\n}" | ||
| body: | ||
| block source="⟨stmt⟩" | ||
| stmt: identifier "value" source="value" | ||
| macro_call_expr source="#⟨macro_name_node⟩ ⟨argument⟩" | ||
| macro_name_node: identifier "Preview" source="Preview" | ||
| argument: | ||
| argument source="⟨value⟩" | ||
| value: | ||
| function_expr source="{\n ⟨body⟩\n}" | ||
| body: | ||
| block source="⟨stmt⟩\n ⟨stmt⟩" | ||
| stmt: | ||
| variable_declaration source="⟨modifier⟩ ⟨pattern⟩ = ⟨value⟩" | ||
| modifier: modifier "let" source="let" | ||
| pattern: identifier "previewValue" source="previewValue" | ||
| value: int_literal "42" source="42" | ||
| identifier "previewValue" source="previewValue" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #expect(value == 42) | ||
|
|
||
| #custom<Int>(value) { | ||
| value | ||
| } completion: { | ||
| value | ||
| } | ||
|
|
||
| #Preview { | ||
| let previewValue = 42 | ||
| previewValue | ||
| } |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI think handling these as macro calls might be just fine. And if not we can always tweak later.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.