From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Lynch Newsgroups: gmane.lisp.guile.devel Subject: [PATCH 4/4] Fix some reserved word usages in ecmascript implementation Date: Wed, 28 Oct 2020 00:03:35 -0400 Message-ID: <20201028040330.22051-5-sean@seanplynch.com> References: <20201028040330.22051-1-sean@seanplynch.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3136"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Sean Lynch To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Wed Oct 28 15:27:35 2020 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kXmQI-0000hX-Ne for guile-devel@m.gmane-mx.org; Wed, 28 Oct 2020 15:27:34 +0100 Original-Received: from localhost ([::1]:51412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXmQH-00026L-KU for guile-devel@m.gmane-mx.org; Wed, 28 Oct 2020 10:27:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXciE-0006QB-QM for guile-devel@gnu.org; Wed, 28 Oct 2020 00:05:26 -0400 Original-Received: from mail-qk1-x72e.google.com ([2607:f8b0:4864:20::72e]:43695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kXciC-0002Sj-Rn for guile-devel@gnu.org; Wed, 28 Oct 2020 00:05:26 -0400 Original-Received: by mail-qk1-x72e.google.com with SMTP id q199so3419930qke.10 for ; Tue, 27 Oct 2020 21:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seanplynch-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K0o1m5HPzvdEOMKNCSCX8noOYFeb/SReJmx4DpIOCWc=; b=ObnpZGa1/Y33YBMyiLata63kPk9ab+E7iWB22TpQzo2blP/y5ujnjUfwEMHCNKNGN/ bXadMRx5PhmRYTL5RLHJZbFTk/Hp/S2Sd9Ol8eN4ieLIXPyR+ye3EYVo3UkUeSGYWzmU 9ngNzzwpFIeXAKeIArxz/azJaaWkE8Ndd0Ol26NIdxUn/iPCAUu7Af/7mLjR7Q3w7/q3 R+Q+Gwbol+0yjj5pG6BxAH8yRGDY7lxfwVO9XdC/I6mpsVYf9S47t0zozxcvpfKkBMDF cxZGqE0A2ZHaQGKvKwadT9zQrNSnFAo4L0r/EpjaMKliAaCG7NiXIrOToO/FhOKd/Q3d ibFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K0o1m5HPzvdEOMKNCSCX8noOYFeb/SReJmx4DpIOCWc=; b=Yga40Gey41vGorD4IB+Ai12yZ3xR6YhaVABlf6jqjzJeMJeCQqtJnUMoOkf9Z2rmoI oi2qSxxOUZNJp6Ok5QP67+CiBCrD8f/ok/0wh2Wfh1E9JtNKXux2Z7uKzraKz+6lelO3 Jjzx5/Gzeswbr06SttoG38BD6LqKXMto87ehhmD0Y6BZrFztLt/ATweE5ZbWB/wTLGdG G7HZsEYhcbXwzND6uQHu/8PN7OqeSkloXllVN0wjJ8NaXZ5kHAsF8Oz54tvHGZ1P0F5B CWQVPZSQw9fYd9z1xk5g/7crb0lW7qV8av8yghEFpd+SKsnveYzU5iVVxuVrfMp7rEca qFuw== X-Gm-Message-State: AOAM530Qb7JwG/Bb7Acl9xkifOF4E2zQTw1VuYMqLto+kPNTxNHQRgCL OcOS4wKggqbcMZDMvt5ZEdRnav65yYC6tCws X-Google-Smtp-Source: ABdhPJwMyAI+NdP7aMa9emSFU0G+6rfGXMZJdG33R1Bs0cGbeGOj6lqg47GESvx6f67bKOX6Y0BmSA== X-Received: by 2002:a37:8685:: with SMTP id i127mr5214537qkd.37.1603857923147; Tue, 27 Oct 2020 21:05:23 -0700 (PDT) Original-Received: from guix.stny.rr.com (cpe-74-69-187-15.stny.res.rr.com. [74.69.187.15]) by smtp.googlemail.com with ESMTPSA id 67sm2318916qkd.14.2020.10.27.21.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2020 21:05:22 -0700 (PDT) X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201028040330.22051-1-sean@seanplynch.com> Received-SPF: neutral client-ip=2607:f8b0:4864:20::72e; envelope-from=sean@seanplynch.com; helo=mail-qk1-x72e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 28 Oct 2020 10:27:17 -0400 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20601 Archived-At: Reserved words are valid ecmascript in certain contexts, referred to by the IdentifierName syntax rule. For example, while throw is a keyword, using throw as a property accessor such as foo.throw is valid. While this implementation isn't quite correct, it is an improvement. For an example of how this might be incorrect, it will reject the expression super.foo uncoditionally, however, that expression is valid inside a member function of a class. Further, the *keywords* alist is now updated to the that specified by ECMAScript 2020, and *future-reserved-words* is merged into *keywords* because in the end the only item that wouldn't be a keyword seems to be enum. * module/language/ecmascript/parse.scm: Add IdentifierName production that includes reserved word list. * module/language/ecmascript/tokenize.scm: Update reserved word list and do not error upon encountering one. The parser will be responsible for rejecting an illegal usage of a reserved word. --- module/language/ecmascript/parse.scm | 51 +++++++++++++-- module/language/ecmascript/tokenize.scm | 84 +++++++++---------------- 2 files changed, 73 insertions(+), 62 deletions(-) diff --git a/module/language/ecmascript/parse.scm b/module/language/ecmascript/parse.scm index be41e4b9c..8fff96f54 100644 --- a/module/language/ecmascript/parse.scm +++ b/module/language/ecmascript/parse.scm @@ -55,9 +55,9 @@ > <= >= == != === !== + - * % ++ -- << >> >>> & bor ^ ! ~ && or ? colon = += -= *= %= <<= >>= >>>= &= bor= ^= / /= - break else new var case finally return void catch for switch while - continue function this with default if throw delete in try do - instanceof typeof null true false + await break case catch class const continue debugger default delete do else + enum export extends false finally for function if import in instanceof new + null return super switch this throw true try typeof var void while with yield Identifier StringLiteral NumericLiteral RegexpLiteral) @@ -65,6 +65,45 @@ (Program (SourceElements) : $1 (*eoi*) : *eof-object*) + (IdentifierName (Identifier) : $1 + (await) : $1 + (break) : $1 + (case) : $1 + (catch) : $1 + (class) : $1 + (const) : $1 + (continue) : $1 + (debugger) : $1 + (default) : $1 + (delete) : $1 + (do) : $1 + (else) : $1 + (enum) : $1 + (export) : $1 + (extends) : $1 + (false) : $1 + (finally) : $1 + (for) : $1 + (function) : $1 + (if) : $1 + (import) : $1 + (in) : $1 + (instanceof) : $1 + (new) : $1 + (null) : $1 + (return) : $1 + (super) : $1 + (switch) : $1 + (this) : $1 + (throw) : $1 + (true) : $1 + (try) : $1 + (typeof) : $1 + (var) : $1 + (void) : $1 + (while) : $1 + (with) : $1 + (yield) : $1) ;; ;; Verily, here we define statements. Expressions are defined ;; afterwards. @@ -218,14 +257,14 @@ (lbrace PropertyNameAndValueList rbrace) : `(object ,@$2)) (PropertyNameAndValueList (PropertyName colon AssignmentExpression) : `((,$1 ,$3)) (PropertyNameAndValueList comma PropertyName colon AssignmentExpression) : `(,@$1 (,$3 ,$5))) - (PropertyName (Identifier) : $1 + (PropertyName (IdentifierName) : $1 (StringLiteral) : (string->symbol $1) (NumericLiteral) : $1) (MemberExpression (PrimaryExpression) : $1 (FunctionExpression) : $1 (MemberExpression lbracket Expression rbracket) : `(aref ,$1 ,$3) - (MemberExpression dot Identifier) : `(pref ,$1 ,$3) + (MemberExpression dot IdentifierName) : `(pref ,$1 ,$3) (new MemberExpression Arguments) : `(new ,$2 ,$3)) (NewExpression (MemberExpression) : $1 @@ -234,7 +273,7 @@ (CallExpression (MemberExpression Arguments) : `(call ,$1 ,$2) (CallExpression Arguments) : `(call ,$1 ,$2) (CallExpression lbracket Expression rbracket) : `(aref ,$1 ,$3) - (CallExpression dot Identifier) : `(pref ,$1 ,$3)) + (CallExpression dot IdentifierName) : `(pref ,$1 ,$3)) (Arguments (lparen rparen) : '() (lparen ArgumentList rparen) : $2) (ArgumentList (AssignmentExpression) : `(,$1) diff --git a/module/language/ecmascript/tokenize.scm b/module/language/ecmascript/tokenize.scm index 8289b950c..cbae3bbe4 100644 --- a/module/language/ecmascript/tokenize.scm +++ b/module/language/ecmascript/tokenize.scm @@ -173,69 +173,44 @@ loc str)))))))) (define *keywords* - '(("break" . break) - ("else" . else) - ("new" . new) - ("var" . var) + '(("await" . await) + ("break" . break) ("case" . case) - ("finally" . finally) - ("return" . return) - ("void" . void) ("catch" . catch) - ("for" . for) - ("switch" . switch) - ("while" . while) + ("class" . class) + ("const" . const) ("continue" . continue) - ("function" . function) - ("this" . this) - ("with" . with) + ("debugger" . debugger) ("default" . default) - ("if" . if) - ("throw" . throw) ("delete" . delete) - ("in" . in) - ("try" . try) ("do" . do) - ("instanceof" . instanceof) - ("typeof" . typeof) - - ;; these aren't exactly keywords, but hey - ("null" . null) - ("true" . true) - ("false" . false))) - -(define *future-reserved-words* - '(("abstract" . abstract) + ("else" . else) ("enum" . enum) - ("int" . int) - ("short" . short) - ("boolean" . boolean) ("export" . export) - ("interface" . interface) - ("static" . static) - ("byte" . byte) ("extends" . extends) - ("long" . long) - ("super" . super) - ("char" . char) - ("final" . final) - ("native" . native) - ("synchronized" . synchronized) - ("class" . class) - ("float" . float) - ("package" . package) - ("throws" . throws) - ("const" . const) - ("goto" . goto) - ("private" . private) - ("transient" . transient) - ("debugger" . debugger) - ("implements" . implements) - ("protected" . protected) - ("volatile" . volatile) - ("double" . double) + ("false" . false) + ("finally" . finally) + ("for" . for) + ("function" . function) + ("if" . if) ("import" . import) - ("public" . public))) + ("in" . in) + ("instanceof" . instanceof) + ("new" . new) + ("null" . null) + ("return" . return) + ("super" . super) + ("switch" . switch) + ("this" . this) + ("throw" . throw) + ("true" . true) + ("try" . try) + ("typeof" . typeof) + ("var" . var) + ("void" . void) + ("while" . while) + ("with" . with) + ("yield" . yield))) (define (read-identifier port loc) (let lp ((c (peek-char port)) (chars '())) @@ -247,9 +222,6 @@ (let ((word (list->string (reverse chars)))) (cond ((assoc-ref *keywords* word) => (lambda (x) (make-lexical-token x loc #f))) - ((assoc-ref *future-reserved-words* word) - (syntax-error "word is reserved for the future, dude." - loc word)) (else (make-lexical-token 'Identifier loc (string->symbol word))))) (begin (read-char port) -- 2.29.1