How can I Ignore certain text in ANTLR4?










0















first of all, thank you in advance for your answer, this problem is killing me



  1. My first question is how can ignore certain text?
    I wanna ignore certain text from my document, I have the next text:

Text



And I wanna ignore the text enclosed by the rectangle...when the lexer find the "demandante" word it will stop to ignore...



I used this grammar



grammar A;

documento:((acciondemandante acciondemandado) | (acciondemandado acciondemandante));
acciondemandante: PALABRASDEMANDA informacionentidad+;
acciondemandado: PALABRASDEMANDADO informacionentidad+;
informacionentidad: nombres distancia? identificacion;
nombres: nombrenormal|nombremayuscula;
nombrenormal: WORDCAPITALIZE WORDCAPITALIZE+;
nombremayuscula: WORDUPPER WORDUPPER+;
distancia: WORDLOWER;
identificacion: tipo indicador? INT+;
tipo: cedula | NIT;
cedula: CEDULA | LCASE_LETTER LCASE_LETTER | UCASE_LETTER UCASE_LETTER;
indicador: WORDCAPITALIZE | WORDLOWER;

CEDULA: 'cedula' | 'cc' | 'CC';
NIT: 'NIT' | 'nit';
PALABRASDEMANDADO: 'demandados' | 'demandado';
PALABRASDEMANDA: 'demandante' | 'demandantes';
WORDUPPER: UCASE_LETTER UCASE_LETTER+;
WORDLOWER: LCASE_LETTER LCASE_LETTER+;
WORDCAPITALIZE: UCASE_LETTER LCASE_LETTER+;
LCASE_LETTER: 'a'..'z' | 'ñ' | 'á' | 'é' | 'í' | 'ó' | 'ú';
UCASE_LETTER: 'A'..'Z' | 'Ñ' | 'Á' | 'É' | 'Í' | 'Ó' | 'Ú';
INT: DIGIT+;
DIGIT: '0'..'9';
SPECIAL_CHAR: '.' -> skip;
WS : [ trn]+ -> skip;
//ANY: ~[ ]+;


I have tried a trick skipping the whitespaces WS : [ trn]+ -> skip; and then ignoring what is not whitespaces ANY: ~[ ]+; But it does not work because the lexer never recognize the ANY token...



What I would like my grammar to read



bullshit bullshit demandado Julian Solarte c.c 120109321 bullshit bullshit



  1. My second problem is that I get the "mismatched input ''" problem, and in order to resolve this problem I add this rule "SKIPEND: EOF ->skip;" but it does not works...

Thank you thank you so much.










share|improve this question






















  • Why Antlr and not plain regex?

    – Perdi Estaquel
    Nov 15 '18 at 5:30











  • What do you mean?

    – Julian Solarte
    Nov 15 '18 at 16:15











  • What do I mean? It would seem a lot simpler to match with the following (not tested): Pattern.compile("^(Demandante:.*?)Demandados", MULTILINE | DOTALL); and use the captured text.

    – Perdi Estaquel
    Nov 15 '18 at 22:45
















0















first of all, thank you in advance for your answer, this problem is killing me



  1. My first question is how can ignore certain text?
    I wanna ignore certain text from my document, I have the next text:

Text



And I wanna ignore the text enclosed by the rectangle...when the lexer find the "demandante" word it will stop to ignore...



I used this grammar



grammar A;

documento:((acciondemandante acciondemandado) | (acciondemandado acciondemandante));
acciondemandante: PALABRASDEMANDA informacionentidad+;
acciondemandado: PALABRASDEMANDADO informacionentidad+;
informacionentidad: nombres distancia? identificacion;
nombres: nombrenormal|nombremayuscula;
nombrenormal: WORDCAPITALIZE WORDCAPITALIZE+;
nombremayuscula: WORDUPPER WORDUPPER+;
distancia: WORDLOWER;
identificacion: tipo indicador? INT+;
tipo: cedula | NIT;
cedula: CEDULA | LCASE_LETTER LCASE_LETTER | UCASE_LETTER UCASE_LETTER;
indicador: WORDCAPITALIZE | WORDLOWER;

