English 中文(简体)
利用定期表述从源代码中抽取职能和职能负责人
原标题:Using regular expressions to extract functions and function headers from source code
  • 时间:2010-07-12 10:39:29
  •  标签:
  • regex

我试图从一些来源代码文档中提取职能和职能负责人。 这里的例子有:

################################################################################
# test module
#
# Description : Test module
#
DATABASE test

###
# Global Vars
GLOBALS
    DEFINE G_test_string    STRING
END GLOBALS

###
# Modular Vars
DEFINE M_counter            INTEGER

###
# Constants
CONSTANT MAX_ARR_SIZE = 100

##################################
# Alternative header
##################################
FUNCTION test_function_1()
    DEFINE  F_x     INTEGER

    LET F_x = 1

    RETURN F_x
END FUNCTION

###################################
# Function:
#   This is a test function
#
# Parameters:
#   in - test
#
# Returns:
#   out - result
#
FUNCTION test_function_2( P_in_var )
    DEFINE  P_in_var    INTEGER

    DEFINE  F_out_var   INTEGER


    LET F_out_var = P_in_var

    RETURN F_out_var
END FUNCTION

FUNCTION test_init_array()
    DEFINE  F_array     ARRAY[ MAX_ARR_SIZE ] OF INTEGER
    DEFINE  F_element   INTEGER

    FOR F_element = 1 TO MAX_ARR_SIZE

        LET F_array[ F_element ] = F_element * F_element

    END FOR

END FUNCTION

职能可能或不可能比职能更重。 I m试图抓住职能来源、职能负责人、职能名称和小组中的任何参数。 这里的表述是(如果是这样的话)的。 Net网,并一直在使用Regex英雄进行检测:

^([#]{0,1}.*?)(FUNCTIONs+(.*?)[(](.*?)[)].*?END FUNCTION) 

看来,除了档案中的第一个功能(测试功能1)外,这似乎还涉及所有人。 最初的测试组——功能1)从第1行(来源档案的顶端)中捕获所有物品,直到联合国功能测试开始。 我认识到这一点,因为档案中还有其他评论的编号,但我只想抓住职能负责人。

最佳回答

If I see it correctly, you have problems identifying lines starting with #. To achieve this, you could turn on the RegexOptions.Multiline flag and match the function header with

((?:^#.*s)*)

Edit: For this to work, you d have to switch OFF RegexOptions.Singleline and replace .*? with [sS]*? in your function body part.

问题回答

暂无回答




相关问题
Uncommon regular expressions [closed]

Recently I discovered two amazing regular expression features: ?: and ?!. I was curious of other neat regex features. So maybe you would like to share some tricky regular expressions.

regex to trap img tag, both versions

I need to remove image tags from text, so both versions of the tag: <img src="" ... ></img> <img src="" ... />

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

Is it possible to negate a regular expression search?

I m building a lexical analysis engine in c#. For the most part it is done and works quite well. One of the features of my lexer is that it allows any user to input their own regular expressions. This ...

regex for four-digit numbers (or "default")

I need a regex for four-digit numbers separated by comma ("default" can also be a value). Examples: 6755 3452,8767,9865,8766,3454 7678,9876 1234,9867,6876,9865 default Note: "default" ...

热门标签