-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lkt lowering: robustify traits checking for nodes
Reject invalid uses of traits, make sure that the Node trait is instantiated with the root node, etc. For #622
- Loading branch information
Showing
10 changed files
with
201 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
testsuite/tests/grammar/invalid_node_traits/derived_node.lkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import lexer_example | ||
|
||
@with_lexer(foo_lexer) | ||
grammar foo_grammar { | ||
@main_rule main_rule <- Example(@example) | ||
} | ||
|
||
@abstract class FooNode implements Node[FooNode] { | ||
} | ||
|
||
class Example : FooNode implements Node[Example] { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import lexer_example | ||
|
||
@with_lexer(foo_lexer) | ||
grammar foo_grammar { | ||
@main_rule main_rule <- Example(@example) | ||
} | ||
|
||
@abstract class FooNode implements Node[Int] { | ||
} | ||
|
||
class Example : FooNode { | ||
} |
12 changes: 12 additions & 0 deletions
12
testsuite/tests/grammar/invalid_node_traits/root_error.lkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import lexer_example | ||
|
||
@with_lexer(foo_lexer) | ||
grammar foo_grammar { | ||
@main_rule main_rule <- skip(Example) | ||
} | ||
|
||
@abstract class FooNode implements Node[FooNode], ErrorNode { | ||
} | ||
|
||
class Example : FooNode { | ||
} |
12 changes: 12 additions & 0 deletions
12
testsuite/tests/grammar/invalid_node_traits/root_no_node.lkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import lexer_example | ||
|
||
@with_lexer(foo_lexer) | ||
grammar foo_grammar { | ||
@main_rule main_rule <- Example(@example) | ||
} | ||
|
||
@abstract class FooNode { | ||
} | ||
|
||
class Example : FooNode implements TokenNode { | ||
} |
12 changes: 12 additions & 0 deletions
12
testsuite/tests/grammar/invalid_node_traits/root_token.lkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import lexer_example | ||
|
||
@with_lexer(foo_lexer) | ||
grammar foo_grammar { | ||
@main_rule main_rule <- Example(@example) | ||
} | ||
|
||
@abstract class FooNode implements Node[FooNode], TokenNode { | ||
} | ||
|
||
class Example : FooNode { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
== derived_node.lkt == | ||
derived_node.lkt:11:36: error: Only the root node can implement the Node trait | ||
11 | class Example : FooNode implements Node[Example] { | ||
| ^^^^^^^^^^^^^ | ||
|
||
|
||
== non_node.lkt == | ||
non_node.lkt:8:36: error: The Node generic trait must be instantiated with the root node (FooNode) | ||
8 | @abstract class FooNode implements Node[Int] { | ||
| ^^^^^^^^^ | ||
|
||
|
||
== root_error.lkt == | ||
root_error.lkt:8:51: error: The root node cannot be an error node | ||
8 | @abstract class FooNode implements Node[FooNode], ErrorNode { | ||
| ^^^^^^^^^ | ||
|
||
|
||
== root_no_node.lkt == | ||
root_no_node.lkt:8:11: error: The root node must implement the Node trait | ||
8 | @abstract class FooNode { | ||
|
||
|
||
== root_token.lkt == | ||
root_token.lkt:8:51: error: The root node cannot be a token node | ||
8 | @abstract class FooNode implements Node[FooNode], TokenNode { | ||
| ^^^^^^^^^ | ||
|
||
|
||
== unknown_trait.lkt == | ||
unknown_trait.lkt:11:36: error: Nodes cannot implement this trait | ||
11 | class Example : FooNode implements AnalysisUnit[FooNode] { | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
|
||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
driver: lkt_compile |
12 changes: 12 additions & 0 deletions
12
testsuite/tests/grammar/invalid_node_traits/unknown_trait.lkt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import lexer_example | ||
|
||
@with_lexer(foo_lexer) | ||
grammar foo_grammar { | ||
@main_rule main_rule <- Example(@example) | ||
} | ||
|
||
@abstract class FooNode implements Node[FooNode] { | ||
} | ||
|
||
class Example : FooNode implements AnalysisUnit[FooNode] { | ||
} |