Skip to content

Commit 0694805

Browse files
author
Donald Steinert
committed
Merge pull request #270 from shift-js/feat/lexer
renames lexerFunctions lexerHelpers
2 parents 1d7d669 + 00b7d99 commit 0694805

File tree

7 files changed

+54
-54
lines changed

7 files changed

+54
-54
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ npm install
5656

5757
- Lexer: Generates a stream of tokens representing the lexical parts of the Swift input. The lexer uses a state object to store the token stream and other relevant information related to the Swift input. It is organized into three main files:
5858
- ```lexer.js``` iterates over the Swift code, separating it into individual parts to be evaluated based on their precedence in Swift.
59-
- ```lexerFunctions.js``` contains helper functions to handle particular lexical parts of Swift.
59+
- ```lexerHelpers.js``` contains helper functions to handle particular lexical parts of Swift.
6060
- ```lexicalTypes.js``` organizes and lists the valid lexical tokens of Swift, such as keywords, operators, and punctuation.
6161

6262
- Parser: Generates an Abstract Syntax Tree from the tokens created by the lexer. The parser takes the token objects and builds a tree that represents the relationships of the different parts of the code, that is then turned into JavaScript using Escodegen.

tests/lexerTests/lexerTestsFirstMilestone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var lexicalTypes = require('../../transpiler/lexer/lexicalTypes');
2-
var lexerFunctions = require('../../transpiler/lexer/lexerFunctions');
2+
var lexerHelpers = require('../../transpiler/lexer/lexerHelpers');
33
var lexer = require('../../transpiler/lexer/lexer');
44
var expect = require('chai').expect;
55

tests/lexerTests/lexerTestsFourthMilestone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var lexicalTypes = require('../../transpiler/lexer/lexicalTypes');
2-
var lexerFunctions = require('../../transpiler/lexer/lexerFunctions');
2+
var lexerHelpers = require('../../transpiler/lexer/lexerHelpers');
33
var lexer = require('../../transpiler/lexer/lexer');
44
var expect = require('chai').expect;
55

tests/lexerTests/lexerTestsSecondMilestone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var lexicalTypes = require('../../transpiler/lexer/lexicalTypes');
2-
var lexerFunctions = require('../../transpiler/lexer/lexerFunctions');
2+
var lexerHelpers = require('../../transpiler/lexer/lexerHelpers');
33
var lexer = require('../../transpiler/lexer/lexer');
44
var expect = require('chai').expect;
55

tests/lexerTests/lexerTestsThirdMilestone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var lexicalTypes = require('../../transpiler/lexer/lexicalTypes');
2-
var lexerFunctions = require('../../transpiler/lexer/lexerFunctions');
2+
var lexerHelpers = require('../../transpiler/lexer/lexerHelpers');
33
var lexer = require('../../transpiler/lexer/lexer');
44
var expect = require('chai').expect;
55

transpiler/lexer/lexer.js

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var lexerFunctions = require("./lexerFunctions");
1+
var lexerHelpers = require("./lexerHelpers");
22

