From 2cf0a658d189907f995d6c758a5f09218df40034 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Jan 03 2022 08:56:36 +0000 Subject: Simplify the grammar a bit --- diff --git a/README.md b/README.md index aeb713e..f653c6a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This script does **not** check source files and does not check whether the licen Content: * `fedora-approved-licenses.txt` - contains list of licenses from [Fedora Licensing:Main](https://fedoraproject.org/wiki/Licensing:Main#Software_License_List). This is manually synced with the wiki. The file can contain empty lines and comments. - * `grammar.lark` - this file contains BNF grammar for [Lark](https://lark-parser.readthedocs.io/en/latest/). It miss one line: `license_item: "MIT"|"GPLv1"|..."`. This line is added there dynamically by `create-grammar.py`. + * `grammar.lark` - this file contains BNF grammar for [Lark](https://lark-parser.readthedocs.io/en/latest/). It miss one line: `good_license: "MIT"|"GPLv1"|..."`. This line is added there dynamically by `create-grammar.py`. * `create-grammar.py` - read `grammar.lark` and accepts filename as argument (usually `approved-licenses.txt`) and prints complete grammar. ## Run from checkout diff --git a/create-grammar.py b/create-grammar.py index e3abf87..aa19e76 100755 --- a/create-grammar.py +++ b/create-grammar.py @@ -18,6 +18,6 @@ with open(opts.licenses) as f: line = line.strip() ITEMS['"{}"'.format(line)] = 1 -grammar += "license_item: {0}".format('|'.join(ITEMS.keys())) +grammar += "license_good: {0}".format('|'.join(ITEMS.keys())) print(grammar) diff --git a/grammar.lark b/grammar.lark index a6bb76a..ecd267d 100644 --- a/grammar.lark +++ b/grammar.lark @@ -1,6 +1,6 @@ start: license -license: license_item | left_parenthesis license right_parenthesis | license operator license | license "or" bad_license | bad_license "or" license +license: left_parenthesis license right_parenthesis | license operator license | license_good | license_bad left_parenthesis: "(" right_parenthesis: ")" @@ -12,6 +12,6 @@ operator: "or"|"and" // here we can add bad licenses // it is fine to have them because they are "eaten" by "or" operator // FIXME general string is greedy, can we do it more generally? -bad_license: "Bad License" +license_bad: "Bad License" // license_item is generated and appended to this grammar by create-grammar.py