Last active
July 26, 2020 16:05
-
-
Save omry/a76e9c4cd076bf10804d8287814883ef to your computer and use it in GitHub Desktop.
Hydra-interpolations-grammar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved | |
// Regenerate parser by running 'python setup.py antlr' at project root. | |
// If you make changes here be sure to update the documentation (and update the grammar in command_line_syntax.md) | |
grammar Override; | |
single_override : override EOF; | |
overrides_file : override ('\n' override)*; | |
override: ( | |
key '=' value? // key=value | |
| '~' key ('=' value?)? // ~key | ~key=value | |
| '+' key '=' value? // +key= | +key=value | |
); | |
key : | |
packageOrGroup // key | |
| packageOrGroup '@' package (':' package)? // group@pkg | group@pkg1:pkg2 | |
| packageOrGroup '@:' package // group@:pkg2 | |
; | |
packageOrGroup: package | ID ('/' ID)+; // db, hydra/launcher | |
package: (ID | DOT_PATH); // db, hydra.launcher | |
value: element | choiceSweep; | |
element: | |
primitive | |
| listValue | |
| dictValue | |
; | |
choiceSweep: element (',' element)+; // value1,value2,value3 | |
primitive: | |
WS? (QUOTED_VALUE | // 'hello world', "hello world" | |
( ID // foo_10 | |
| NULL // null, NULL | |
| INT // 0, 10, -20, 1_000_000 | |
| FLOAT // 3.14, -20.0, 1e-1, -10e3 | |
| BOOL // true, TrUe, false, False | |
| DOT_PATH // foo.bar | |
| interpolation // ${foo.bar}, ${env:USER,me} | |
| '/' | ':' | '-' | '\\' | |
| '+' | '.' | '$' | |
)+ | |
) | |
WS?; | |
listValue: '[' (element(',' element)*)? ']'; // [], [1,2,3], [a,b,[1,2]] | |
dictValue: '{' // {}, {a:10,b:20} | |
(id_ws ':' element (',' id_ws ':' element)*)? | |
'}'; | |
interpolation: | |
'${' primitive '}' // simple | |
| '${' ID ':' element (',' element)* '}'; // custom resolver | |
id_ws: WS? ID WS?; | |
// Types | |
fragment DIGIT: [0-9_]; | |
fragment NZ_DIGIT: [1-9]; | |
fragment INT_PART: DIGIT+; | |
fragment FRACTION: '.' DIGIT+; | |
fragment POINT_FLOAT: INT_PART? FRACTION | INT_PART '.'; | |
fragment EXPONENT: [eE] [+-]? DIGIT+; | |
fragment EXPONENT_FLOAT: ( INT_PART | POINT_FLOAT) EXPONENT; | |
FLOAT: [-]?(POINT_FLOAT | EXPONENT_FLOAT | [Ii][Nn][Ff] | [Nn][Aa][Nn]); | |
INT: [-]? ('0' | (NZ_DIGIT DIGIT*)); | |
BOOL: | |
[Tt][Rr][Uu][Ee] // TRUE | |
| [Ff][Aa][Ll][Ss][Ee]; // FALSE | |
NULL: [Nn][Uu][Ll][Ll]; | |
fragment CHAR: [a-zA-Z]; | |
ID : (CHAR|'_') (CHAR|DIGIT|'_')*; | |
DOT_PATH: ID ('.' ID)+; | |
WS: (' ' | '\t')+; | |
QUOTED_VALUE: | |
'\'' ('\\\''|.)*? '\'' // Single quoted string. can contain escaped single quote : /' | |
| '"' ('\\"'|.)*? '"' ; // Double quoted string. can contain escaped double quote : /" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment