2
0
Эх сурвалжийг харах

More JS reserved words (Issue 45).

Vladislav Folts 11 жил өмнө
parent
commit
8f2434361e

+ 15 - 23
src/js/Lexer.js

@@ -1,21 +1,13 @@
 var RTL$ = require("rtl.js");
 var RTL$ = require("rtl.js");
+var Context = require("js/Context.js");
 var JS = GLOBAL;
 var JS = GLOBAL;
-var JsString = require("JsString.js");
-var Errors = require("Errors.js");
-var Stream = require("Stream.js");
+var JsString = require("js/JsString.js");
+var Errors = require("js/Errors.js");
+var Stream = require("js/Stream.js");
 var quote = "\"";
 var quote = "\"";
 var commentBegin = "(*";
 var commentBegin = "(*";
 var commentEnd = "*)";
 var commentEnd = "*)";
-var jsReservedWords = "break case catch continue debugger default delete do else finally for function if in instanceof new return switch this throw try typeof var void while with Math";
-var Context = RTL$.extend({
-	init: function Context(){
-		this.handleChar = null;
-		this.handleLiteral = null;
-		this.handleString = null;
-		this.handleIdent = null;
-		this.isLexem = null;
-	}
-});
+var jsReservedWords = "break case catch continue debugger default delete do else finally for function if in instanceof new return switch this throw try typeof var void while with false true null class enum export extends import super implements interface let package private protected public static yield Math";
 var Literal = RTL$.extend({
 var Literal = RTL$.extend({
 	init: function Literal(){
 	init: function Literal(){
 		this.s = RTL$.makeCharArray(1);
 		this.s = RTL$.makeCharArray(1);
@@ -30,7 +22,7 @@ function isLetter(c/*CHAR*/){
 	return c >= 97 && c <= 122 || c >= 65 && c <= 90;
 	return c >= 97 && c <= 122 || c >= 65 && c <= 90;
 }
 }
 
 
-function digit(stream/*Type*/, context/*Context*/){
+function digit(stream/*Type*/, context/*Type*/){
 	var result = false;
 	var result = false;
 	var c = 0;
 	var c = 0;
 	if (!Stream.eof(stream)){
 	if (!Stream.eof(stream)){
@@ -43,7 +35,7 @@ function digit(stream/*Type*/, context/*Context*/){
 	return result;
 	return result;
 }
 }
 
 
-function hexDigit(stream/*Type*/, context/*Context*/){
+function hexDigit(stream/*Type*/, context/*Type*/){
 	var result = false;
 	var result = false;
 	var c = 0;
 	var c = 0;
 	c = Stream.getChar(stream);
 	c = Stream.getChar(stream);
@@ -54,13 +46,13 @@ function hexDigit(stream/*Type*/, context/*Context*/){
 	return result;
 	return result;
 }
 }
 
 
-function handleLiteral(context/*Context*/, s/*ARRAY OF CHAR*/){
+function handleLiteral(context/*Type*/, s/*ARRAY OF CHAR*/){
 	var result = false;
 	var result = false;
 	var r = context.handleLiteral(JsString.make(s)); result = (r === undefined || r);
 	var r = context.handleLiteral(JsString.make(s)); result = (r === undefined || r);
 	return result;
 	return result;
 }
 }
 
 
-function point(stream/*Type*/, context/*Context*/){
+function point(stream/*Type*/, context/*Type*/){
 	var result = false;
 	var result = false;
 	if (!Stream.eof(stream) && Stream.getChar(stream) == 46 && (Stream.eof(stream) || Stream.peekChar(stream) != 46)){
 	if (!Stream.eof(stream) && Stream.getChar(stream) == 46 && (Stream.eof(stream) || Stream.peekChar(stream) != 46)){
 		result = handleLiteral(context, ".");
 		result = handleLiteral(context, ".");
@@ -68,7 +60,7 @@ function point(stream/*Type*/, context/*Context*/){
 	return result;
 	return result;
 }
 }
 
 
-function string(stream/*Type*/, context/*Context*/){
+function string(stream/*Type*/, context/*Type*/){
 	var result = false;
 	var result = false;
 	var c = 0;
 	var c = 0;
 	var s = null;
 	var s = null;
@@ -112,7 +104,7 @@ function isReservedWorld(s/*Type*/, words/*ARRAY OF CHAR*/){
 	return i == JsString.len(s);
 	return i == JsString.len(s);
 }
 }
 
 
-function ident(stream/*Type*/, context/*Context*/, reservedWords/*ARRAY OF CHAR*/){
+function ident(stream/*Type*/, context/*Type*/, reservedWords/*ARRAY OF CHAR*/){
 	var result = false;
 	var result = false;
 	var c = 0;
 	var c = 0;
 	var s = null;
 	var s = null;
@@ -144,7 +136,7 @@ function ident(stream/*Type*/, context/*Context*/, reservedWords/*ARRAY OF CHAR*
 	return result;
 	return result;
 }
 }
 
 
-function skipComment(stream/*Type*/, context/*Context*/){
+function skipComment(stream/*Type*/, context/*Type*/){
 	var result = false;
 	var result = false;
 	if (Stream.peekStr(stream, commentBegin)){
 	if (Stream.peekStr(stream, commentBegin)){
 		Stream.next(stream, commentBegin.length);
 		Stream.next(stream, commentBegin.length);
@@ -168,7 +160,7 @@ function readSpaces(c/*CHAR*/){
 	return c == 32 || c == 8 || c == 9 || c == 10 || c == 13;
 	return c == 32 || c == 8 || c == 9 || c == 10 || c == 13;
 }
 }
 
 
-function skipSpaces(stream/*Type*/, context/*Context*/){
+function skipSpaces(stream/*Type*/, context/*Type*/){
 	if (context.isLexem == null || !context.isLexem()){
 	if (context.isLexem == null || !context.isLexem()){
 		while (true){
 		while (true){
 			if (Stream.read(stream, readSpaces) && skipComment(stream, context)){
 			if (Stream.read(stream, readSpaces) && skipComment(stream, context)){
@@ -177,7 +169,7 @@ function skipSpaces(stream/*Type*/, context/*Context*/){
 	}
 	}
 }
 }
 
 
-function separator(stream/*Type*/, context/*Context*/){
+function separator(stream/*Type*/, context/*Type*/){
 	return Stream.eof(stream) || !isLetter(Stream.peekChar(stream));
 	return Stream.eof(stream) || !isLetter(Stream.peekChar(stream));
 }
 }
 
 
@@ -188,7 +180,7 @@ function makeLiteral(s/*ARRAY OF CHAR*/){
 	return result;
 	return result;
 }
 }
 
 
-function literal(l/*Literal*/, stream/*Type*/, context/*Context*/){
+function literal(l/*Literal*/, stream/*Type*/, context/*Type*/){
 	var result = false;
 	var result = false;
 	if (Stream.peekStr(stream, l.s)){
 	if (Stream.peekStr(stream, l.s)){
 		Stream.next(stream, l.s.length);
 		Stream.next(stream, l.s.length);

+ 3 - 1
src/ob/Lexer.ob

@@ -5,7 +5,9 @@ CONST
     quote = 22X; (* " *)
     quote = 22X; (* " *)
     commentBegin = "(*";
     commentBegin = "(*";
     commentEnd = "*)";
     commentEnd = "*)";
-    jsReservedWords = "break case catch continue debugger default delete do else finally for function if in instanceof new return switch this throw try typeof var void while with Math"; (* Math is used in generated code for some functions so it is reserved word from code generator standpoint *)
+
+    (* Math is used in generated code for some functions so it is reserved word from code generator standpoint *)
+    jsReservedWords = "break case catch continue debugger default delete do else finally for function if in instanceof new return switch this throw try typeof var void while with false true null class enum export extends import super implements interface let package private protected public static yield Math";
 
 
 TYPE
 TYPE
     Literal = POINTER TO RECORD
     Literal = POINTER TO RECORD

+ 1 - 1
test/expected/js_keyword.js

@@ -1,5 +1,5 @@
 var do$ = function (){
 var do$ = function (){
-var case$ = 0;
+var break$ = 0;var case$ = 0;var catch$ = 0;var continue$ = 0;var debugger$ = 0;var default$ = 0;var delete$ = 0;var else$ = 0;var class$ = 0;var enum$ = 0;var export$ = 0;var extends$ = 0;var import$ = 0;var super$ = 0;var true$ = 0;var false$ = 0;var null$ = 0;var implements$ = 0;var interface$ = 0;var let$ = 0;var package$ = 0;var private$ = 0;var protected$ = 0;var public$ = 0;var static$ = 0;var yield$ = 0;var finally$ = 0;var for$ = 0;var if$ = 0;var in$ = 0;var instanceof$ = 0;var new$ = 0;var return$ = 0;var switch$ = 0;var this$ = 0;var try$ = 0;var typeof$ = 0;var var$ = 0;var void$ = 0;var while$ = 0;var with$ = 0;var Math$ = 0;
 
 
 function function$(){
 function function$(){
 	var i = null;
 	var i = null;

+ 8 - 1
test/input/js_keyword.ob

@@ -1,6 +1,13 @@
 MODULE do;
 MODULE do;
 TYPE throw = PROCEDURE;
 TYPE throw = PROCEDURE;
-VAR case: INTEGER;
+VAR
+    break, case, catch, continue, debugger, default, delete, else,
+    class, enum, export, extends, import, super,
+    true, false, null,
+    implements, interface, let, package, private, protected, public, static, yield,
+    finally, for, if, in, instanceof, new, return, switch, this, 
+    try, typeof, var, void, while, with, Math
+    : INTEGER;
 PROCEDURE function();
 PROCEDURE function();
 VAR i: throw;
 VAR i: throw;
 BEGIN
 BEGIN