Anonymous avatar Anonymous committed 0ec3e9a

- Corrected typo.
- Fixed a bug, where unmatched closed bracket crashed parser.

Comments (0)

Files changed (6)

org.lispdev.parser/src/org/lispdev/parser/LispParser.java

 import org.lispdev.parser.tokens.TokenEOF;
 
 
+/**
+ * Creates ast tree from list of tokens
+ */
 public class LispParser
 {
-  List<Token> tokens;
-  ListIterator<Token> iterator;
+  private final List<Token> tokens;
+  private ListIterator<Token> iterator;
 
   public LispParser(List<Token> t)
   {
     iterator = tokens.listIterator();
   }
 
-  Node newNode;
+  private Node newNode;
 
   public TreeRoot parse()
   {
         return parseOperator(t);
       case OPEN_PAREN :
         return parseOpenParen(t);
+      case CLOSE_PAREN :
+        return parseCloseParen(t);
       default:
-        Assert.isLegal(true,"Parsing is not defined for: "+t.toString());
+        Assert.isLegal(false,"Parsing is not defined for: "+t.toString());
         return null;
     }
   }
         newNode = res;
         return iterator.next();
       }
-      String breakStr = t.isBraking();
+      String breakStr = t.isBreaking();
       if( breakStr != null )
       {
         res.setError(new ParseError(t.offset(), 1, ")", breakStr));
     }
   }
 
+  /**
+   * @param t token having the property that t.isCloseParen() == true
+   * Only should happen when parens are unbalanced.
+   */
+  private Token parseCloseParen(Token t)
+  {
+    Node res = new Node(t);
+    res.setError(new ParseError(t.offset(), 1, "", ")"));
+    newNode = res;
+    return iterator.next();
+  }
+
   private Token parseOperator(Token t)
   {
     OperatorNode res = new OperatorNode(t);
     t = skipHiddens(res);
-    String bs = t.isBraking();
+    String bs = t.isBreaking();
     if( bs != null ) //error
     {
       if( bs.equals("(") )

org.lispdev.parser/src/org/lispdev/parser/tokens/Token.java

 
   /**
    * Checks if the token can break unmatched pair ( '(', #| or " )
-   * @return true if breaks parsing at unmatched
-   * error in previous top level form
+   * @return error string if breaks parsing at unmatched
+   * error in previous top level form or null if not breaking
    */
-  public String isBraking()
+  public String isBreaking()
   {
     return null;
   }

org.lispdev.parser/src/org/lispdev/parser/tokens/TokenEOF.java

   }
 
   @Override
-  public String isBraking()
+  public String isBreaking()
   {
     return "EOF";
   }

org.lispdev.parser/src/org/lispdev/parser/tokens/TokenOutline.java

   }
 
   @Override
-  public String isBraking()
+  public String isBreaking()
   {
     return (parseType != ParseType.HIDDEN ? "outline comment" : null);
   }

org.lispdev.parser/src/org/lispdev/parser/tokens/TokenTLParen.java

     return ParseType.OPEN_PAREN;
   }
 
-  public String isBraking()
+  public String isBreaking()
   {
     return "(";
   }

org.lispdev.parser/src/org/lispdev/parser/tokens/TokenUtils.java

 
   public static boolean parsingEqual(Token n0, Token n1)
   {
-    return n0.isBraking() == n1.isBraking() && n0.parseType() == n1.parseType();
+    return n0.isBreaking() == n1.isBreaking() && n0.parseType() == n1.parseType();
   }
 
   public static void adjustTokenOffset(Token t, int offset)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.