CEDULA: 'cedula' | 'cc' | 'CC';
NIT: 'NIT' | 'nit';
PALABRASDEMANDADO: 'demandados' | 'demandado';
PALABRASDEMANDA: 'demandante' | 'demandantes';
WORDUPPER: UCASE_LETTER UCASE_LETTER+;
WORDLOWER: LCASE_LETTER LCASE_LETTER+;
WORDCAPITALIZE: UCASE_LETTER LCASE_LETTER+;
LCASE_LETTER: 'a'..'z' | 'ñ' | 'á' | 'é' | 'í' | 'ó' | 'ú';
UCASE_LETTER: 'A'..'Z' | 'Ñ' | 'Á' | 'É' | 'Í' | 'Ó' | 'Ú';
INT: DIGIT+;
DIGIT: '0'..'9';
SPECIAL_CHAR: '.' -> skip;
WS : [ trn]+ -> skip;
//ANY: ~[ ]+;


I have tried a trick skipping the whitespaces WS : [ trn]+ -> skip; and then ignoring what is not whitespaces ANY: ~[ ]+; But it does not work because the lexer never recognize the ANY token...



What I would like my grammar to read



bullshit bullshit demandado Julian Solarte c.c 120109321 bullshit bullshit



  1. My second problem is that I get the "mismatched input ''" problem, and in order to resolve this problem I add this rule "SKIPEND: EOF ->skip;" but it does not works...

Thank you thank you so much.










share|improve this question






















  • Why Antlr and not plain regex?

    – Perdi Estaquel
    Nov 15 '18 at 5:30











  • What do you mean?

    – Julian Solarte
    Nov 15 '18 at 16:15











  • What do I mean? It would seem a lot simpler to match with the following (not tested): Pattern.compile("^(Demandante:.*?)Demandados", MULTILINE | DOTALL); and use the captured text.

    – Perdi Estaquel
    Nov 15 '18 at 22:45














0












0








0


2






first of all, thank you in advance for your answer, this problem is killing me



  1. My first question is how can ignore certain text?
    I wanna ignore certain text from my document, I have the next text:

Text



And I wanna ignore the text enclosed by the rectangle...when the lexer find the "demandante" word it will stop to ignore...



I used this grammar



grammar A;

documento:((acciondemandante acciondemandado) | (acciondemandado acciondemandante));
acciondemandante: PALABRASDEMANDA informacionentidad+;
acciondemandado: PALABRASDEMANDADO informacionentidad+;
informacionentidad: nombres distancia? identificacion;
nombres: nombrenormal|nombremayuscula;
nombrenormal: WORDCAPITALIZE WORDCAPITALIZE+;
nombremayuscula: WORDUPPER WORDUPPER+;
distancia: WORDLOWER;
identificacion: tipo indicador? INT+;
tipo: cedula | NIT;
cedula: CEDULA | LCASE_LETTER LCASE_LETTER | UCASE_LETTER UCASE_LETTER;
indicador: WORDCAPITALIZE | WORDLOWER;

CEDULA: 'cedula' | 'cc' | 'CC';
NIT: 'NIT' | 'nit';
PALABRASDEMANDADO: 'demandados' | 'demandado';
PALABRASDEMANDA: 'demandante' | 'demandantes';
WORDUPPER: UCASE_LETTER UCASE_LETTER+;
WORDLOWER: LCASE_LETTER LCASE_LETTER+;
WORDCAPITALIZE: UCASE_LETTER LCASE_LETTER+;
LCASE_LETTER: 'a'..'z' | 'ñ' | 'á' | 'é' | 'í' | 'ó' | 'ú';
UCASE_LETTER: 'A'..'Z' | 'Ñ' | 'Á' | 'É' | 'Í' | 'Ó' | 'Ú';
INT: DIGIT+;
DIGIT: '0'..'9';
SPECIAL_CHAR: '.' -> skip;
WS : [ trn]+ -> skip;
//ANY: ~[ ]+;


