CommentParsing.py revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
## @file
# This file is used to define comment parsing interface
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
'''
CommentParsing
'''
##
# Import Modules
#
import re
## ParseHeaderCommentSection
#
# Parse Header comment section lines, extract Abstract, Description, Copyright
# , License lines
#
# @param CommentList: List of (Comment, LineNumber)
# @param FileName: FileName of the comment
#
Abstract = ''
Description = ''
Copyright = ''
License = ''
EndOfLine = "\n"
STR_HEADER_COMMENT_START = "@file"
#
# first find the last copyright line
#
Last = 0
if _IsCopyrightLine(Line):
break
for Item in CommentList:
#
# if there are blank lines between License or Description, keep them as they would be
# indication of different block; or in the position that Abstract should be, also keep it
# as it indicates that no abstract
#
continue
else:
else:
#
# in case there is no abstract and description
#
if not Comment:
Abstract = ''
elif _IsCopyrightLine(Comment):
else:
#
# in case there is no description
#
if _IsCopyrightLine(Comment):
else:
if _IsCopyrightLine(Comment):
else:
#
# Contents after copyright line are license, those non-copyright lines in between
# copyright line will be discarded
#
if License:
else:
continue
if not Copyright:
if not License:
## _IsCopyrightLine
# check whether current line is copyright line, the criteria is whether there is case insensitive keyword "Copyright"
# followed by zero or more white space characters followed by a "(" character
#
# @param LineContent: the line need to be checked
# @return: True if current line is copyright line, False else
#
def _IsCopyrightLine (LineContent):
return Result
## ParseGenericComment
#
# @param GenericComment: Generic comment list, element of
# (CommentLine, LineNum)
# @param ContainerFile: Input value for filename of Dec file
#
if ContainerFile:
pass
HelpTxt = None
HelpStr = ''
for Item in GenericComment:
if HelpStr:
HelpTxt = TextObject()
return HelpTxt
## ParseDecPcdGenericComment
#
# @param GenericComment: Generic comment list, element of (CommentLine,
# LineNum)
# @param ContainerFile: Input value for filename of Dec file
#
HelpStr = ''
PcdErr = None
if PcdErr:
PcdErr = PcdErrorObject()
if PcdErr:
PcdErr = PcdErrorObject()
if PcdErr:
PcdErr = PcdErrorObject()
else:
#
# remove the last EOL if the comment is of format 'FOO\n'
#
## ParseDecPcdTailComment
#
# @param TailCommentList: Tail comment list of Pcd, item of format (Comment, LineNum)
# @param ContainerFile: Input value for filename of Dec file
# @retVal SupModuleList: The supported module type list detected
# @retVal HelpStr: The generic help text string detected
#
#
# get first word and compare with SUP_MODULE_LIST
#
return None, Comment
#
# parse line, it must have supported module type specified
#
SupModuleList = []
if not Mod:
continue
elif Mod not in SUP_MODULE_LIST:
else:
return SupModuleList, HelpStr
## _CheckRangeExpression
#
# @param Expression: Pcd range expression
#
#
# check grammar for Pcd range expression is not required yet
#
if Expression:
pass
return True
## ValidateCopyright
#
#
#
if not Result:
## _ValidateCopyright
#
# @param Line: Line that contains copyright information, # stripped
#
# @retval Result: True if line is conformed to Spec format, False else
# @retval ErrMsg: the detailed error description
#
def _ValidateCopyright(Line):
if Line:
pass
ErrMsg = ''
def GenerateTokenList (Comment):
#
# Tokenize Comment using '#' and ' ' as token seperators
#
RelplacedComment = None
while Comment != RelplacedComment:
#
# Comment - Comment to parse
# TypeTokens - A dictionary of type token synonyms
# RemoveTokens - A list of tokens to remove from help text
# ParseVariable - True for parsing [Guids]. Otherwise False
#
#
# Initialize return values
#
Usage = None
Type = None
String = None
HelpText = None
NumTokens = 2
if ParseVariable:
#
# Remove white space around first instance of ':' from Comment if 'Variable'
# is in front of ':' and Variable is the 1st or 2nd token in Comment.
#
#
# Remove first instance of L"<VariableName> from Comment and put into String
# if and only if L"<VariableName>" is the 1st token, the 2nd token. Or
# L"<VariableName>" is the third token immediately following 'Variable:'.
#
End = -1
if Start >= 0:
else:
if Start >= 0:
if End >= 0:
Type = 'Variable'
NumTokens = 1
#
# Initialze HelpText to Comment.
# Content will be remove from HelpText as matching tokens are found
#
#
# Tokenize Comment using '#' and ' ' as token seperators
#
#
# Search first two tokens for Usage and Type and remove any matching tokens
# from HelpText
#
if Usage != None or not ParseVariable:
if Usage != None:
if Token in RemoveTokens:
#
# If no Usage token is present and set Usage to UNDEFINED
#
if Usage == None:
Usage = 'UNDEFINED'
#
# If no Type token is present and set Type to UNDEFINED
#
if Type == None:
Type = 'UNDEFINED'
#
# If Type is not 'Variable:', then set String to None
#
if Type != 'Variable':
String = None
#
# Strip ' ' and '#' from the beginning of HelpText
# If HelpText is an empty string after all parsing is
# complete then set HelpText to None
#
if HelpText == '':
HelpText = None
#
# Return parsing results
#