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:
DiagnosticMessage(Kind kind, int line, int column, const QString &message)
: kind(kind), line(line), column(column), message(message) {}
bool isWarning() const
{ return kind == Warning; }
bool isError() const
{ return kind == Error; }
Kind kind;
int line;
int column;
......@@ -2083,17 +2089,15 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
tk.dval = yylval;
tk.loc = yylloc;
#if 0
const QString msg = QString::fromUtf8("Missing `;'");
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning,
yylloc.startLine, yylloc.startColumn, msg));
#endif
first_token = &token_buffer[0];
last_token = &token_buffer[1];
yytoken = T_AUTOMATIC_SEMICOLON;
yytoken = T_SEMICOLON;
yylval = 0;
action = errorState;
......@@ -2103,24 +2107,6 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
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].dval = yylval;
token_buffer[0].loc = yylloc;
......@@ -2139,6 +2125,24 @@ PropertyNameAndValueListOpt: PropertyNameAndValueList ;
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) {
int a = t_action(errorState, *tk);
if (a > 0 && t_action(a, yytoken)) {
......
......@@ -1094,17 +1094,15 @@ case 266: {
tk.dval = yylval;
tk.loc = yylloc;
#if 0
const QString msg = QString::fromUtf8("Missing `;'");
diagnostic_messages.append(DiagnosticMessage(DiagnosticMessage::Warning,
yylloc.startLine, yylloc.startColumn, msg));
#endif
first_token = &token_buffer[0];
last_token = &token_buffer[1];
yytoken = T_AUTOMATIC_SEMICOLON;
yytoken = T_SEMICOLON;
yylval = 0;
action = errorState;
......@@ -1114,24 +1112,6 @@ case 266: {
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].dval = yylval;
token_buffer[0].loc = yylloc;
......@@ -1150,6 +1130,24 @@ case 266: {
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) {
int a = t_action(errorState, *tk);
if (a > 0 && t_action(a, yytoken)) {
......
......@@ -120,6 +120,12 @@ public:
DiagnosticMessage(Kind kind, int line, int column, const QString &message)
: kind(kind), line(line), column(column), message(message) {}
bool isWarning() const
{ return kind == Warning; }
bool isError() const
{ return kind == Error; }
Kind kind;
int line;
int column;
......
......@@ -86,11 +86,15 @@ protected:
virtual bool visit(FunctionDeclaration *ast)
{
if (! ast->name)
return false;
QString text = ast->name->asString();
text += QLatin1Char('(');
for (FormalParameterList *it = ast->formals; it; it = it->next) {
text += it->name->asString();
if (it->name)
text += it->name->asString();
if (it->next)
text += QLatin1String(", ");
......@@ -100,7 +104,7 @@ protected:
Declaration d;
d.text = text;
d.startLine= ast->startLine;
d.startLine = ast->startLine;
d.startColumn = ast->startColumn;
d.endLine = ast->endLine;
d.endColumn = ast->endColumn;
......@@ -112,6 +116,9 @@ protected:
virtual bool visit(VariableDeclaration *ast)
{
if (! ast->name)
return false;
Declaration d;
d.text = ast->name->asString();
d.startLine= ast->startLine;
......@@ -201,20 +208,23 @@ void ScriptEditor::updateDocumentNow()
lexer.setCode(code, /*line = */ 1);
driver.setLexer(&lexer);
parser.parse(&driver);
if (parser.parse(&driver)) {
JavaScript::AST::Visitor v;
driver.ast()->accept(&v);
FindDeclarations decls;
m_declarations = decls.accept(driver.ast());
FindDeclarations decls;
m_declarations = decls.accept(driver.ast());
QStringList items;
items.append(tr("<Select Symbol>"));
QStringList items;
items.append(tr("<Select Symbol>"));
foreach (Declaration decl, m_declarations)
items.append(decl.text);
foreach (Declaration decl, m_declarations)
items.append(decl.text);
m_methodCombo->clear();
m_methodCombo->addItems(items);
updateMethodBoxIndex();
m_methodCombo->clear();
m_methodCombo->addItems(items);
updateMethodBoxIndex();
}
QList<QTextEdit::ExtraSelection> selections;
......@@ -229,21 +239,20 @@ void ScriptEditor::updateDocumentNow()
QTextEdit::ExtraSelection sel;
foreach (const JavaScriptParser::DiagnosticMessage &d, parser.diagnosticMessages()) {
const int line = d.line;
if (d.isWarning())
continue;
QTextCursor c(document()->findBlockByNumber(line - 1));
sel.cursor = c;
int line = d.line;
int column = d.column;
if (parser.errorColumnNumber() > 1)
sel.cursor.setPosition(c.position() + d.column - 1);
if (column == 0)
column = 1;
if (d.kind == JavaScriptParser::DiagnosticMessage::Warning) {
sel.format = warningFormat;
sel.cursor.movePosition(QTextCursor::StartOfWord);
} else {
sel.format = errorFormat;
}
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);
selections.append(sel);
......@@ -328,7 +337,8 @@ static void indentScriptBlock(const TextEditor::TabSettings &ts,
{
typedef typename SharedTools::Indenter<Iterator> Indenter ;
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 int indent = indenter.indentForBottomLine(current, programBegin,
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