示例#1
0
    def stateParse(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, SensitivityList.OpenBlock):
            return
        elif isinstance(
                currentBlock,
            (SensitivityList.ItemBlock, SensitivityList.DelimiterBlock)):
            return
        elif isinstance(currentBlock, SensitivityList.CloseBlock):
            parserState.Pop()
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise GroupParserException("End of generic list not found.",
                                   currentBlock)
示例#2
0
    def stateParse(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, Architecture.NameBlock):
            parserState.NextState = cls.stateParseDeclarations
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise GroupParserException(
            "End of architecture declaration not found.".format(
                block=currentBlock.__class__.__qualname__), currentBlock)
示例#3
0
    def stateParsePorts(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, PortList.OpenBlock):
            parserState.NextState = cls.stateParseDeclarations
            parserState.PushState = PortListGroup.stateParse
            parserState.NextGroup = PortListGroup(parserState.LastGroup,
                                                  currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise GroupParserException("End of port clause not found.",
                                   currentBlock)
示例#4
0
    def stateParse(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, PackageBody.NameBlock):
            return
        elif isinstance(currentBlock, PackageBody.EndBlock):
            parserState.NextGroup = cls(parserState.LastGroup,
                                        parserState.BlockMarker,
                                        parserState.Block)
            parserState.Pop()
            parserState.BlockMarker = None
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        else:
            for block in cls.DECLARATION_SIMPLE_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.DECLARATION_SIMPLE_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

            for block in cls.DECLARATION_COMPOUND_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.DECLARATION_COMPOUND_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.NextGroup = group(parserState.LastGroup,
                                                  parserState.BlockMarker,
                                                  currentBlock)
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise GroupParserException(
            "End of package body declaration not found.".format(
                block=currentBlock.__class__.__qualname__), currentBlock)
示例#5
0
    def stateParseDeclarations(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, Entity.BeginBlock):
            parserState.NextState = cls.stateParseStatements
            return
        elif isinstance(currentBlock, Entity.EndBlock):
            parserState.NextGroup = cls(parserState.LastGroup,
                                        parserState.BlockMarker,
                                        parserState.Block)
            parserState.Pop()
            parserState.BlockMarker = None
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        else:
            for block in cls.DECLARATION_SIMPLE_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.DECLARATION_SIMPLE_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

            for block in cls.DECLARATION_COMPOUND_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.DECLARATION_COMPOUND_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise GroupParserException(
            "End of entity declarative region not found.", currentBlock)
示例#6
0
    def stateParseGenerics(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, GenericList.OpenBlock):
            parserState.NextState = cls.stateParseParameters
            parserState.PushState = GenericListGroup.stateParse
            parserState.NextGroup = GenericListGroup(parserState.LastGroup,
                                                     currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, ParameterList.OpenBlock):
            parserState.NextState = cls.stateParseDeclarations
            parserState.PushState = ParameterListGroup.stateParse
            parserState.NextGroup = ParameterListGroup(parserState.LastGroup,
                                                       currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, Function.ReturnTypeBlock):
            if isinstance(currentBlock.EndToken, EndToken):
                parserState.Pop()
            else:
                parserState.NextState = cls.stateParse2
                parserState.ReIssue = True
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise BlockParserException("End of generic clause not found.",
                                   currentBlock)
示例#7
0
    def stateParseStatements(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, Process.EndBlock):
            parserState.NextGroup = cls(parserState.LastGroup,
                                        parserState.BlockMarker,
                                        parserState.Block)
            parserState.Pop()
            parserState.BlockMarker = None
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        else:
            for block in cls.STATEMENT_SIMPLE_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.STATEMENT_SIMPLE_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

            for block in cls.STATEMENT_COMPOUND_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.STATEMENT_COMPOUND_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise BlockParserException("End of process declaration not found.",
                                   currentBlock)
示例#8
0
    def stateParseDeclarations(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, Architecture.BeginBlock):
            parserState.NextState = cls.stateParseStatements
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        else:
            for block in cls.DECLARATION_SIMPLE_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.DECLARATION_SIMPLE_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

            for block in cls.DECLARATION_COMPOUND_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.DECLARATION_COMPOUND_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise GroupParserException(
            "End of architecture declaration not found.".format(
                block=currentBlock.__class__.__qualname__), currentBlock)
示例#9
0
    def stateParse(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, Context.NameBlock):
            parserState.NextGroup = cls(parserState.LastGroup, currentBlock)
            parserState.BlockMarker = currentBlock
            #parserState.NextState =   cls.stateParseGenerics
            return
        elif isinstance(currentBlock, Context.EndBlock):
            #parserState.NextGroup =   cls(parserState.LastGroup, parserState.BlockMarker, parserState.Block)
            #parserState.Pop()
            #parserState.BlockMarker = None
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        else:
            for block in cls.SIMPLE_BLOCKS:
                if isinstance(currentBlock, block):
                    group = cls.SIMPLE_BLOCKS[block]
                    parserState.PushState = group.stateParse
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise GroupParserException(
            "End of context declaration not found.".format(
                block=currentBlock.__class__.__qualname__), currentBlock)
示例#10
0
    def stateParse(cls, parserState: ParserState):
        currentBlock = parserState.Block

        if isinstance(currentBlock, GenericList.OpenBlock):
            return
        elif isinstance(
                currentBlock,
                pyVHDLParser.Blocks.InterfaceObject.InterfaceConstantBlock):
            parserState.PushState = GenericListItemGroup.stateParse
            parserState.NextGroup = GenericListItemGroup(
                parserState.LastGroup, currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, GenericList.CloseBlock):
            parserState.Pop()
            return
        elif isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return

        if isinstance(currentBlock, EndOfDocumentBlock):
            parserState.NextGroup = EndOfDocumentGroup(currentBlock)
            return

        raise GroupParserException("End of generic list not found.",
                                   currentBlock)
示例#11
0
    def stateDocument(cls, parserState: ParserState):
        from pyVHDLParser.Groups.DesignUnit import ContextGroup, EntityGroup, ArchitectureGroup, PackageGroup, PackageBodyGroup, ConfigurationGroup
        from pyVHDLParser.Groups.Reference import LibraryGroup, UseGroup
        from pyVHDLParser.Groups.Comment import CommentGroup, WhitespaceGroup

        SIMPLE_BLOCKS = {
            Library.StartBlock: LibraryGroup,
            Use.StartBlock: UseGroup
        }
        COMPOUND_BLOCKS = {
            Context.NameBlock: ContextGroup,
            Entity.NameBlock: EntityGroup,
            Architecture.NameBlock: ArchitectureGroup,
            Package.NameBlock: PackageGroup,
            PackageBody.NameBlock: PackageBodyGroup,
            Configuration.NameBlock: ConfigurationGroup
        }

        currentBlock = parserState.Block

        if isinstance(currentBlock, (LinebreakBlock, IndentationBlock)):
            parserState.PushState = WhitespaceGroup.stateParse
            parserState.NextGroup = WhitespaceGroup(parserState.LastGroup,
                                                    currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        elif isinstance(currentBlock, CommentBlock):
            parserState.PushState = CommentGroup.stateParse
            parserState.NextGroup = CommentGroup(parserState.LastGroup,
                                                 currentBlock)
            parserState.BlockMarker = currentBlock
            parserState.ReIssue = True
            return
        else:
            for blk in SIMPLE_BLOCKS:
                if isinstance(currentBlock, blk):
                    group = SIMPLE_BLOCKS[blk]
                    parserState.PushState = group.stateParse
                    parserState.NextGroup = group(parserState.LastGroup,
                                                  currentBlock)
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

            for blk in COMPOUND_BLOCKS:
                if isinstance(currentBlock, blk):
                    group = COMPOUND_BLOCKS[blk]
                    parserState.PushState = group.stateParse
                    parserState.NextGroup = group(parserState.LastGroup,
                                                  currentBlock)
                    parserState.BlockMarker = currentBlock
                    parserState.ReIssue = True
                    return

            if isinstance(currentBlock, EndOfDocumentBlock):
                parserState.NewGroup = EndOfDocumentGroup(currentBlock)
                return

        raise BlockParserException(
            "Expected keywords: architecture, context, entity, library, package, use. Found '{block!s}'."
            .format(block=currentBlock.__class__.__qualname__), currentBlock)