I have tried a trick skipping the whitespaces WS : [ trn]+ -> skip; and then ignoring what is not whitespaces ANY: ~[ ]+; But it does not work because the lexer never recognize the ANY token...



What I would like my grammar to read



bullshit bullshit demandado Julian Solarte c.c 120109321 bullshit bullshit



  1. My second problem is that I get the "mismatched input ''" problem, and in order to resolve this problem I add this rule "SKIPEND: EOF ->skip;" but it does not works...

Thank you thank you so much.










share|improve this question














first of all, thank you in advance for your answer, this problem is killing me



  1. My first question is how can ignore certain text?
    I wanna ignore certain text from my document, I have the next text:

Text



And I wanna ignore the text enclosed by the rectangle...when the lexer find the "demandante" word it will stop to ignore...



I used this grammar



grammar A;

documento:((acciondemandante acciondemandado) | (acciondemandado acciondemandante));
acciondemandante: PALABRASDEMANDA informacionentidad+;
acciondemandado: PALABRASDEMANDADO informacionentidad+;
informacionentidad: nombres distancia? identificacion;
nombres: nombrenormal|nombremayuscula;
nombrenormal: WORDCAPITALIZE WORDCAPITALIZE+;
nombremayuscula: WORDUPPER WORDUPPER+;
distancia: WORDLOWER;
identificacion: tipo indicador? INT+;
tipo: cedula | NIT;
cedula: CEDULA | LCASE_LETTER LCASE_LETTER | UCASE_LETTER UCASE_LETTER;
indicador: WORDCAPITALIZE | WORDLOWER;

CEDULA: 'cedula' | 'cc' | 'CC';
NIT: 'NIT' | 'nit';
PALABRASDEMANDADO: 'demandados' | 'demandado';
PALABRASDEMANDA: 'demandante' | 'demandantes';
WORDUPPER: UCASE_LETTER UCASE_LETTER+;
WORDLOWER: LCASE_LETTER LCASE_LETTER+;
WORDCAPITALIZE: UCASE_LETTER LCASE_LETTER+;
LCASE_LETTER: 'a'..'z' | 'ñ' | 'á' | 'é' | 'í' | 'ó' | 'ú';
UCASE_LETTER: 'A'..'Z' | 'Ñ' | 'Á' | 'É' | 'Í' | 'Ó' | 'Ú';
INT: DIGIT+;
DIGIT: '0'..'9';
SPECIAL_CHAR: '.' -> skip;
WS : [ trn]+ -> skip;
//ANY: ~[ ]+;


I have tried a trick skipping the whitespaces WS : [ trn]+ -> skip; and then ignoring what is not whitespaces ANY: ~[ ]+; But it does not work because the lexer never recognize the ANY token...



What I would like my grammar to read



bullshit bullshit demandado Julian Solarte c.c 120109321 bullshit bullshit



  1. My second problem is that I get the "mismatched input ''" problem, and in order to resolve this problem I add this rule "SKIPEND: EOF ->skip;" but it does not works...

Thank you thank you so much.







java antlr antlr4






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 3:18









Julian SolarteJulian Solarte

10110




10110












  • Why Antlr and not plain regex?

    – Perdi Estaquel
    Nov 15 '18 at 5:30











  • What do you mean?

    – Julian Solarte
    Nov 15 '18 at 16:15











  • What do I mean? It would seem a lot simpler to match with the following (not tested): Pattern.compile("^(Demandante:.*?)Demandados", MULTILINE | DOTALL); and use the captured text.

    – Perdi Estaquel
    Nov 15 '18 at 22:45


















  • Why Antlr and not plain regex?

    – Perdi Estaquel
    Nov 15 '18 at 5:30











  • What do you mean?

    – Julian Solarte
    Nov 15 '18 at 16:15











  • What do I mean? It would seem a lot simpler to match with the following (not tested): Pattern.compile("^(Demandante:.*?)Demandados", MULTILINE | DOTALL); and use the captured text.

    – Perdi Estaquel
    Nov 15 '18 at 22:45

















