zaach / jison

Bison in JavaScript.
http://jison.org
4.35k stars 448 forks source link

Use URLs as terms #357

Open juniorjp opened 7 years ago

juniorjp commented 7 years ago

I'm trying to define the following regex as a term:

/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/   return 'TERM'

But it's not working. Any way to accomplish this?

GerHobbelt commented 7 years ago

This is an error report from bleeding edge GerHobbelt/jison, which gives a hint what's wrong:

JisonLexerError: Lexical error on line 7: unsupported lexer input: ":" while lexing rules
       (i.e. jison lex regexes).

       NOTE: When you want the input ":" to be interpreted as a literal part
       of a lex rule regex, you MUST enclose it in double or single quotes,
       e.g. as shown in this error message just before. If not, then know
       that this is not accepted as a regex operator here in
       jison-lex rules.

       Offending input:
    ...tp|https)[:]\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!...
    -----------------------^ 

Note that the first 'literal' : has already been "patched" in a different way suitable for any regex. 😉