| Author | Dave Jarvis <email> |
|---|---|
| Date | 2015-02-28 10:05:47 GMT-0800 |
| Commit | e581a4d830e2d5e1a9b3db35721091ad64161ece |
| Parent | 4e8509b |
| .last_name > name/last, # maps a column to an ancestor node | ||
| .age > @age, # @ maps a column to an attribute node | ||
| -account.person_id +> person.person_id, # performs an INNER JOIN | ||
| +account.person_id +> person.person_id, # +> performs an INNER JOIN | ||
| account > account, # context is now "account" node | ||
| .id > @id, # account id attribute | ||
| ^, # pop stack to previous context | ||
| address > address, # switch context to "address" node | ||
| .*, # .* globs all columns | ||
| -account.person_id -> company.person_id, # performs an OUTER JOIN | ||
| +account.person_id -> company.person_id, # -> performs an OUTER JOIN | ||
| ; # Starts the optional WHERE clause | ||
| ``` |
| token Identifier (letter (letter | digit | '_')*) ; | ||
| token LineTerminator (',') ; | ||
| -token AssociatedWith ('>') ; | ||
| +token AssignMap ('>') ; | ||
| +token InnerJoin ('+' '>') ; | ||
| +token OuterJoin ('-' '>') ; | ||
| -TTable. Table ::= Identifier ; | ||
| -TColumn. Column ::= "." Identifier ; | ||
| -TTableColumn. TableColumn ::= Identifier Column ; | ||
| -TAttribute. Attribute ::= "@" Identifier ; | ||
| -TParameter. Parameter ::= "$" Identifier ; | ||
| +TTbl. Table ::= Identifier ; | ||
| +TCol. Column ::= "." Identifier ; | ||
| +TTblCol. TableColumn ::= Identifier Column ; | ||
| +TAttr. Attribute ::= "@" Identifier ; | ||
| +TParam. Parameter ::= "$" Identifier ; | ||
| RXM. Query ::= Start Map ";" Where ; | ||
| SDecl. Start ::= StartDecl LineTerminator; | ||
| -SStart. StartDecl ::= "root" AssociatedWith Element ; | ||
| +SStart. StartDecl ::= "root" AssignMap Element ; | ||
| SModule. StartDecl ::= "module" Identifier ; | ||
| MDecl. Map ::= MapDecl LineTerminator ; | ||
| MGlob. MapDecl ::= ".*" ; | ||
| MLine. MapDecl ::= LineDecl ; | ||
| - | ||
| -LDNode. LineDecl ::= LineNode; | ||
| -LDJoin. LineDecl ::= LineJoin; | ||
| -LDPop. LineDecl ::= LinePop; | ||
| -LDImp. LineDecl ::= LineImport; | ||
| -LNode. LineNode ::= Entity AssociatedWith Node ; | ||
| -LJoin. LineJoin ::= TableColumn AssociatedWith TableColumn ; | ||
| -LPop. LinePop ::= "^" ; | ||
| -LImp. LineImport ::= "import" Identifier ; | ||
| +ETbl. Entity ::= Table ; | ||
| +ECol. Entity ::= Column ; | ||
| -rules Entity ::= Table | Column | TableColumn ; | ||
| +NElem. Node ::= Element ; | ||
| +NAttr. Node ::= Attribute ; | ||
| -NodeElem. Node ::= Element ; | ||
| -NodeAttr. Node ::= Attribute ; | ||
| +DeclNode. LineDecl ::= Entity AssignMap Node ; | ||
| +DeclInner. LineDecl ::= TableColumn InnerJoin TableColumn ; | ||
| +DeclOuter. LineDecl ::= TableColumn OuterJoin TableColumn ; | ||
| +DeclPop. LineDecl ::= "^" ; | ||
| +DeclImport. LineDecl ::= "import" Identifier ; | ||
| ElIdent. Element ::= Identifier ; |
| package com.whitemagicsoftware.rxm; | ||
| +import java.io.StringReader; | ||
| + | ||
| import java_cup.runtime.*; | ||
| import com.whitemagicsoftware.rxm.*; | ||
| import com.whitemagicsoftware.rxm.Absyn.*; | ||
| /** | ||
| * Parses the expression into an abstract tree. | ||
| */ | ||
| public class Parser { | ||
| - public Parser( String rxm ) { | ||
| - Yylex lexer = new Yylex( rxm ); | ||
| - } | ||
| -} | ||
| + public Parser( String rxm ) throws Exception { | ||
| + Yylex lexer = new Yylex( new StringReader( rxm ) ); | ||
| -Yylex l = null; | ||
| - parser p; | ||
| - try | ||
| - { | ||
| - if (args.length == 0) l = new Yylex(System.in); | ||
| - else l = new Yylex(new FileReader(args[0])); | ||
| - } | ||
| - catch(FileNotFoundException e) | ||
| - { | ||
| - System.err.println("Error: File not found: " + args[0]); | ||
| - System.exit(1); | ||
| - } | ||
| - p = new parser(l); | ||
| - /* The default parser is the first-defined entry point. */ | ||
| - /* You may want to change this. Other options are: */ | ||
| - /* */ | ||
| - try | ||
| - { | ||
| + parser p = new parser( lexer ); | ||
| + | ||
| + try { | ||
| com.whitemagicsoftware.rxm.Absyn.Query parse_tree = p.pQuery(); | ||
| System.out.println(); | ||
| System.out.println(PrettyPrinter.print(parse_tree)); | ||
| } | ||
| - catch(Throwable e) | ||
| - { | ||
| - System.err.println("At line " + String.valueOf(l.line_num()) + ", near \"" + l.buff() + "\" :"); | ||
| + catch(Throwable e) { | ||
| + System.err.println("At line " + String.valueOf(lexer.line_num()) + ", near \"" + lexer.buff() + "\" :"); | ||
| System.err.println(" " + e.getMessage()); | ||
| - System.exit(1); | ||
| } | ||
| + } | ||
| +} | ||
| Delta | 31 lines added, 47 lines removed, 16-line decrease |
|---|