33
module.exports = function(code) {
44

@@ -60,23 +60,23 @@ module.exports = function(code) {
6060
STATE.lastFunction = STATE.insideFunction[STATE.insideFunction.length - 1];
6161

6262
// handles new lines
63-
if (lexerFunctions.handleNewLine(STATE)) {
63+
if (lexerHelpers.handleNewLine(STATE)) {
6464
continue
6565
}
6666

6767
// handles comments
68-
if (lexerFunctions.checkForCommentStart(STATE)) {
68+
if (lexerHelpers.checkForCommentStart(STATE)) {
6969
continue;
7070
}
71-
if (lexerFunctions.handleComment(STATE)) {
71+
if (lexerHelpers.handleComment(STATE)) {
7272
continue;
7373
}
74-
if (lexerFunctions.checkIfInsideComment(STATE)) {
74+
if (lexerHelpers.checkIfInsideComment(STATE)) {
7575
continue;
7676
}
7777

7878
// ignores chunks that are solely whitespace
79-
if (lexerFunctions.checkForWhitespace(STATE.chunk)) {
79+
if (lexerHelpers.checkForWhitespace(STATE.chunk)) {
8080
STATE.advanceAndClear(1);
8181
continue;
8282
}
@@ -89,36 +89,36 @@ module.exports = function(code) {
8989
}
9090

9191
// handles numbers
92-
if (lexerFunctions.handleNumber(STATE) === true) {
92+
if (lexerHelpers.handleNumber(STATE) === true) {
9393
STATE.advanceAndClear(1);
9494
continue;
95-
} else if (lexerFunctions.handleNumber(STATE) === "skip"){
96-
lexerFunctions.handleEndOfFile(STATE.nextCol, STATE.tokens);
95+
} else if (lexerHelpers.handleNumber(STATE) === "skip"){
96+
lexerHelpers.handleEndOfFile(STATE.nextCol, STATE.tokens);
9797
STATE.advance(2);
9898
continue;
9999
}
100100

101101
// handles ranges
102-
if (lexerFunctions.handleRange(STATE)) {
102+
if (lexerHelpers.handleRange(STATE)) {
103103
continue;
104104
}
105105

106106
// handles string interpolation
107-
if (lexerFunctions.checkForStringInterpolationStart(STATE)) {
107+
if (lexerHelpers.checkForStringInterpolationStart(STATE)) {
108108
continue;
109109
}
110-
if(lexerFunctions.checkForStringInterpolationEnd(STATE)) {
110+
if(lexerHelpers.checkForStringInterpolationEnd(STATE)) {
111111
continue;
112112
}
113113

114114
// tokenizes return arrows
115115
if (STATE.currCol === "-" && STATE.nextCol === ">") {
116-
lexerFunctions.checkFor(STATE, 'FUNCTION_DECLARATION', "->", STATE.tokens);
116+
lexerHelpers.checkFor(STATE, 'FUNCTION_DECLARATION', "->", STATE.tokens);
117117
if (STATE.insideFunction.length) {
118118
STATE.lastFunction.returnArrows.push(STATE.tokens.length - 1);
119119
} else {
120120
STATE.variableArrows.push(STATE.tokens.length - 1);
121-
lexerFunctions.rewriteVariableParensHistory(STATE);
121+
lexerHelpers.rewriteVariableParensHistory(STATE);
122122
}
123123
STATE.advanceAndClear(2);
124124
continue;
@@ -134,45 +134,45 @@ module.exports = function(code) {
134134
}
135135

136136
// handles start and end of function invocations
137-
if (lexerFunctions.handleFunctionInvocationStart(STATE)) {
137+
if (lexerHelpers.handleFunctionInvocationStart(STATE)) {
138138
continue;
139139
}
140-
if (lexerFunctions.handleFunctionInvocationEnd(STATE)) {
140+
if (lexerHelpers.handleFunctionInvocationEnd(STATE)) {
141141
continue;
142142
}
143143

144144
// tuple handling
145-
if (lexerFunctions.checkForTupleStart(STATE)) {
145+
if (lexerHelpers.checkForTupleStart(STATE)) {
146146
continue;
147147
}
148-
if (STATE.insideTuple.status && lexerFunctions.handleTuple(STATE)) {
148+
if (STATE.insideTuple.status && lexerHelpers.handleTuple(STATE)) {
149149
continue;
150150
}
151-
if (lexerFunctions.checkForTupleEnd(STATE)) {
152-
lexerFunctions.handleEndOfFile(STATE.nextCol, STATE.tokens);
151+
if (lexerHelpers.checkForTupleEnd(STATE)) {
152+
lexerHelpers.handleEndOfFile(STATE.nextCol, STATE.tokens);
153153
continue;
154154
}
155155

156156
// handles parentheses inside of the function invocation
157-
if (lexerFunctions.handleFunctionInvocationInside(STATE)) {
157+
if (lexerHelpers.handleFunctionInvocationInside(STATE)) {
158158
continue;
159159
}
160160

161161
//handling functions declarations
162-
if (lexerFunctions.handleFunctionDeclarationStart(STATE)) {
162+
if (lexerHelpers.handleFunctionDeclarationStart(STATE)) {
163163
continue;
164164
}
165-
if (lexerFunctions.handleInsideOfFunctionDeclaration(STATE)) {
165+
if (lexerHelpers.handleInsideOfFunctionDeclaration(STATE)) {
166166
continue;
167167
}
168-
if (lexerFunctions.handleFunctionDeclarationEnd(STATE)) {
168+
if (lexerHelpers.handleFunctionDeclarationEnd(STATE)) {
169169
continue;
170170
}
171171

172172
// collection initializer handling
173173
if (STATE.tokens.length && STATE.currCol === '(' &&
174174
(STATE.lastToken.type === 'ARRAY_END' || STATE.lastToken.type === 'DICTIONARY_END')) {
175-
lexerFunctions.checkFor(STATE, 'FUNCTION_INVOCATION', STATE.currCol, STATE.tokens);
175+
lexerHelpers.checkFor(STATE, 'FUNCTION_INVOCATION', STATE.currCol, STATE.tokens);
176176
var tmp = {};
177177
tmp.name = STATE.lastToken.value;
178178
tmp.status = true;
@@ -189,7 +189,7 @@ module.exports = function(code) {
189189
}
190190

191191
// handles classes and structs
192-
if (lexerFunctions.handleClassOrStruct(STATE)) {
192+
if (lexerHelpers.handleClassOrStruct(STATE)) {
193193
continue;
194194
}
195195

@@ -203,74 +203,74 @@ module.exports = function(code) {
203203
}
204204

205205
// handles property access and method calls via dot notation
206-
if (STATE.currCol === '.' && !lexerFunctions.checkForWhitespace(STATE.prevCol) &&
207-
!lexerFunctions.checkForWhitespace(STATE.nextCol) && (
206+
if (STATE.currCol === '.' && !lexerHelpers.checkForWhitespace(STATE.prevCol) &&
207+
!lexerHelpers.checkForWhitespace(STATE.nextCol) && (
208208
STATE.lastToken.type === 'IDENTIFIER' || STATE.lastToken.value === 'self' ||
209209
STATE.lastToken.type === 'TYPE_PROPERTY')) {
210-
lexerFunctions.makeToken(undefined, STATE.chunk, STATE.tokens, 'DOT_SYNTAX', '.');
210+
lexerHelpers.makeToken(undefined, STATE.chunk, STATE.tokens, 'DOT_SYNTAX', '.');
211211
STATE.advanceAndClear(1);
212212
continue;
213213
}
214214

215215
// evaluation block that executes if the lexer is not inside a string,
216216
// not inside a number, and an appropriate evaluation point has been reached
217217
if (!STATE.insideString && !STATE.insideNumber &&
218-
lexerFunctions.checkForEvaluationPoint(STATE)) {
218+
lexerHelpers.checkForEvaluationPoint(STATE)) {
219219

220220
// identifies tuple elements names following dot syntax lookups
221221
if (STATE.lastToken && STATE.lastToken.type === 'DOT_SYNTAX' && STATE.TUPLE_ELEMENT_NAMES[STATE.chunk]) {
222-
lexerFunctions.makeToken(undefined, undefined, STATE.tokens, 'TUPLE_ELEMENT_NAME', STATE.chunk);
222+
lexerHelpers.makeToken(undefined, undefined, STATE.tokens, 'TUPLE_ELEMENT_NAME', STATE.chunk);
223223

224224
// invokes helper function to determine whether a collection is an array or dictionary
225225
// upon identification of certain punctuation
226226
} else if (STATE.insideCollection.length && STATE.lastCollection.type === undefined &&
227-
lexerFunctions.checkFor(STATE, 'PUNCTUATION', STATE.chunk, STATE.tokens)) {
228-
lexerFunctions.determineCollectionType(STATE);
227+
lexerHelpers.checkFor(STATE, 'PUNCTUATION', STATE.chunk, STATE.tokens)) {
228+
lexerHelpers.determineCollectionType(STATE);
229229

230230
// handles the last square bracket arrays and dictionaries appropriately
231231
} else if (STATE.insideCollection.length && STATE.currCol === ']' && !STATE.subscriptLookup) {
232-
lexerFunctions.checkFor(STATE, 'COLLECTION', STATE.chunk, STATE.tokens, function() {
232+
lexerHelpers.checkFor(STATE, 'COLLECTION', STATE.chunk, STATE.tokens, function() {
233233
STATE.tokens[STATE.tokens.length - 1].type = STATE.lastCollection.type || 'ARRAY_END';
234234
STATE.insideCollection.pop();
235235
});
236236

237237
// handles the opens square bracket of arrays and dictionaries
238238
} else if (STATE.tokens.length && STATE.lastToken.type !== 'IDENTIFIER' &&
239239
STATE.lastToken.type !== 'SUBSCRIPT_LOOKUP_END' && STATE.currCol === '[') {
240-
lexerFunctions.checkFor(STATE, 'COLLECTION', STATE.chunk, STATE.tokens, function(){
240+
lexerHelpers.checkFor(STATE, 'COLLECTION', STATE.chunk, STATE.tokens, function(){
241241
STATE.insideCollection.push({type: undefined, location: STATE.tokens.length-1});})
242242

243243
// default, fallthrough evaluation of chunk based on lexical precedence
244244
} else {
245-
lexerFunctions.checkFor(STATE, 'KEYWORD', STATE.chunk, STATE.tokens) ||
246-
lexerFunctions.checkFor(STATE, 'NATIVE_METHOD', STATE.chunk, STATE.tokens) ||
247-
lexerFunctions.checkFor(STATE, 'METHOD_ARGUMENT_NAME', STATE.chunk, STATE.tokens) ||
248-
lexerFunctions.checkFor(STATE, 'TYPE_PROPERTY', STATE.chunk, STATE.tokens) ||
249-
lexerFunctions.checkFor(STATE, 'TYPE', STATE.chunk, STATE.tokens) ||
250-
lexerFunctions.checkFor(STATE, 'PUNCTUATION', STATE.chunk, STATE.tokens) ||
251-
lexerFunctions.checkFor(STATE, 'SUBSCRIPT_LOOKUP', STATE.chunk, STATE.tokens, function() {
245+
lexerHelpers.checkFor(STATE, 'KEYWORD', STATE.chunk, STATE.tokens) ||
246+
lexerHelpers.checkFor(STATE, 'NATIVE_METHOD', STATE.chunk, STATE.tokens) ||
247+
lexerHelpers.checkFor(STATE, 'METHOD_ARGUMENT_NAME', STATE.chunk, STATE.tokens) ||
248+
lexerHelpers.checkFor(STATE, 'TYPE_PROPERTY', STATE.chunk, STATE.tokens) ||
249+
lexerHelpers.checkFor(STATE, 'TYPE', STATE.chunk, STATE.tokens) ||
250+
lexerHelpers.checkFor(STATE, 'PUNCTUATION', STATE.chunk, STATE.tokens) ||
251+
lexerHelpers.checkFor(STATE, 'SUBSCRIPT_LOOKUP', STATE.chunk, STATE.tokens, function() {
252252
STATE.subscriptLookup = !STATE.subscriptLookup;
253253
}) ||
254-
lexerFunctions.checkFor(STATE, 'OPERATOR', STATE.chunk, STATE.tokens) ||
255-
lexerFunctions.checkFor(STATE, 'TERMINATOR', STATE.chunk, STATE.tokens) ||
256-
lexerFunctions.checkForIdentifier(STATE) ||
257-
lexerFunctions.checkForLiteral(STATE.chunk, STATE.tokens);
254+
lexerHelpers.checkFor(STATE, 'OPERATOR', STATE.chunk, STATE.tokens) ||
255+
lexerHelpers.checkFor(STATE, 'TERMINATOR', STATE.chunk, STATE.tokens) ||
256+
lexerHelpers.checkForIdentifier(STATE) ||
257+
lexerHelpers.checkForLiteral(STATE.chunk, STATE.tokens);
258258
}
259259

260260
STATE.clearChunk();
261261

262262
// special evaluation point handling
263-
if (lexerFunctions.checkForWhitespace(STATE.nextCol)) {
263+
if (lexerHelpers.checkForWhitespace(STATE.nextCol)) {
264264
STATE.advance(1);
265265
}
266-
lexerFunctions.handleEndOfFile(STATE.nextCol, STATE.tokens);
266+
lexerHelpers.handleEndOfFile(STATE.nextCol, STATE.tokens);
267267

268268
}
269269
STATE.advance(1);
270270
}
271271

272272
if (STATE.tokens[STATE.tokens.length - 1].value === '\\n') {
273-
lexerFunctions.makeToken(undefined, undefined, STATE.tokens, 'TERMINATOR', 'EOF');
273+
lexerHelpers.makeToken(undefined, undefined, STATE.tokens, 'TERMINATOR', 'EOF');
274274
}
275275

276276
return STATE.tokens;
File renamed without changes.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy