mirror of
https://github.com/boxgaming/qbjs.git
synced 2024-09-19 20:14:58 +00:00
add support for LET and REM
This commit is contained in:
parent
1a257e3e92
commit
d8cb436930
3 changed files with 20 additions and 9 deletions
|
@ -28,7 +28,7 @@ CodeMirror.defineMode("qbjs", function(conf, parserConf) {
|
|||
var endKeywords = ['next','loop','wend'];
|
||||
|
||||
var wordOperators = wordRegexp(['and', 'or', 'not', 'xor', 'is', 'mod', 'eqv', 'imp']);
|
||||
var commonkeywords = ['dim', 'as', 'redim', 'then', 'until', 'exit', 'in', 'to',
|
||||
var commonkeywords = ['dim', 'as', 'redim', 'then', 'until', 'exit', 'in', 'to', 'let',
|
||||
'const', 'integer', 'single', 'double', 'long', '_unsigned', 'string', '_byte', 'object',
|
||||
'option explicit', 'call', 'step'];
|
||||
|
||||
|
|
14
qb2js.js
14
qb2js.js
|
@ -430,7 +430,7 @@ if (QB.halted()) { return; }
|
|||
} else {
|
||||
await sub_AddWarning( i, "Missing Sub [" + subname + "], ignoring Call command");
|
||||
}
|
||||
} else if ( c > 2) {
|
||||
} else if ( c > 2 || first == "LET" ) {
|
||||
var assignment = 0; /* INTEGER */
|
||||
assignment = 0;
|
||||
var j = 0; /* INTEGER */
|
||||
|
@ -440,8 +440,13 @@ if (QB.halted()) { return; }
|
|||
break;
|
||||
}
|
||||
}
|
||||
var asnVarIndex = 0; /* SINGLE */
|
||||
asnVarIndex = 1;
|
||||
if ( first == "LET" ) {
|
||||
asnVarIndex = 2;
|
||||
}
|
||||
if ( assignment > 0) {
|
||||
js = (await func_RemoveSuffix( (await func_ConvertExpression( (await func_Join( parts , 1, assignment - 1, " ")) , i)))) + " = " + (await func_ConvertExpression( (await func_Join( parts , assignment + 1, - 1, " ")) , i)) + ";";
|
||||
js = (await func_RemoveSuffix( (await func_ConvertExpression( (await func_Join( parts , asnVarIndex, assignment - 1, " ")) , i)))) + " = " + (await func_ConvertExpression( (await func_Join( parts , assignment + 1, - 1, " ")) , i)) + ";";
|
||||
} else {
|
||||
if ((await func_FindMethod( QB.arrayValue(parts, [ 1]).value , m, "SUB")) ) {
|
||||
js = (await func_ConvertSub( m, (await func_Join( parts , 2, - 1, " ")) , i));
|
||||
|
@ -1581,8 +1586,9 @@ var ReadLine = null;
|
|||
quoteDepth = 0;
|
||||
var i = 0; /* INTEGER */
|
||||
for ( i= 1; i <= (QB.func_Len( fline)); i= i + 1) { if (QB.halted()) { return; }
|
||||
var c = ''; /* STRING */
|
||||
var c = ''; /* STRING */ var c4 = ''; /* STRING */
|
||||
c = (QB.func_Mid( fline, i, 1));
|
||||
c4 = (QB.func_UCase( (QB.func_Mid( fline, i, 4))));
|
||||
if ( c == (QB.func_Chr( 34)) ) {
|
||||
if ( quoteDepth == 0) {
|
||||
quoteDepth = 1;
|
||||
|
@ -1590,7 +1596,7 @@ var ReadLine = null;
|
|||
quoteDepth = 0;
|
||||
}
|
||||
}
|
||||
if ( quoteDepth == 0 && c == "'" ) {
|
||||
if ( quoteDepth == 0 && ( c == "'" || c4 == "REM ") ) {
|
||||
fline = (QB.func_Left( fline, i - 1));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -512,7 +512,7 @@ Sub ConvertLines (firstLine As Integer, lastLine As Integer, functionName As Str
|
|||
AddWarning i, "Missing Sub [" + subname + "], ignoring Call command"
|
||||
End If
|
||||
|
||||
ElseIf c > 2 Then
|
||||
ElseIf c > 2 Or first = "LET" Then
|
||||
Dim assignment As Integer
|
||||
assignment = 0
|
||||
Dim j As Integer
|
||||
|
@ -523,11 +523,15 @@ Sub ConvertLines (firstLine As Integer, lastLine As Integer, functionName As Str
|
|||
End If
|
||||
Next j
|
||||
|
||||
Dim asnVarIndex
|
||||
asnVarIndex = 1
|
||||
If first = "LET" Then asnVarIndex = 2
|
||||
|
||||
If assignment > 0 Then
|
||||
' This is a variable assignment
|
||||
' TODO: implicit variable declaration
|
||||
' TODO: special case for Mid$ statement
|
||||
js = RemoveSuffix(ConvertExpression(Join(parts(), 1, assignment - 1, " "), i)) + " = " + ConvertExpression(Join(parts(), assignment + 1, -1, " "), i) + ";"
|
||||
js = RemoveSuffix(ConvertExpression(Join(parts(), asnVarIndex, assignment - 1, " "), i)) + " = " + ConvertExpression(Join(parts(), assignment + 1, -1, " "), i) + ";"
|
||||
|
||||
Else
|
||||
If FindMethod(parts(1), m, "SUB") Then
|
||||
|
@ -1683,8 +1687,9 @@ Function ReadLine (lineIndex As Integer, fline As String, rawJS As Integer)
|
|||
quoteDepth = 0
|
||||
Dim i As Integer
|
||||
For i = 1 To Len(fline)
|
||||
Dim c As String
|
||||
Dim As String c, c4
|
||||
c = Mid$(fline, i, 1)
|
||||
c4 = UCase$(Mid$(fline, i, 4))
|
||||
If c = Chr$(34) Then
|
||||
If quoteDepth = 0 Then
|
||||
quoteDepth = 1
|
||||
|
@ -1692,7 +1697,7 @@ Function ReadLine (lineIndex As Integer, fline As String, rawJS As Integer)
|
|||
quoteDepth = 0
|
||||
End If
|
||||
End If
|
||||
If quoteDepth = 0 And c = "'" Then
|
||||
If quoteDepth = 0 And (c = "'" Or c4 = "REM ") Then
|
||||
fline = Left$(fline, i - 1)
|
||||
Exit For
|
||||
End If
|
||||
|
|
Loading…
Reference in a new issue