Skip to content
This repository has been archived by the owner on May 13, 2019. It is now read-only.

Commit

Permalink
Fix "error" rule handling -- semicolon insertion works!
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewd committed Jan 22, 2011
1 parent a287633 commit 6f43668
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/capuchin/parser.rb
Expand Up @@ -450,7 +450,7 @@ class Capuchin::Parser < Parslet::Parser
end end


rule(:variable_statement) do rule(:variable_statement) do
`var` >> sp >> variable_declaration_list.as(:vars) >> sp? >> (`;` | error) `var` >> sp >> variable_declaration_list.as(:vars) >> (sp? >> `;` | error)
end end


rule(:variable_declaration_list) do rule(:variable_declaration_list) do
Expand All @@ -468,7 +468,7 @@ class Capuchin::Parser < Parslet::Parser
end end


rule(:const_statement) do rule(:const_statement) do
`const` >> sp >> const_declaration_list >> sp? >> (`;` | error) `const` >> sp >> const_declaration_list >> (sp? >> `;` | error)
end end
rule(:const_declaration_list) do rule(:const_declaration_list) do
const_declaration.as(:first) >> (sp? >> `,` >> sp? >> const_declaration).repeat.as(:rest) const_declaration.as(:first) >> (sp? >> `,` >> sp? >> const_declaration).repeat.as(:rest)
Expand All @@ -482,15 +482,15 @@ class Capuchin::Parser < Parslet::Parser
end end


rule(:expr_statement) do rule(:expr_statement) do
expr_no_bf.as(:expr_statement) >> sp? >> (`;` | error) expr_no_bf.as(:expr_statement) >> (sp? >> `;` | error)
end end


rule(:if_statement) do rule(:if_statement) do
`if` >> sp? >> `(` >> sp? >> expr.as(:if_condition) >> sp? >> `)` >> sp? >> statement.as(:true_part) >> (sp? >> `else` >> sp? >> statement).maybe.as(:false_part) `if` >> sp? >> `(` >> sp? >> expr.as(:if_condition) >> sp? >> `)` >> sp? >> statement.as(:true_part) >> (sp? >> `else` >> sp? >> statement).maybe.as(:false_part)
end end


rule(:iteration_statement) do rule(:iteration_statement) do
`do` >> sp? >> statement.as(:code) >> sp? >> `while` >> sp? >> `(` >> sp? >> expr.as(:do_while) >> sp? >> `)` >> sp? >> (`;` | error) | `do` >> sp? >> statement.as(:code) >> sp? >> `while` >> sp? >> `(` >> sp? >> expr.as(:do_while) >> sp? >> `)` >> (sp? >> `;` | error) |
`while` >> sp? >> `(` >> sp? >> expr.as(:while) >> sp? >> `)` >> sp? >> statement.as(:code) | `while` >> sp? >> `(` >> sp? >> expr.as(:while) >> sp? >> `)` >> sp? >> statement.as(:code) |
`for` >> sp? >> `(` >> sp? >> (expr_no_in >> sp?).maybe.as(:init) >> `;` >> sp? >> (expr >> sp?).maybe.as(:test) >> `;` >> sp? >> (expr >> sp?).maybe.as(:counter) >> `)` >> sp? >> statement.as(:code) | `for` >> sp? >> `(` >> sp? >> (expr_no_in >> sp?).maybe.as(:init) >> `;` >> sp? >> (expr >> sp?).maybe.as(:test) >> `;` >> sp? >> (expr >> sp?).maybe.as(:counter) >> `)` >> sp? >> statement.as(:code) |
`for` >> sp? >> `(` >> sp? >> (`var` >> sp >> variable_declaration_list_no_in.as(:vars)).as(:init) >> sp? >> `;` >> sp? >> (expr >> sp?).maybe.as(:test) >> `;` >> sp? >> (expr >> sp?).maybe.as(:counter) >> `)` >> sp? >> statement.as(:code) | `for` >> sp? >> `(` >> sp? >> (`var` >> sp >> variable_declaration_list_no_in.as(:vars)).as(:init) >> sp? >> `;` >> sp? >> (expr >> sp?).maybe.as(:test) >> `;` >> sp? >> (expr >> sp?).maybe.as(:counter) >> `)` >> sp? >> statement.as(:code) |
Expand All @@ -500,13 +500,13 @@ class Capuchin::Parser < Parslet::Parser
end end


rule(:continue_statement) do rule(:continue_statement) do
`continue` >> (sp >> ident).maybe.as(:continue) >> sp? >> (`;` | error) `continue` >> (sp >> ident).maybe.as(:continue) >> (sp? >> `;` | error)
end end
rule(:break_statement) do rule(:break_statement) do
`break` >> (sp >> ident).maybe.as(:break) >> sp? >> (`;` | error) `break` >> (sp >> ident).maybe.as(:break) >> (sp? >> `;` | error)
end end
rule(:return_statement) do rule(:return_statement) do
`return` >> sp? >> (expr >> sp?).maybe.as(:return) >> (`;` | error) `return` >> (sp? >> expr).maybe.as(:return) >> (sp? >> `;` | error)
end end


rule(:with_statement) do rule(:with_statement) do
Expand All @@ -532,7 +532,7 @@ class Capuchin::Parser < Parslet::Parser
end end


rule(:throw_statement) do rule(:throw_statement) do
`throw` >> sp? >> expr.as(:throw) >> sp? >> (`;` | error) `throw` >> sp? >> expr.as(:throw) >> (sp? >> `;` | error)
end end


rule(:try_statement) do rule(:try_statement) do
Expand Down Expand Up @@ -605,7 +605,7 @@ class Capuchin::Parser < Parslet::Parser
end end


rule(:error) do rule(:error) do
match("[ \t]").repeat >> `\n` | eof match("[ \t]").repeat >> (`}`.prsnt? | match("[\r\n]") | eof)
end end


rule(:eof) do rule(:eof) do
Expand Down

0 comments on commit 6f43668

Please sign in to comment.