ANTLR语法未按预期解析

时间:2018-10-27 20:50:22

标签: grammar antlr4 lexer

grammar HTML;
 @header{
    package com.test.html;
 }

tag  : tagName COLON attrs;

tagName:STRING;

attrs : attr (',' attr)*;

attr: attrName '=' attrValue;

attrName: STRING  ;

attrValue: ALPHANUMERIC (SP ALPHANUMERIC)* ;

COLON : ':';

STRING : CHAR (ALPHANUMERIC)*;

ALPHANUMERIC: (CHAR | DIGIT);

CHAR : [a-z_];

DIGIT : [0-9];

WS : [ \r\n]+ -> skip; // skip newlines

//SP :[ ] -> channel(HIDDEN);

Enter text to be parsed...**stid:type=text25,len=10,description=hello44 how are you doing today**
Before parser
line 1:9 token recognition error at: '=t'
line 1:5 mismatched input 'type' expecting RULE
line 1:16 token recognition error at: ','
line 1:20 token recognition error at: '=1'
line 1:23 token recognition error at: ','
line 1:35 token recognition error at: '=h'
line 1:43 token recognition error at: ' '
line 1:47 token recognition error at: ' '
line 1:51 token recognition error at: ' '
line 1:55 token recognition error at: ' '
line 1:61 token recognition error at: ' '
(validation stid : type ext 25 len 0 description ello 44 how are you doing today)

我希望以上语法能够解析以下文本。但它引发了一个错误,如上所示。

  

stid = stid:type = text25,len = 10,description = hello44您今天好吗

0 个答案:

没有答案