Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
469 lines (411 sloc) 15.996 kb
// http://erlang.org/pipermail/erlang-questions/2011-November/062390.html
// http://erlang.org/pipermail/erlang-questions/attachments/20111114/ba08f89c/attachment.obj
// https://github.com/erlang/otp/blob/master/lib/stdlib/src/erl_parse.yrl
//
// Erlang bnf grammar
//
// Rootsymbol form
{
parserClass="org.intellij.erlang.parser.ErlangParser"
stubParserClass="org.intellij.erlang.parser.ErlangParserUtil"
implements="org.intellij.erlang.psi.ErlangCompositeElement"
extends="org.intellij.erlang.psi.impl.ErlangCompositeElementImpl"
elementTypeHolderClass="org.intellij.erlang.ErlangTypes"
elementTypePrefix="ERL_"
elementTypeClass="org.intellij.erlang.psi.ErlangCompositeElementType"
tokenTypeClass="org.intellij.erlang.psi.ErlangTokenType"
psiClassPrefix="Erlang"
psiImplClassSuffix="Impl"
psiPackage="org.intellij.erlang.psi"
psiImplPackage="org.intellij.erlang.psi.impl"
psiImplUtilClass="org.intellij.erlang.psi.impl.ErlangPsiImplUtil"
// operators
OP_PLUS = "+"
OP_MINUS = "-"
OP_AR_MUL = "*"
OP_AR_DIV = "/"
OP_DIV = "div"
OP_REM = "rem"
OP_OR = "or"
OP_XOR = "xor"
OP_BOR = "bor"
OP_BXOR = "bxor"
OP_BSL = "bsl"
OP_BSR = "bsr"
OP_AND = "and"
OP_BAND = "band"
OP_EQ_EQ = "=="
OP_DIV_EQ = "/="
OP_EQ_COL_EQ = "=:="
OP_EQ_DIV_EQ = "=/="
OP_LT = "<"
OP_EQ_LT = "=<"
OP_GT = ">"
OP_GT_EQ = ">="
OP_LT_EQ = "<="
OP_NOT = "not"
OP_BNOT = "bnot"
OP_PLUS_PLUS = "++"
OP_MINUS_MINUS = "--"
OP_EQ = "="
OP_EXL = "!"
OP_LT_MINUS = "<-"
OP_ANDALSO = "andalso"
OP_ORELSE = "orelse"
BIN_START = "<<"
BIN_END = ">>"
PAR_LEFT = "("
PAR_RIGHT = ")"
CURLY_LEFT = "{"
CURLY_RIGHT = "}"
BRACKET_LEFT = "["
BRACKET_RIGHT = "]"
DOT = "."
DOT_DOT = ".."
DOT_DOT_DOT = "..."
COLON = ":"
COLON_COLON = "::"
OR_OR = "||"
OR = "|"
SEMI = ";"
COMMA = ","
ARROW = "->"
RADIX = "#"
QMARK = "?"
UNI_PATTERN = "_"
AFTER = "after"
COND = "cond"
LET = "let"
WHEN = "when"
BEGIN = "begin"
END = "end"
OF = "of"
CASE = "case"
FUN = "fun"
QUERY = "query"
CATCH = "catch"
IF = "if"
RECEIVE = "receive"
TRY = "try"
INT = "integer"
FLOAT = "float"
CHAR = "char"
extends("assignment_expression|send_expression|orelse_expression|andalso_expression|comp_op_expression|list_op_expression|additive_expression|multiplicative_expression")=fake_binary_expression
extends(".*_(expression|comprehension|literal|atomic|q_atom|q_var)")=expression
name(".*_(expression|comprehension|literal|atomic)")=expression
name(".*attribute")=attribute
name(".*type|.*_t")=type
pin(".*(clauses|exprs|list)(?:_\d.*)?")=1
implements("record_definition|function|q_var|module|macros_definition|type_definition|typed_expr")="org.intellij.erlang.psi.ErlangNamedElement"
extends("record_definition|function|q_var|module|macros_definition|type_definition|typed_expr")="org.intellij.erlang.psi.impl.ErlangNamedElementImpl"
}
forms ::= form_with_period *
private form_with_period ::= form period {recoverUntil=form_recover pin=1}
private left period ::= '.'
private form_recover ::= !('+' | '-' | '<<' | '?' | '[' | '_' | '{' | atom | bnot | char | float | integer | not | string | var)
private form ::=
(is_app_config config_expression)
| function
| rule
| record_definition
| include
| macros_definition
| type_definition
| attribute
| macros_call // macros support
private is_app_config ::= &<<isApplicationLanguage>>
q_atom ::= macros_arg | macros | atom
q_var ::= '_' | var {
methods = [getReference processDeclarations getName setName getNameIdentifier getUseScope]
}
macros_arg ::= '?''?' macros_name
macros ::= '?' macros_name {
pin=1
methods = [getReference]
}
macros_name ::= atom | var
private tuple_recoverer ::= !('}'|',')
record_definition ::= '-' 'record' '(' q_atom ',' typed_record_fields ')' {
pin=2
methods = [getName setName getNameIdentifier getTextOffset]
}
macros_definition ::= '-' 'define' '(' macros_name argument_definition_list? ',' macros_body ')' {
pin = 2
methods = [getName setName getNameIdentifier getTextOffset]
}
macros_body ::= expression ((',' | ';' | '->') expression)* {pin(".*")=1}
include ::= '-' ('include' | 'include_lib') '(' include_string ')' {pin=2}
include_string ::= string {methods = [getReference]}
attribute ::= '-' (
module
| export
| export_type_attribute
| specification
| callback_spec
| behaviour
| atom_attribute
) {pin=1}
callback_spec ::= 'callback' type_spec {pin=1}
specification ::= 'spec' type_spec {
pin=1
methods = [getSignature]
}
export ::= 'export' '(' export_functions ')' {pin=1}
export_type_attribute ::= 'export_type' '(' export_types ')' {pin=1}
module ::= 'module' '(' q_atom (',' argument_definition)? ')' {
pin=1
methods = [getName setName getNameIdentifier getTextOffset processDeclarations]
}
behaviour ::= 'behaviour' '(' module_ref ')' {
pin=1
methods = [getName]
}
type_definition ::= '-' ('type'|'opaque') (type_body | '(' type_body ')') {
pin = 2
methods = [getName setName getNameIdentifier getTextOffset]
}
private type_body ::= q_atom argument_definition_list '::' top_type {pin=1}
private type_ref_with_module ::= [module_ref ':'] type_ref
type_ref ::= q_atom {
methods = [getReference]
}
atom_attribute ::= q_atom [('(' typed_attr_val ')') | typed_attr_val | attr_val]
export_functions ::= '[' export_function_list? ']' {pin=1}
private export_function_list ::= export_function (',' export_function)*
export_function ::= q_atom '/' integer {
pin = 1
methods = [getReference]
}
export_types ::= '[' export_type_list? ']' {pin=1}
private export_type_list ::= export_type (',' export_type)*
export_type ::= q_atom '/' integer {
pin = 1
methods = [getReference]
}
private type_spec ::= fun_type_sigs_braces | fun_type_sigs
fun_type_sigs_braces ::= '(' fun_type_sigs ')' {pin=1}
fun_type_sigs ::= spec_fun ['::'] type_sigs_list {
pin = 1
methods=[getReference]
}
private type_sigs_list ::= type_sig (';' type_sig)*
spec_fun ::= q_atom ['/' integer | ':' q_atom ['/' integer]]
typed_attr_val ::= expression ((',' typed_record_fields) | ('::' top_type))
typed_record_fields ::= '{' typed_exprs? '}' {pin=1}
private typed_exprs ::= typed_expr_or_macros (',' typed_expr_or_macros)* // todo: hack #145
private typed_expr_or_macros ::= generic_function_call_expression | typed_expr
typed_expr ::= q_atom ['=' expression] ['::' top_type] {
pin(".*")=1
methods=[getName setName getNameIdentifier getTextOffset]
}
type_sig ::= fun_type [type_sig_guard]
type_sig_guard ::= when type_guard_list
private type_guard_list ::= type_guard (',' type_guard)*
type_guard ::= (q_atom '(' top_type_list ')') | top_type
private top_type_list ::= top_type (',' top_type)*
top_type ::= [q_var '::'] top_type_100_t
top_type_100_t ::= type ['|' top_type_100_t] {pin(".*")=1}
type ::=
'(' top_type ')'
| int_type ['..' int_type]
| fun '(' fun_type_100_t? ')'
| type_ref_with_module ['(' top_type_list? ')']
| binary_type
| q_var ['::' top_type]
| '[' [top_type (',' '...')?] ']'
| '{' top_type_list? '}'
| '#' record_ref '{' field_type_list? '}' {pin(".*") = 1}
int_type ::= '-'? (integer | macros)
fun_type_100_t ::= '(' ('...' | top_type_list?) ')' top_type_clause {pin(".*")=1}
top_type_clause ::= '->' top_type {pin=1}
fun_type ::= fun_type_arguments top_type_clause {pin=1}
fun_type_arguments ::= '(' top_type_list? ')' {pin=1}
private field_type_list ::= field_type (',' field_type)*
field_type ::= q_atom '::' top_type {
pin = 1
methods = [getReference]
}
binary_type ::= '<<' [bin_base_type | bin_unit_type | bin_base_type_list] '>>' {pin=1}
private bin_base_type_list ::= bin_base_type ',' bin_unit_type
bin_base_type ::= q_var ':' integer
bin_unit_type ::= q_var ':' q_var '*' integer
attr_val ::= ('(' exprs ')') | exprs {name="attribute value"}
function ::= function_clause (';' function_clause)* {
pin(".*") = 1
methods = [
atom_name = "function_clause[0]/q_atom"
getName
setName
getArity
getNameIdentifier
getPresentation
getIcon
]
}
function_clause ::= q_atom argument_definition_list clause_guard? clause_body
argument_definition_list ::= '(' argument_definition? (',' argument_definition)* ')'
clause_guard ::= when guard {pin=1}
clause_body ::= '->' exprs {pin=1}
config_expression ::=
config_tuple_expression
| config_list_expression
| config_bin_list_expression
| config_qualified_or_call_expression
| (prefix_op? atomic)
| q_var
private config_qualified_or_call_expression ::= q_atom left_accessors?
private left_accessors ::= config_call_expression | qualified_expression+
left config_call_expression ::= config_argument_list {pin=0}
config_argument_list ::= '(' config_exprs? ')' {elementType=argument_list}
config_list_expression ::= '[' config_exprs? ']' {elementType=list_expression}
config_bin_list_expression ::= '<<' config_exprs? '>>' {elementType=binary_expression}
config_tuple_expression ::= '{' config_exprs? '}' {elementType=tuple_expression}
private config_exprs ::= config_expression (',' config_expression)*
expression ::=
catch_expression
| assignment_expression
| send_expression
| orelse_expression
| andalso_expression
| comp_op_expression
| list_op_expression
| additive_expression
| multiplicative_expression
| prefix_expression
| colon_qualified_expression
| max_group
| max_expression
| parenthesized_expression
prefix_expression ::= prefix_op expression
catch_expression ::= catch expression {pin=1}
assignment_expression ::= expression '=' expression { rightAssociative=true }
send_expression ::= expression '!' expression { rightAssociative=true }
orelse_expression ::= expression orelse expression
andalso_expression ::= expression andalso expression
comp_op_expression ::= expression comp_op expression
list_op_expression ::= expression list_op expression
multiplicative_expression ::= expression mult_op &(!(atom (',' | '>>'))) expression // for #141
additive_expression ::= expression add_op expression
parenthesized_expression ::= '(' expression ')'
private max_group ::=
function_call_expression
| global_function_call_expression
| generic_function_call_expression
| anonymous_call_expression
| record_expression
| record2_expression
| qualified_expression
colon_qualified_expression ::= expression ':' expression
qualified_expression ::= q_atom '.' q_atom&(!('('))
record2_expression ::= record_tail {elementType=record_expression}
max_expression ::=
atomic
| q_var
| tuple_expression
| list_atom_with_arity_expression
| list_expression
| case_expression
| if_expression
| binary_comprehension
| list_comprehension
| receive_expression
| fun_expression
| try_expression
| query_expression
| binary_expression
| begin_end_expression
list_atom_with_arity_expression ::= '[' atom_with_arity_expression (',' atom_with_arity_expression)* ']' {elementType="list_expression" pin=0}
atom_with_arity_expression ::= q_atom '/' integer {elementType="expression" pin=0}
begin_end_expression ::= begin begin_end_body end {pin=1}
begin_end_body ::= exprs {name="expression"}
list_expression ::= '[' (']' | (expression tail)) {pin=0} // todo: rewrite without tail
private tail ::= ']' | ('|' expression ']') | (',' expression tail)
binary_expression ::= '<<' bin_element_list? '>>' {pin=1}
private bin_element_list ::= bin_element (',' bin_element)*
bin_element ::= prefix_op? expression (':' expression)? opt_bit_type_list? {name="binary element"}
opt_bit_type_list ::= '/' bit_type_list {pin=1}
private bit_type_list ::= bit_type ('-' bit_type)*
bit_type ::= q_atom [':' integer]
list_comprehension ::= '[' expression '||' lc_exprs ']' {
pin=3
methods=[processDeclarations]
}
lc_exprs ::= lc_expression (',' lc_expression)*
lc_expression ::= argument_definition [('<-' | '<=') expression] {pin(".*")=1}
binary_comprehension ::= '<<' binary_expression '||' lc_exprs '>>' {
pin=3
elementType="list_comprehension"
}
tuple_expression ::= '{' exprs? '}' {pin=1}
record_expression ::= expression record_tail {
pin=2
methods = [getReference]
}
private record_tail ::= '#' record_ref (record_field_ref | record_tuple) {pin=1}
record_field_ref ::= '.' q_atom {pin=1 elementType="record_field"}
record_ref ::= q_atom {methods = [getReference]}
record_tuple ::= '{' record_fields? '}' {pin=1}
record_fields ::= record_field (',' record_field)*
record_field ::= (q_atom | '_') '=' (qualified_atom_expression | expression) {
pin=1
methods = [
getReference
field_name_atom = "q_atom[0]"
]
recoverUntil="tuple_recoverer"
}
private qualified_atom_expression ::= q_atom '.' q_atom {pin=0}
module_ref ::= q_atom {
methods = [getReference]
}
global_function_call_expression ::= module_ref_or_dot_atom ':' function_call_expression {pin=0}
private module_ref_or_dot_atom ::= '.' q_atom | module_ref
function_call_expression ::= q_atom argument_list {
pin=0
methods = [getReference getNameIdentifier getTextOffset]
}
macros_call ::= generic_function_call_expression
generic_function_call_expression ::= (q_atom_or_var ':')? (q_atom_or_var | macros) argument_list {pin=0}
private q_atom_or_var ::= q_atom | q_var
anonymous_call_expression ::= expression argument_list
private expr_with_guard ::= expression clause_guard? {pin=1}
private call_exprs ::= expr_with_guard (',' expr_with_guard)*
if_expression ::= if if_clauses end {pin=1}
if_clauses ::= if_clause (';' if_clause)*
if_clause ::= guard clause_body {pin=1}
case_expression ::= case expression of cr_clauses end {pin=1}
cr_clauses ::= cr_clause (';' cr_clause)*
cr_clause ::= argument_definition clause_guard? clause_body {pin=1}
argument_definition ::= expression
receive_expression ::= receive ((cr_clauses end) | (cr_clauses? after expression clause_body end)) {pin=1}
fun_expression ::= fun ((fun_clauses end) | ([(module_ref | q_var) ':'] (function_with_arity|function_with_arity_variables))) {pin=1}
function_with_arity ::= q_atom '/' integer {
pin= 1
methods = [getReference]
}
function_with_arity_variables ::= q_var '/' (integer|q_var) {pin=1}
fun_clauses ::= fun_clause (';' fun_clause)*
fun_clause ::= argument_definition_list clause_guard? clause_body {pin=1}
try_expression ::= try try_expressions_clause (of cr_clauses)? try_catch {pin=1}
try_catch ::= (catch try_clauses [after try_expressions_clause] end) | (after try_expressions_clause end) {pin(".*")="catch|after"}
try_expressions_clause ::= exprs
try_clauses ::= try_clause (';' try_clause)*
try_clause ::= [argument_definition ':'] argument_definition clause_guard? clause_body {pin=2}
query_expression ::= query list_comprehension end {pin=1}
argument_list ::= '(' call_exprs? ')'
fake fake_binary_expression ::= expression + {
methods = [
left="expression[0]"
right="expression[1]"]
}
private exprs ::= expression (',' expression)*
guard ::= exprs (';' exprs)* {pin(".*")=1}
private atomic ::= char | integer | float | q_atom | string+
private prefix_op ::= '+' | '-' | bnot | not
private mult_op ::= '/' |'*' | div | rem | band | and
private add_op ::= '+' |'-' | bor | bxor | bsl | bsr | or | xor
private list_op ::= '++' | '--'
private comp_op ::= '==' | '/=' |'=<' |'<' |'>=' |'>' |'=:=' |'=/='
rule ::= rule_clause (';' rule_clause)* {pin(".*")=1}
rule_clause ::= q_atom argument_list clause_guard? rule_body
rule_body ::= ':-' lc_exprs {pin=1}
Jump to Line
Something went wrong with that request. Please try again.