How to implement JavaScript/ECMAScript "no LineTerminator here" rule in JavaCC? -



How to implement JavaScript/ECMAScript "no LineTerminator here" rule in JavaCC? -

i go on working on javacc grammar ecmascript 5.1. goes quite well, think i've covered of expressions now.

i have 2 questions, both of them related automatic semicolon insertion (§7.9.1). 1 of them.

the specification defines next production:

postfixexpression : lefthandsideexpression lefthandsideexpression [no lineterminator here] ++ lefthandsideexpression [no lineterminator here] --

how can implement reliable "no lineterminator here" check?

for record line_terminator @ moment like:

special_token : { <line_terminator: <lf> | <cr> | <ls> | <ps> > | < #lf: "\n" > /* line feed */ | < #cr: "\r" > /* carriage homecoming */ | < #ls: "\u2028" > /* line separator */ | < #ps: "\u2029" > /* paragraph separator */ }

i have read lexical states, not sure if right direction. i've checked few other javascript grammars have found, did not find similar rules there. (i sense myself total cargo culter when seek overtake these grammars.)

i'd grateful pointer, hint or keyword right search direction.

i think "restricted productions" can this

void postfixexpression() : {} { lefthandsideexpression() ( lookahead( "++", {gettoken(0).beginline == gettoken(1).beginline}) "++" | lookahead( "--", {gettoken(0).beginline == gettoken(1).beginline}) "--" | {} ) }

javascript ecmascript-5 javacc

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -