Merge branch 'bugfix/ldgen_allow_more_characters_sections_entries' into 'master'

ldgen: allow more characters in `sections` fragment `entries`

See merge request espressif/esp-idf!10956
This commit is contained in:
Angus Gratton
2020-10-28 14:40:43 +08:00
2 changed files with 61 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ from pyparsing import Optional
from pyparsing import originalTextFor from pyparsing import originalTextFor
from pyparsing import Forward from pyparsing import Forward
from pyparsing import indentedBlock from pyparsing import indentedBlock
from pyparsing import Combine
from collections import namedtuple from collections import namedtuple
import abc import abc
@@ -216,8 +217,14 @@ class Fragment():
class Sections(Fragment): class Sections(Fragment):
# Unless quoted, symbol names start with a letter, underscore, or point
# and may include any letters, underscores, digits, points, and hyphens.
GNU_LD_SYMBOLS = Word(alphas + "_.", alphanums + "._-")
entries_grammar = Combine(GNU_LD_SYMBOLS + Optional("+"))
grammars = { grammars = {
"entries": KeyGrammar(Word(alphanums + "+.").setResultsName("section"), 1, None, True) "entries": KeyGrammar(entries_grammar.setResultsName("section"), 1, None, True)
} }
""" """

View File

@@ -523,6 +523,59 @@ entries:
with self.assertRaises(ParseFatalException): with self.assertRaises(ParseFatalException):
FragmentFile(test_fragment, self.sdkconfig) FragmentFile(test_fragment, self.sdkconfig)
def test_entries_grammar(self):
test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
_valid1
valid2.
.valid3_-
""")
fragment_file = FragmentFile(test_fragment, self.sdkconfig)
self.assertEqual(fragment_file.fragments[0].entries,
{"_valid1", "valid2.", ".valid3_-"})
# invalid starting char
test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
1invalid
""")
with self.assertRaises(ParseException):
FragmentFile(test_fragment, self.sdkconfig)
test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
-invalid
""")
with self.assertRaises(ParseException):
FragmentFile(test_fragment, self.sdkconfig)
# + notation
test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
valid+
""")
fragment_file = FragmentFile(test_fragment, self.sdkconfig)
self.assertEqual(fragment_file.fragments[0].entries,
{"valid+"})
test_fragment = self.create_fragment_file(u"""
[sections:test]
entries:
inva+lid+
""")
with self.assertRaises(ParseFatalException):
FragmentFile(test_fragment, self.sdkconfig)
class SchemeTest(FragmentTest): class SchemeTest(FragmentTest):