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

JavaScript target can't use wildcards #1213

Closed
dabbler0 opened this issue Jun 16, 2016 · 5 comments
Closed

JavaScript target can't use wildcards #1213

dabbler0 opened this issue Jun 16, 2016 · 5 comments

Comments

@dabbler0
Copy link

dabbler0 commented Jun 16, 2016

The JavaScript target compiles . to matchWildcard() instead of this.matchWildcard(), which raises an error. Manually changing to this.matchWildcard() in the generated source seems to fix the problem.

@ericvergnaud
Copy link
Contributor

Hi,
can you provide a grammar sample to reproduce this?
Eric

@nodayoshikazu
Copy link

Hi,
I am experiencing the same issue. Attached is a grammar snippet to reproduce this. Thanks.
-Yoshi
m.txt

@parrt
Copy link
Member

parrt commented Nov 22, 2016

/*  makefile parser grammar   */

grammar m;


root:
       (command)+ EOF
;

command:
    BackSlash? ( ID | Id_or_dir )
  | BackTick ( (.)+? ) BackTick
;

NL:
    ( '\r' '\n'? | '\n' )
;

At: '@' ;
BackTick: '`' ;
Slash: '/' ;
BackSlash: '\\' ;
Vert: '|' ;
LeftAngle: '<' ;
RightAngle: '>' ;
OpenParen: '(' ;
CloseParen: ')' ;
OpenBrace: '{' ;
CloseBrace: '}' ;
DoubleQuote: '"' ;
SingleQuote: '\'' ;

Equal: '=' ;
BangEqual: '!=' ;
QuestionEqual: '?=' ;
ColonEqual: ':=' ;
ColcolEqual: '::=' ;
PlusEqual: '+=' ;

Tab: '\t' ;
AndAnd: '&&' ;
OrOr: '||' ;

Value:	Digit+ ;


StrLiteral:  SingleQuote Id_or_dir SingleQuote
            | DoubleQuote ~["]+ DoubleQuote
;

Id_or_dir: ID ( '/' ID? )*
	  | ( '../' | './' | '/' ) ID? 
;

ID: [a-zA-Z_.~*\[] ( [\-a-zA-Z_.~*\]] | [0-9] )*  ;

fragment
Digit:
	[0-9]
;
LineComment:
	Tab* '#' ~[\r\n]* NL -> skip
;
Whitespace
    :   [ ]+ -> skip
;

NotNewline: ( ~[\r\n] ) ;

@ChristophWedler
Copy link

As a workaround, you can use the following "action" before the use of the dot:

    { var matchWildcard = this.matchWildcard.bind(this); }

But a fix in the Javascript generator would be better, of course...

@nodayoshikazu
Copy link

Thanks for the tip. Since this is an old problem and I could not wait for the new antlr release with the fix, I did my work around (added "this.") and it is working fine so far.

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

No branches or pull requests

5 participants