Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limits like DIGIT {min,max} in patterns #4627

Open
asfar-securiti opened this issue May 22, 2024 · 1 comment
Open

limits like DIGIT {min,max} in patterns #4627

asfar-securiti opened this issue May 22, 2024 · 1 comment

Comments

@asfar-securiti
Copy link

Is is possible to use syntax like regex like syntax to set limit for specific fragments or tokens? I have tried but it is giving me java compilation error:

address: STREET SPACES{1,3} POSTAL_CODE SPACES SPACES? SPACES? CITY SPACES{1,3} COUNTRY ;

` switch ( getInterpreter().adaptivePredict(_input,6,_ctx) ) {
case 1:
enterOuterAlt(_localctx, 1);
{
setState(10);
match(STREET);
setState(11);
match(SPACES);
1,3
setState(13);
match(POSTAL_CODE);
setState(14);
match(SPACES);
setState(16);
_errHandler.sync(this);
switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) {
case 1:
{
setState(15);
match(SPACES);
}
break;
}
setState(19);
_errHandler.sync(this);
_la = _input.LA(1);
if (_la==SPACES) {
{
setState(18);
match(SPACES);
}
}

			setState(21);
			match(CITY);
			setState(22);
			match(SPACES);
			1,3
			setState(24);
			match(COUNTRY);
			}
			break;
		case 2:
			enterOuterAlt(_localctx, 2);
			{
			setState(25);
			match(STREET);
			setState(26);
			match(SPACES);
			setState(28);
			_errHandler.sync(this);
			switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) {
			case 1:
				{
				setState(27);
				match(SPACES);
				}
				break;
			}
			setState(31);
			_errHandler.sync(this);
			_la = _input.LA(1);
			if (_la==SPACES) {
				{
				setState(30);
				match(SPACES);
				}
			}

			setState(33);
			match(POSTAL_CODE);
			setState(34);
			match(SPACES);
			setState(36);
			_errHandler.sync(this);
			switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) {
			case 1:
				{
				setState(35);
				match(SPACES);
				}
				break;
			}
			setState(39);
			_errHandler.sync(this);
			_la = _input.LA(1);
			if (_la==SPACES) {
				{
				setState(38);
				match(SPACES);
				}
			}

			setState(41);
			match(COUNTRY);
			}
			break;
		}

`

@KvanTTT
Copy link
Member

KvanTTT commented May 24, 2024

Hi! ANTLR doesn't support such a syntax. Instead, it treats {} as semantics predicates and just inserts incorrect code to the generated source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants