Grammar feedback request : Hydra override DSL

68 views
Skip to first unread message

Omry Yadan

unread,
Jul 8, 2020, 9:55:13 PM7/8/20
to antlr-discussion
I would love to get some feedback and suggestions for this grammar.
There are a few things I don't like in it, but I would like to hear what the experts has to say first.

A few example inputs (off the top of my head, did not run through but all should work):

# changing a value
key=value

# addition
+key=value

# deletion
~key=value
~key

# value can be an int, a float, a bool or null:
key=10
key=3.14
key=false
key=null

# interpolation is a special value:

# interpolation
key=${abc}

# custom interpolation:
key=${func:param1,param2}

# value can be a list:
key=[1,2,3]

# or a choice sweep
key=1,2,3 

# or just a quoted string:
key='1,2,3'
key='[1,2,3]'

# value can be a dict:
key={a:10,b:20}
# lists and dicts can be nested
key=[{a:10}]
key={a:[1,2,3]}

# key has some semantics too:
group@pkg=value
group@src_pkg:dst_pkg=value

constants are case insensitive (true, false, null, inf, nan)

// Regenerate parser by running 'python setup.py antlr' at project root.
grammar Override;

override: (
key EQ value? // key=value
| TILDE key (EQ value?)? // ~key | ~key=value
| PLUS key EQ value? // +key= | +key=value
) EOF;

key :
packageOrGroup // key
| packageOrGroup AT package (COLON package)? // group@pkg | group@pkg1:pkg2
| packageOrGroup AT COLON package // group@:pkg2
;

value: element | choiceSweep;

choiceSweep: element (COMMA element)+;

package: (ID | DOT_PATH);

packageOrGroup: package | ID (SLASH ID)+;

element:
NULL
| QUOTED_VALUE
| primitive
| listValue
| dictValue
;

primitive: (
ID
| INT
| FLOAT
| BOOL
| BACKSLASH
| SLASH
| COLON
| DASH
| PLUS
| DOT
| ASTERISK
| DOLLAR
| DOT_PATH
| INTERPOLATION
)+;

dictValue: DOPEN (ID COLON element (COMMA ID COLON element)*)? DCLOSE;

listValue: LOPEN (element(COMMA element)*)? LCLOSE;

// Tokens
LOPEN: '[';
LCLOSE: ']';
DOPEN: '{';
DCLOSE: '}';
COMMA: ',';
COLON: ':';
DOLLAR: '$';
EQ: '=';
PLUS: '+';
DASH: '-';
TILDE: '~';
DOT: '.';
BACKSLASH: '\\';
SLASH: '/';
AT: '@';
ASTERISK : '*';

// Types
INT: [+-]?('0' | [1-9][0-9_]*);
// does not currently support scientific notation. can be added later
fragment NAN: [Nn][Aa][Nn];
fragment INF: [Ii][Nn][Ff];
FLOAT: ([+-]?([0-9_]+ '.' [0-9_]+ | INF)|NAN);

fragment TRUE: [Tt][Rr][Uu][Ee];
fragment FALSE: [Ff][Aa][Ll][Ss][Ee];
BOOL: TRUE|FALSE;

NULL: [Nn][Uu][Ll][Ll];

ID : [a-zA-Z0-9_]+;
DOT_PATH: ID (DOT ID)+;

WS: (' ' | '\t')+ -> channel(HIDDEN);

QUOTED_VALUE: '\'' .*? '\'' | '"' .*? '"' ;

INTERPOLATION:
DOLLAR DOPEN (
// interpolation
(ID | DOT_PATH)
// custom interpolation
| ID COLON (ID | QUOTED_VALUE) (COMMA (ID | QUOTED_VALUE))*
) DCLOSE;

Thanks.

edgar hoover

unread,
Aug 10, 2020, 9:05:22 AM8/10/20
to antlr-discussion
It's unclear to me what kind of feedback you are looking for.  Also a grammar is just the first of many steps to a solution, so what are you trying to solve?
I doubt I can help you (and I don't have the time) but FYI.

cheers

jan

Omry Yadan

unread,
Aug 10, 2020, 11:53:22 AM8/10/20
to antlr-di...@googlegroups.com

Thanks for answering.

Yeah, there isn't enough context there.
Hydra is a framework for configuring applications. one of the key features is that you can override anything in the config from the command line.
for example, if the app config is:

foo:
  bar: 10

You could override it at runtiem with foo.bar=20.
This grammar is parsing the command line for this.
This tutorial describes the basic features of Hydra: https://hydra.cc/docs/next/tutorials/basic/your_first_app/simple_cli

This grammar is now documented here :
https://hydra.cc/docs/next/advanced/command_line_syntax

This doc describes extension to the grammar, adding support for functions and type casts:
https://docs.google.com/document/d/1JDZGHKk4PrZHqsTTS6ao-DQOu2eVD4ULR6uAxVUR-WI/edit#

I understand that this is a lot to take in just to provide feedback.

--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/antlr-discussion/34d9c948-faf7-4cbb-9f5d-6e9244aeddb4o%40googlegroups.com.

Martin Mirchev

unread,
Sep 30, 2020, 11:02:54 AM9/30/20
to antlr-discussion
Hi, Grammar looks good. I think there  is nothing you can do except trying to compress the first two rules, but it is not needed.
Reply all
Reply to author
Forward
0 new messages