Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 解析器捕获所有参数列表_C#_Sql_Antlr4 - Fatal编程技术网

C# 解析器捕获所有参数列表

C# 解析器捕获所有参数列表,c#,sql,antlr4,C#,Sql,Antlr4,好的,我已经浪费了两天的时间,并且查看了与堆栈上的ANTLR4有关的所有其他答案,但我无法解决这个问题 我正在分析如下所示的SQL表定义: CREATE TABLE [dbo].[GeographicZones]( [GeographicZoneID] [int] IDENTITY(1,1) NOT NULL, [Township] [smallint] NOT NULL, [Range] [smallint] NOT NULL, [Section] [tinyi

好的,我已经浪费了两天的时间,并且查看了与堆栈上的ANTLR4有关的所有其他答案,但我无法解决这个问题

我正在分析如下所示的SQL表定义:

CREATE TABLE [dbo].[GeographicZones](
    [GeographicZoneID] [int] IDENTITY(1,1) NOT NULL,
    [Township] [smallint] NOT NULL,
    [Range] [smallint] NOT NULL,
    [Section] [tinyint] NOT NULL,
    [TownshipRange]  AS ((((('T'+CONVERT([varchar](3),[Township],0))+case when [Township]>(0) then 'N' else 'S' end)+'R')+CONVERT([varchar](3),[Range],0))+case when [Range]>(0) then 'E' else 'W' end),
    [LAOZone] [bit] NOT NULL,
    [MSDZone] [bit] NOT NULL,
    [ParrottZone] [bit] NOT NULL,
 CONSTRAINT [PK_GeographicZones] PRIMARY KEY CLUSTERED 
(
    [GeographicZoneID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [UK_GeographicZones_TRS] UNIQUE NONCLUSTERED 
(
    [Township] ASC,
    [Range] ASC,
    [Section] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
我无法解析的关键点是
TownshipRange
computed列。我不关心
AS
语句之后
()
之间的内容,我想忽略逗号分隔符

以下是
computedColumn
规则:

/**
TSql only. In code generation, this is mapped as a read-only
property. In translation, special comments are placed that
indicate that this should be a computed column.
*/
computedColumn
    : columnName AS anyExpr ( PERSISTED ( NOT NULL )? )?
    {
    logInfo( "Computed column {0}",
        $columnName.ctx.GetText() );
    }
    ;
以下是用于ANTLR4.0.1的
anyExpr
规则:

/**
Use for a parameter list (blah blah) where we don't care
about the contents. Uses a sempred to go until $open == 0.
Note that the right paren is missing from the end of the rule -
this is by design.
*/
anyExpr
locals [int open = 1]
    : Lp
    ( {$open > 0}? 
        ( ~( Lp | Rp )
        | Lp { $open++; }
        | Rp { $open--; }
        )
    )*
    ;
以下是使用ANTLR4 4.3.0记录的输出:

INFO    Computed column [TownshipRange]
line 579:22 extraneous input '(' expecting {Comma, Rp}
它失败的
是第一个嵌套的左paren。但是,无论开始paren后的第一个字符是什么,它都会立即失败并发出相同的警告

我的“一网打尽”的逻辑出了什么问题,在4.0.1和4.3之间发生了什么变化,打破了这一点

作为旁注(可能与问题有关),4.3在LL模式下解析整个SQL文件需要很长时间,因此我使用SLL。4.0.1在LL和SLL中都识别规则,解析时间几乎没有差异


4.0.1是否可能只是忽略了无关的输入,而我的
anyExpr
一直被破坏?

为什么不引用anyExpr本身呢

anyExpr
 : Lp ( ~( Lp | Rp ) | anyExpr )* Rp 
 ;
这可能会导致更快的解析(我自己没有尝试过!)


为什么不直接引用anyExpr呢?
anyExpr:Lp(~(Lp | Rp)| anyExpr)*Rp;
巴特勋爵,这可能刚刚奏效。我会让你知道的。一旦我这样做了,你能把答案贴出来吗?我倾向于把事情复杂化。巴特,你就是那个人。大约一秒钟内用SLL或LLExact完成100000行C#代码!!我已经吸取了教训-先去堆栈!:):)酷,然后我把它作为答案写下来。再次感谢。如此简单,如此优雅。
anyExpr
 : Lp ( ~( Lp | Rp )+ | anyExpr )* Rp 
 ;