Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/antlr/grammars-v4 into an…
Browse files Browse the repository at this point in the history
…tlr-plugin
  • Loading branch information
teverett committed Sep 5, 2016
2 parents 832a3c1 + 833d123 commit 57ce6ed
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 25 deletions.
18 changes: 11 additions & 7 deletions .gitignore
@@ -1,7 +1,11 @@
**/.DS_Store
/**/.project
/**/.classpath
/**/.settings/
/**/target

.fetch_time_cache
**/.DS_Store
/**/.project
/**/.classpath
/**/.settings/
/**/target

.fetch_time_cache

#IntelliJ Idea project files
.idea/
*.iml
36 changes: 18 additions & 18 deletions java/Java.g4
Expand Up @@ -89,7 +89,7 @@ variableModifier

classDeclaration
: 'class' Identifier typeParameters?
('extends' type)?
('extends' typeType)?
('implements' typeList)?
classBody
;
Expand All @@ -103,7 +103,7 @@ typeParameter
;

typeBound
: type ('&' type)*
: typeType ('&' typeType)*
;

enumDeclaration
Expand All @@ -128,7 +128,7 @@ interfaceDeclaration
;

typeList
: type (',' type)*
: typeType (',' typeType)*
;

classBody
Expand Down Expand Up @@ -163,7 +163,7 @@ memberDeclaration
for invalid return type after parsing.
*/
methodDeclaration
: (type|'void') Identifier formalParameters ('[' ']')*
: (typeType|'void') Identifier formalParameters ('[' ']')*
('throws' qualifiedNameList)?
( methodBody
| ';'
Expand All @@ -184,7 +184,7 @@ genericConstructorDeclaration
;

fieldDeclaration
: type variableDeclarators ';'
: typeType variableDeclarators ';'
;

interfaceBodyDeclaration
Expand All @@ -203,7 +203,7 @@ interfaceMemberDeclaration
;

constDeclaration
: type constantDeclarator (',' constantDeclarator)* ';'
: typeType constantDeclarator (',' constantDeclarator)* ';'
;

constantDeclarator
Expand All @@ -212,7 +212,7 @@ constantDeclarator

// see matching of [] comment in methodDeclaratorRest
interfaceMethodDeclaration
: (type|'void') Identifier formalParameters ('[' ']')*
: (typeType|'void') Identifier formalParameters ('[' ']')*
('throws' qualifiedNameList)?
';'
;
Expand Down Expand Up @@ -246,7 +246,7 @@ enumConstantName
: Identifier
;

type
typeType
: classOrInterfaceType ('[' ']')*
| primitiveType ('[' ']')*
;
Expand All @@ -271,8 +271,8 @@ typeArguments
;

typeArgument
: type
| '?' (('extends' | 'super') type)?
: typeType
| '?' (('extends' | 'super') typeType)?
;

qualifiedNameList
Expand All @@ -289,11 +289,11 @@ formalParameterList
;

formalParameter
: variableModifier* type variableDeclaratorId
: variableModifier* typeType variableDeclaratorId
;

lastFormalParameter
: variableModifier* type '...' variableDeclaratorId
: variableModifier* typeType '...' variableDeclaratorId
;

methodBody
Expand Down Expand Up @@ -357,7 +357,7 @@ annotationTypeElementDeclaration
;

annotationTypeElementRest
: type annotationMethodOrConstantRest ';'
: typeType annotationMethodOrConstantRest ';'
| classDeclaration ';'?
| interfaceDeclaration ';'?
| enumDeclaration ';'?
Expand Down Expand Up @@ -398,7 +398,7 @@ localVariableDeclarationStatement
;

localVariableDeclaration
: variableModifier* type variableDeclarators
: variableModifier* typeType variableDeclarators
;

statement
Expand Down Expand Up @@ -469,7 +469,7 @@ forInit
;

enhancedForControl
: variableModifier* type variableDeclaratorId ':' expression
: variableModifier* typeType variableDeclaratorId ':' expression
;

forUpdate
Expand Down Expand Up @@ -504,15 +504,15 @@ expression
| expression '[' expression ']'
| expression '(' expressionList? ')'
| 'new' creator
| '(' type ')' expression
| '(' typeType ')' expression
| expression ('++' | '--')
| ('+'|'-'|'++'|'--') expression
| ('~'|'!') expression
| expression ('*'|'/'|'%') expression
| expression ('+'|'-') expression
| expression ('<' '<' | '>' '>' '>' | '>' '>') expression
| expression ('<=' | '>=' | '>' | '<') expression
| expression 'instanceof' type
| expression 'instanceof' typeType
| expression ('==' | '!=') expression
| expression '&' expression
| expression '^' expression
Expand Down Expand Up @@ -543,7 +543,7 @@ primary
| 'super'
| literal
| Identifier
| type '.' 'class'
| typeType '.' 'class'
| 'void' '.' 'class'
| nonWildcardTypeArguments (explicitGenericInvocationSuffix | 'this' arguments)
;
Expand Down
11 changes: 11 additions & 0 deletions oncrpc/README.md
@@ -0,0 +1,11 @@
#ONCRPCv2 and XDR grammars

External Data Representation (XDR) is a data serialization format defined
by [RFC 4506](https://tools.ietf.org/html/rfc4506) (which obsoletes the
previous definition in [RFC 1832](https://tools.ietf.org/html/rfc1832)).

Open Network Computing Remote Procedure Call (ONCRPC) aka SunRPC is a
remote procedure call system that uses XDR for serialization. version 2
is defined by [RFC 5531](https://tools.ietf.org/html/rfc5531)

ONCRPC is the rpc mechanism that NFS (Network File System) is built on.
12 changes: 12 additions & 0 deletions oncrpc/examples/CalculatorService.x
@@ -0,0 +1,12 @@
struct CalculationResult {
hyper result;
unsigned hyper startMillis;
unsigned hyper finishMillis;
};

program CALCULATOR {
version CALCULATORVERS {
CalculationResult add(hyper, hyper) = 1;
hyper addSimple(hyper, hyper) = 2;
} = 1;
} = 117;
16 changes: 16 additions & 0 deletions oncrpc/oncrpcv2.g4
@@ -0,0 +1,16 @@
grammar oncrpcv2;
import xdr;

//oncrpcv2 additions on top of xdr (rfc 5531)
programDef: 'program' IDENTIFIER '{'
versionDef
versionDef*
'}' '=' constant ';';
versionDef: 'version' IDENTIFIER '{'
procedureDef
procedureDef*
'}' '=' constant ';';
procedureDef: procReturn IDENTIFIER '(' procFirstArg (',' typeSpecifier)* ')' '=' constant ';';
procReturn: 'void' | typeSpecifier;
procFirstArg: 'void' | typeSpecifier;
oncrpcv2Specification : (xdrSpecification | programDef)*; //this is the top level rule for oncrpcv2 (rfc 5531)
54 changes: 54 additions & 0 deletions oncrpc/pom.xml
@@ -0,0 +1,54 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>oncrpc</artifactId>
<packaging>jar</packaging>
<name>ONCRPC and XDR grammars</name>
<parent>
<groupId>com.antlr.grammarsv4</groupId>
<artifactId>grammarsv4</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr.version}</version>
<configuration>
<sourceDirectory>${basedir}</sourceDirectory>
<visitor>true</visitor>
<listener>true</listener>
</configuration>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4test-maven-plugin</artifactId>
<configuration>
<verbose>false</verbose>
<showTree>false</showTree>
<entryPoint>oncrpcv2Specification</entryPoint>
<grammarName>oncrpcv2</grammarName>
<packageName></packageName>
<exampleFiles>examples/</exampleFiles>
</configuration>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
57 changes: 57 additions & 0 deletions oncrpc/xdr.g4
@@ -0,0 +1,57 @@
grammar xdr;

// parser rules

declaration:
typeSpecifier IDENTIFIER
| typeSpecifier IDENTIFIER '[' value ']'
| typeSpecifier IDENTIFIER '<' value? '>'
| 'opaque' IDENTIFIER '[' value ']'
| 'opaque' IDENTIFIER '<' value? '>'
| 'string' IDENTIFIER '<' value? '>'
| typeSpecifier '*' IDENTIFIER
| 'void'
;
value: constant | IDENTIFIER;
constant: DECIMAL | HEXADECIMAL | OCTAL;
typeSpecifier:
'unsigned'? 'int'
| 'unsigned'? 'hyper'
| 'float'
| 'double'
| 'quadruple'
| 'bool'
| enumTypeSpec
| structTypeSpec
| unionTypeSpec
| IDENTIFIER
;
enumTypeSpec: 'enum' enumBody;
enumBody: '{' (IDENTIFIER '=' value) (',' IDENTIFIER '=' value)* '}';
structTypeSpec: 'struct' structBody;
structBody: '{' (declaration ';') (declaration ';')* '}';
unionTypeSpec: 'union' unionBody;
unionBody: 'switch' '(' declaration ')' '{'
caseSpec
caseSpec*
('default' ':' declaration ';')?
'}';
caseSpec: ('case' value ':') ('case' value ':')* declaration ';';
constantDef: 'const' IDENTIFIER '=' constant ';';
typeDef:
'typedef' declaration ';'
| 'enum' IDENTIFIER enumBody ';'
| 'struct' IDENTIFIER structBody ';'
| 'union' IDENTIFIER unionBody ';'
;
definition: typeDef | constantDef;
xdrSpecification: definition+; //this is the top level rule for xdr (rfc 4506)

// lexer rules

COMMENT : '/*' .*? '*/' -> skip;
OCTAL : '0' [1-7] ([0-7])*;
DECIMAL : ('-')? ([0-9])+;
HEXADECIMAL : '0x' ([a-fA-F0-9])+;
IDENTIFIER : [a-zA-Z] ([a-zA-Z0-9_])*;
WS : [ \t\r\n]+ -> skip;
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -67,6 +67,7 @@
<module>mumps</module>
<module>mysql</module>
<module>objc</module>
<module>oncrpc</module>
<module>pascal</module>
<module>pcre</module>
<module>pddl</module>
Expand Down

0 comments on commit 57ce6ed

Please sign in to comment.