Commit d2e14e3e authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Fixed the automatic insertion of `;' tokens and improved the QtScriptParser.

parent 4d3c555a
...@@ -269,6 +269,12 @@ public: ...@@ -269,6 +269,12 @@ public:
DiagnosticMessage(Kind kind, int line, int column, const QString &message) DiagnosticMessage(Kind kind, int line, int column, const QString &message)
: kind(kind), line(line), column(column), message(message) {} : kind(kind), line(line), column(column), message(message) {}
bool isWarning() const
{ return kind == Warning; }
bool isError() const
{ return kind == Error; }
Kind kind; Kind kind;
int line; int line;
int column; int column;
...@@ -2083,17 +2089,15 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ; ...@@ -2083,17 +2089,15 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
tk.dval = yylval; tk.dval = yylval;
tk.loc = yylloc; tk.loc = yylloc;
#if 0
const QString msg = QString::fromUtf8("Missing `;'"); const QString msg = QString::fromUtf8("Missing `;'");
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning,
yylloc.startLine, yylloc.startColumn, msg)); yylloc.startLine, yylloc.startColumn, msg));
#endif
first_token = &token_buffer[0]; first_token = &token_buffer[0];
last_token = &token_buffer[1]; last_token = &token_buffer[1];
yytoken = T_AUTOMATIC_SEMICOLON; yytoken = T_SEMICOLON;
yylval = 0; yylval = 0;
action = errorState; action = errorState;
...@@ -2103,24 +2107,6 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ; ...@@ -2103,24 +2107,6 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
hadErrors = true; hadErrors = true;
static int tokens[] = {
T_PLUS,
T_EQ,
T_COMMA,
T_COLON,
T_SEMICOLON,
T_RPAREN, T_RBRACKET, T_RBRACE,
T_NUMERIC_LITERAL,
T_IDENTIFIER,
T_LPAREN, T_LBRACKET, T_LBRACE,
EOF_SYMBOL
};
token_buffer[0].token = yytoken; token_buffer[0].token = yytoken;
token_buffer[0].dval = yylval; token_buffer[0].dval = yylval;
token_buffer[0].loc = yylloc; token_buffer[0].loc = yylloc;
...@@ -2139,6 +2125,24 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ; ...@@ -2139,6 +2125,24 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
goto _Lcheck_token; goto _Lcheck_token;
} }
static int tokens[] = {
T_PLUS,
T_EQ,
T_COMMA,
T_COLON,
T_SEMICOLON,
T_RPAREN, T_RBRACKET, T_RBRACE,
T_NUMERIC_LITERAL,
T_IDENTIFIER,
T_LPAREN, T_LBRACKET, T_LBRACE,
EOF_SYMBOL
};
for (int *tk = tokens; *tk != EOF_SYMBOL; ++tk) { for (int *tk = tokens; *tk != EOF_SYMBOL; ++tk) {
int a = t_action(errorState, *tk); int a = t_action(errorState, *tk);
if (a > 0 && t_action(a, yytoken)) { if (a > 0 && t_action(a, yytoken)) {
......
...@@ -1094,17 +1094,15 @@ case 266: { ...@@ -1094,17 +1094,15 @@ case 266: {
tk.dval = yylval; tk.dval = yylval;
tk.loc = yylloc; tk.loc = yylloc;
#if 0
const QString msg = QString::fromUtf8("Missing `;'"); const QString msg = QString::fromUtf8("Missing `;'");
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning, diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning,
yylloc.startLine, yylloc.startColumn, msg)); yylloc.startLine, yylloc.startColumn, msg));
#endif
first_token = &token_buffer[0]; first_token = &token_buffer[0];
last_token = &token_buffer[1]; last_token = &token_buffer[1];
yytoken = T_AUTOMATIC_SEMICOLON; yytoken = T_SEMICOLON;
yylval = 0; yylval = 0;
action = errorState; action = errorState;
...@@ -1114,24 +1112,6 @@ case 266: { ...@@ -1114,24 +1112,6 @@ case 266: {
hadErrors = true; hadErrors = true;
static int tokens[] = {
T_PLUS,
T_EQ,
T_COMMA,
T_COLON,
T_SEMICOLON,
T_RPAREN, T_RBRACKET, T_RBRACE,
T_NUMERIC_LITERAL,
T_IDENTIFIER,
T_LPAREN, T_LBRACKET, T_LBRACE,
EOF_SYMBOL
};
token_buffer[0].token = yytoken; token_buffer[0].token = yytoken;
token_buffer[0].dval = yylval; token_buffer[0].dval = yylval;
token_buffer[0].loc = yylloc; token_buffer[0].loc = yylloc;
...@@ -1150,6 +1130,24 @@ case 266: { ...@@ -1150,6 +1130,24 @@ case 266: {
goto _Lcheck_token; goto _Lcheck_token;
} }
static int tokens[] = {
T_PLUS,
T_EQ,
T_COMMA,
T_COLON,
T_SEMICOLON,
T_RPAREN, T_RBRACKET, T_RBRACE,
T_NUMERIC_LITERAL,
T_IDENTIFIER,
T_LPAREN, T_LBRACKET, T_LBRACE,
EOF_SYMBOL
};
for (int *tk = tokens; *tk != EOF_SYMBOL; ++tk) { for (int *tk = tokens; *tk != EOF_SYMBOL; ++tk) {
int a = t_action(errorState, *tk); int a = t_action(errorState, *tk);
if (a > 0 && t_action(a, yytoken)) { if (a > 0 && t_action(a, yytoken)) {
......
...@@ -120,6 +120,12 @@ public: ...@@ -120,6 +120,12 @@ public:
DiagnosticMessage(Kind kind, int line, int column, const QString &message) DiagnosticMessage(Kind kind, int line, int column, const QString &message)
: kind(kind), line(line), column(column), message(message) {} : kind(kind), line(line), column(column), message(message) {}
bool isWarning() const
{ return kind == Warning; }
bool isError() const
{ return kind == Error; }
Kind kind; Kind kind;
int line; int line;
int column; int column;
......
...@@ -86,11 +86,15 @@ protected: ...@@ -86,11 +86,15 @@ protected:
virtual bool visit(FunctionDeclaration *ast) virtual bool visit(FunctionDeclaration *ast)
{ {
if (! ast->name)
return false;
QString text = ast->name->asString(); QString text = ast->name->asString();
text += QLatin1Char('('); text += QLatin1Char('(');
for (FormalParameterList *it = ast->formals; it; it = it->next) { for (FormalParameterList *it = ast->formals; it; it = it->next) {
text += it->name->asString(); if (it->name)
text += it->name->asString();
if (it->next) if (it->next)
text += QLatin1String(", "); text += QLatin1String(", ");
...@@ -100,7 +104,7 @@ protected: ...@@ -100,7 +104,7 @@ protected:
Declaration d; Declaration d;
d.text = text; d.text = text;
d.startLine= ast->startLine; d.startLine = ast->startLine;
d.startColumn = ast->startColumn; d.startColumn = ast->startColumn;
d.endLine = ast->endLine; d.endLine = ast->endLine;
d.endColumn = ast->endColumn; d.endColumn = ast->endColumn;
...@@ -112,6 +116,9 @@ protected: ...@@ -112,6 +116,9 @@ protected:
virtual bool visit(VariableDeclaration *ast) virtual bool visit(VariableDeclaration *ast)
{ {
if (! ast->name)
return false;
Declaration d; Declaration d;
d.text = ast->name->asString(); d.text = ast->name->asString();
d.startLine= ast->startLine; d.startLine= ast->startLine;
...@@ -201,20 +208,23 @@ void ScriptEditor::updateDocumentNow() ...@@ -201,20 +208,23 @@ void ScriptEditor::updateDocumentNow()
lexer.setCode(code, /*line = */ 1); lexer.setCode(code, /*line = */ 1);
driver.setLexer(&lexer); driver.setLexer(&lexer);
parser.parse(&driver); if (parser.parse(&driver)) {
JavaScript::AST::Visitor v;
driver.ast()->accept(&v);
FindDeclarations decls; FindDeclarations decls;
m_declarations = decls.accept(driver.ast()); m_declarations = decls.accept(driver.ast());
QStringList items; QStringList items;
items.append(tr("<Select Symbol>")); items.append(tr("<Select Symbol>"));
foreach (Declaration decl, m_declarations) foreach (Declaration decl, m_declarations)
items.append(decl.text); items.append(decl.text);
m_methodCombo->clear(); m_methodCombo->clear();
m_methodCombo->addItems(items); m_methodCombo->addItems(items);
updateMethodBoxIndex(); updateMethodBoxIndex();
}
QList<QTextEdit::ExtraSelection> selections; QList<QTextEdit::ExtraSelection> selections;
...@@ -229,21 +239,20 @@ void ScriptEditor::updateDocumentNow() ...@@ -229,21 +239,20 @@ void ScriptEditor::updateDocumentNow()
QTextEdit::ExtraSelection sel; QTextEdit::ExtraSelection sel;
foreach (const JavaScriptParser::DiagnosticMessage &d, parser.diagnosticMessages()) { foreach (const JavaScriptParser::DiagnosticMessage &d, parser.diagnosticMessages()) {
const int line = d.line; if (d.isWarning())
continue;
QTextCursor c(document()->findBlockByNumber(line - 1)); int line = d.line;
sel.cursor = c; int column = d.column;
if (parser.errorColumnNumber() > 1) if (column == 0)
sel.cursor.setPosition(c.position() + d.column - 1); column = 1;
if (d.kind == JavaScriptParser::DiagnosticMessage::Warning) { sel.format = errorFormat;
sel.format = warningFormat;
sel.cursor.movePosition(QTextCursor::StartOfWord);
} else {
sel.format = errorFormat;
}
QTextCursor c(document()->findBlockByNumber(line - 1));
sel.cursor = c;
sel.cursor.setPosition(c.position() + column - 1);
sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
selections.append(sel); selections.append(sel);
...@@ -328,7 +337,8 @@ static void indentScriptBlock(const TextEditor::TabSettings &ts, ...@@ -328,7 +337,8 @@ static void indentScriptBlock(const TextEditor::TabSettings &ts,
{ {
typedef typename SharedTools::Indenter<Iterator> Indenter ; typedef typename SharedTools::Indenter<Iterator> Indenter ;
Indenter &indenter = Indenter::instance(); Indenter &indenter = Indenter::instance();
indenter.setIndentSize(ts.m_tabSize); indenter.setTabSize(ts.m_tabSize);
indenter.setIndentSize(ts.m_indentSize);
const TextEditor::TextBlockIterator current(block); const TextEditor::TextBlockIterator current(block);
const int indent = indenter.indentForBottomLine(current, programBegin, const int indent = indenter.indentForBottomLine(current, programBegin,
programEnd, typedChar); programEnd, typedChar);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment