Permalink
Browse files

initial commit

  • Loading branch information...
1 parent 36feeaf commit c8a6569686b94a8db6c773f19033313f8961b209 @jbclements committed Mar 23, 2013
Showing with 1,509 additions and 0 deletions.
  1. +7 −0 Makefile
  2. +131 −0 Rust.g4
  3. +868 −0 xidcont.g4
  4. +503 −0 xidstart.g4
View
@@ -0,0 +1,7 @@
+all : RustParser.class
+
+RustParser.class : RustParser.java
+ javac Rust*.java
+
+RustParser.java : Rust.g4 xidstart.g4 xidcont.g4
+ java -jar /usr/local/lib/antlr-4.0-complete.jar Rust.g4
View
131 Rust.g4
@@ -0,0 +1,131 @@
+// for now, this is a grammar for rust token-trees.
+// it's still missing numeric constants and all kinds of comments.
+grammar Rust;
+
+import "xidstart" , "xidcont";
+
+prog : tt* ;
+tt : nondelim | delimited ;
+delimited : LPAREN tt* RPAREN
+ | LBRACKET tt* RBRACKET
+ | LBRACE tt* RBRACE ;
+nondelim :
+ // Expression-operator symbols.
+ EQ
+ | LT
+ | LE
+ | EQEQ
+ | NE
+ | GE
+ | GT
+ | ANDAND
+ | OROR
+ | NOT
+ | TILDE
+ | BINOP
+ | BINOPEQ
+ // Structural symbols
+ | AT
+ | DOT
+ | DOTDOT
+ | COMMA
+ | SEMI
+ | COLON
+ | MOD_SEP
+ | RARROW
+ | LARROW
+ | DARROW
+ | FAT_ARROW
+ | POUND
+ | DOLLAR
+ // Literals
+ | LIT_INT
+ | LIT_UINT
+ | LIT_INT_UNSUFFIXED
+ | LIT_FLOAT
+ | LIT_FLOAT_UNSUFFIXED
+ | LIT_STR
+ // Name components
+ | IDENT
+ | UNDERSCORE
+ | LIFETIME
+ // For interpolation
+ // | INTERPOLATED
+ | DOC_COMMENT
+ ;
+
+WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines
+
+EQ : '=' ;
+LE : '<=' ;
+LT : '<';
+/*
+LE,
+*/
+EQEQ : '==' ;
+NE : '!=' ;
+GE : '>=' ;
+GT : '>' ;
+ANDAND : '&&' ;
+OROR : '||' ;
+NOT : '!' ;
+TILDE : '~' ;
+BINOP : '<<' | '>>'
+ | [-&|+*/^%];
+/*
+BINOPEQ(binop),
+*/
+/* Structural symbols */
+AT : '@' ;
+DOT : '.' ;
+DOTDOT : '..' ;
+COMMA : ',' ;
+SEMI : ';' ;
+COLON : ':' ;
+MOD_SEP : '::' ;
+RARROW : '->' ;
+LARROW : '<-' ;
+DARROW : '<->' ;
+FAT_ARROW : '=>' ;
+LPAREN : '(' ;
+RPAREN : ')' ;
+LBRACKET : '[' ;
+RBRACKET : ']' ;
+LBRACE : '{' ;
+RBRACE : '}' ;
+POUND : '#' ;
+DOLLAR : '$' ;
+
+LIT_INT : '\'\\' ESCAPEDCHAR '\'' | '\'' . '\'' ;
+/*
+
+// Literals
+LIT_INT(i64, ast::int_ty),
+LIT_UINT(u64, ast::uint_ty),
+LIT_INT_UNSUFFIXED(i64),
+LIT_FLOAT(ast::ident, ast::float_ty),
+LIT_FLOAT_UNSUFFIXED(ast::ident),
+*/
+
+LIT_STR : '\"' STRCHAR * '\"' ;
+IDENT : IDSTART IDCONT * ;
+UNDERSCORE : '_' ;
+
+// there's potential ambiguity with char constants,
+// but I think that the greedy read will do the "right
+// thing"
+LIFETIME : '\'' IDENT ;
+// DOC_COMMENT(ast::ident),
+
+HEX : [0-9a-fA-F] ;
+
+ESCAPEDCHAR : 'n' | 'r' | 't' | '\\' | '\'' | '\"'
+ | 'x' HEX HEX | 'u' HEX HEX HEX HEX
+ | 'U' HEX HEX HEX HEX HEX HEX HEX HEX
+ ;
+
+STRCHAR : ~[\\\"] | '\\' STRESCAPE ;
+STRESCAPE : '\n' | ESCAPEDCHAR ;
+
+IDSTART : [_a-zA-Z] | XIDSTART ;
+IDCONT : [_a-zA-Z0-9] | XIDCONT ;
Oops, something went wrong.

0 comments on commit c8a6569

Please sign in to comment.