Appearance
| 1 | namespace Syntax.Parsers.Definitions is | |
| 2 | use Collections.MutableMap | |
| 3 | ||
| 4 | use Syntax.Parsers.Expressions.PRECEDENCE | |
| 5 | ||
| 6 | use Source | |
| 7 | ||
| 8 | use Logging | |
| 9 | ||
| 10 | class PRAGMA( | |
| 11 | pragma_parser: Parser[Trees.Pragmas.PRAGMA], | |
| 12 | definition_parser: Parser[Trees.Definitions.Definition], | |
| 13 | precedence_map: MutableMap[string,PRECEDENCE], | |
| 14 | precedence_helper: PRAGMA_PRECEDENCE | |
| 15 | ): Base[Trees.Definitions.PRAGMA] is | |
| 16 | super() | |
| 17 | ||
| 18 | parse(context: CONTEXT) -> Trees.Definitions.PRAGMA? is | |
| 19 | let pragma = pragma_parser.parse(context) | |
| 20 | ||
| 21 | if !pragma? \/ pragma.is_poisoned then | |
| 22 | return null | |
| 23 | fi | |
| 24 | ||
| 25 | let operator_name: string mut = "" | |
| 26 | let precedence_to_restore: PRECEDENCE mut = _ | |
| 27 | let had_previous mut = false | |
| 28 | let applied mut = false | |
| 29 | ||
| 30 | if pragma.is_name_equal_to("precedence") then | |
| 31 | applied = precedence_helper.apply(context, pragma, precedence_map, operator_name ref, precedence_to_restore ref, had_previous ref) | |
| 32 | fi | |
| 33 | ||
| 34 | let definition = definition_parser.parse(context) | |
| 35 | ||
| 36 | if applied then | |
| 37 | if had_previous then | |
| 38 | precedence_map[operator_name] = precedence_to_restore | |
| 39 | else | |
| 40 | precedence_map.remove(operator_name) | |
| 41 | fi | |
| 42 | fi | |
| 43 | ||
| 44 | if definition? /\ !definition.is_poisoned then | |
| 45 | return Trees.Definitions.PRAGMA(pragma.location::definition.location, pragma, definition) | |
| 46 | fi | |
| 47 | ||
| 48 | return null | |
| 49 | si | |
| 50 | si | |
| 51 | si |