This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
204 additions
and
49 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
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
module.exports = | ||
|
||
dataStructures: (dataStructures) -> | ||
# Variables | ||
dataStructures: {} | ||
|
||
init: (dataStructures) -> | ||
@dataStructures = dataStructures |
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 |
---|---|---|
@@ -1,3 +1,52 @@ | ||
rule = require './rule' | ||
|
||
module.exports = | ||
|
||
dataStructures: (dataStructures) -> | ||
# Variables | ||
expanded: {} | ||
dataStructures: {} | ||
|
||
# Given a data structure, expand its mixins recusrively | ||
# | ||
# @param name [String] Name of the data structure | ||
# @param dataStructure [Object] Data structure | ||
expandMixin: (name, dataStructure) -> | ||
return if @expanded[name] | ||
|
||
# Check for mixin | ||
for section in dataStructure.sections | ||
if section['class'] is 'memberType' | ||
|
||
# New content for the section | ||
memberTypeSection = | ||
content: [] | ||
|
||
for member in section.content | ||
if member['class'] is 'mixin' | ||
|
||
# Expand the super type first | ||
superType = member.content.typeSpecification.name | ||
@expandMixin superType.literal, @dataStructures[superType.literal] | ||
|
||
rule.copyMembers @dataStructures[superType.literal], memberTypeSection | ||
|
||
else | ||
memberTypeSection.content.push member | ||
|
||
# Replace section content with the new content | ||
section.content = memberTypeSection.content | ||
|
||
# Denote this type as expanded | ||
@expanded[name] = true | ||
|
||
init: (dataStructures) -> | ||
@expanded = {} | ||
@dataStructures = dataStructures | ||
|
||
# Initiate flags | ||
for name, dataStructure of @dataStructures | ||
@expanded[name] = false | ||
|
||
# Actual expansion | ||
for name, dataStructure of @dataStructures | ||
@expandMixin name, dataStructure |
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,14 @@ | ||
module.exports = | ||
|
||
# Copy all member types from one data structure to another | ||
# | ||
# @param dataStructure [Object] The super type data structure | ||
# @param memberTypeSection [Object] Member Type Section to be copied into | ||
copyMembers: (dataStructure, memberTypeSection) -> | ||
return if not dataStructure | ||
|
||
for section in dataStructure.sections | ||
if section['class'] is 'memberType' | ||
|
||
for member in section.content | ||
memberTypeSection.content.push member |
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