Skip to content

Commit

Permalink
Use AllowDiv when doing REPL paren matching.
Browse files Browse the repository at this point in the history
Summary:
If we use `AllowRegExp` as the grammar context, then paren matching
breaks if we use `/` as division inside parens.

Always use `AllowDiv` instead. Note that this is not perfect,
because it doesn't work if there are unbalanced parens inside
an actual RegExp.

Reviewed By: tmikov

Differential Revision: D21434307

fbshipit-source-id: c3258bbe73d815349985f97629b54d9dc14e007f
  • Loading branch information
avp authored and facebook-github-bot committed May 7, 2020
1 parent d188b72 commit 6e1367c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test/repl/regress-div.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Remove this once the REPL can handle block comments.
// @lint-ignore-every LICENSELINT

// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.

// RUN: cat %s | %hermes -prompt="" -prompt2="" | %FileCheck --match-full-lines %s

(1 / 2);
// CHECK: 0.5
6 changes: 5 additions & 1 deletion tools/hermes/repl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ static bool needsAnotherLine(llvm::StringRef input) {
}
};

while (const parser::Token *token = lexer.advance()) {
// Use AllowDiv to not skip parens when using division.
// TODO: Find a way to use the correct GrammarContext and make this work
// for all REPL inputs.
while (const parser::Token *token =
lexer.advance(parser::JSLexer::GrammarContext::AllowDiv)) {
if (token->getKind() == parser::TokenKind::eof) {
break;
}
Expand Down

0 comments on commit 6e1367c

Please sign in to comment.