Why Antlr and not plain regex?

– Perdi Estaquel
Nov 15 '18 at 5:30





Why Antlr and not plain regex?

– Perdi Estaquel
Nov 15 '18 at 5:30













What do you mean?

– Julian Solarte
Nov 15 '18 at 16:15





What do you mean?

– Julian Solarte
Nov 15 '18 at 16:15













What do I mean? It would seem a lot simpler to match with the following (not tested): Pattern.compile("^(Demandante:.*?)Demandados", MULTILINE | DOTALL); and use the captured text.

– Perdi Estaquel
Nov 15 '18 at 22:45






What do I mean? It would seem a lot simpler to match with the following (not tested): Pattern.compile("^(Demandante:.*?)Demandados", MULTILINE | DOTALL); and use the captured text.

– Perdi Estaquel
Nov 15 '18 at 22:45













1 Answer
1






active

oldest

votes


















1














My approach to this problem would be 2 steps:



  1. Find the keyword in the input stream (here demandado).

  2. Let a parser parse from this position without forcing an EOF for the input in the grammar. It will go as far as possible ignoring everything it doesn't understand after what was understood.

This will make your grammar much simpler and you will get a parse tree only for the relevant input.






share|improve this answer























  • What about EOF? Why I skip it and it does not works?

    – Julian Solarte
    Nov 15 '18 at 20:32











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311902%2fhow-can-i-ignore-certain-text-in-antlr4%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














My approach to this problem would be 2 steps:



  1. Find the keyword in the input stream (here demandado).

  2. Let a parser parse from this position without forcing an EOF for the input in the grammar. It will go as far as possible ignoring everything it doesn't understand after what was understood.

This will make your grammar much simpler and you will get a parse tree only for the relevant input.






share|improve this answer























  • What about EOF? Why I skip it and it does not works?

    – Julian Solarte
    Nov 15 '18 at 20:32















1














My approach to this problem would be 2 steps:



  1. Find the keyword in the input stream (here demandado).

  2. Let a parser parse from this position without forcing an EOF for the input in the grammar. It will go as far as possible ignoring everything it doesn't understand after what was understood.

This will make your grammar much simpler and you will get a parse tree only for the relevant input.






share|improve this answer























  • What about EOF? Why I skip it and it does not works?

    – Julian Solarte
    Nov 15 '18 at 20:32













1












1








1







My approach to this problem would be 2 steps:



  1. Find the keyword in the input stream (here demandado).

  2. Let a parser parse from this position without forcing an EOF for the input in the grammar. It will go as far as possible ignoring everything it doesn't understand after what was understood.

This will make your grammar much simpler and you will get a parse tree only for the relevant input.






share|improve this answer













My approach to this problem would be 2 steps:



  1. Find the keyword in the input stream (here demandado).

  2. Let a parser parse from this position without forcing an EOF for the input in the grammar. It will go as far as possible ignoring everything it doesn't understand after what was understood.

This will make your grammar much simpler and you will get a parse tree only for the relevant input.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 7:59









Mike LischkeMike Lischke

21.8k354106




21.8k354106












  • What about EOF? Why I skip it and it does not works?

    – Julian Solarte
    Nov 15 '18 at 20:32

















  • What about EOF? Why I skip it and it does not works?

    – Julian Solarte
    Nov 15 '18 at 20:32
















What about EOF? Why I skip it and it does not works?

– Julian Solarte
Nov 15 '18 at 20:32





What about EOF? Why I skip it and it does not works?

– Julian Solarte
Nov 15 '18 at 20:32



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53311902%2fhow-can-i-ignore-certain-text-in-antlr4%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20