Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
Finish expanding member types
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Feb 9, 2015
1 parent b4505ef commit 67434b8
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 95 deletions.
36 changes: 36 additions & 0 deletions src/rules/mson-member-type-name.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,49 @@ module.exports =
expanded: {}
dataStructures: {}

# Given a list of elements, recursively expand member type name contained
# in a group of elements inside the initial group of elements
#
# @param elements [Object] List of elements either from type section or a member type
diveIntoElements: (elements) ->
for member in elements
switch member['class']

when 'property', 'value'
superType = member.content.valueDefinition.typeDefinition.typeSpecification.name

# If super type is a valid symbol
if typeof superType is 'object' and superType?.literal
@expandMember superType.literal, @dataStructures[superType.literal]

superTypeBaseName = @dataStructures[superType.literal].typeDefinition.typeSpecification.name
member.content.valueDefinition.typeDefinition.typeSpecification.name = superTypeBaseName

# If super type is not an object or array or enum
if superTypeBaseName in ['object', 'array', 'value']
memberTypeSection =
content: []

memberTypeSection['class'] = 'memberType'
rule.copyMembers @dataStructures[superType.literal], memberTypeSection
member.content.sections.push memberTypeSection if memberTypeSection.content.length

when 'oneOf', 'group'
@diveIntoElements member.content

# Given a data structure, expand its member type recusrively
#
# @param name [String] Name of the data structure
# @param dataStructure [Object] Data structure
expandMember: (name, dataStructure) ->
return if @expanded[name]

# Check for member type name
for section in dataStructure.sections
if section['class'] is 'memberType'

@diveIntoElements section.content

# Denote this type as expanded
@expanded[name] = true

Expand Down
13 changes: 7 additions & 6 deletions src/rules/mson-mixin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ module.exports =
expanded: {}
dataStructures: {}

# Given a list of elements, recursively expand mixins contained
# in a group of elements inside the initial group of elements
#
#
# @param elements [Object]
# @param sectionOrMember [Object]
diveIntoMember: (elements, sectionOrMember) ->
# @param elements [Object] List of elements either from type section or a member type
# @param sectionOrMember [Object] Type section or a member type
diveIntoElements: (elements, sectionOrMember) ->
for member in elements
switch member['class']

Expand All @@ -26,7 +27,7 @@ module.exports =
content: []

# Recursively dive into the elements
@diveIntoMember member.content, memberType
@diveIntoElements member.content, memberType

# Replace the original member with out new member
member.content = memberType.content
Expand All @@ -50,7 +51,7 @@ module.exports =
memberTypeSection =
content: []

@diveIntoMember section.content, memberTypeSection
@diveIntoElements section.content, memberTypeSection

# Replace section content with the new content
section.content = memberTypeSection.content
Expand Down
Loading

0 comments on commit 67434b8

Please sign in to comment.