Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 469 lines (411 sloc) 15.996 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
// 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}
Something went wrong with that request. Please try again.