From 49ddb152ecf83222633ea153ff5e11915e2a1036 Mon Sep 17 00:00:00 2001 From: Cassowary Date: Sat, 3 Feb 2024 10:13:14 -0800 Subject: [PATCH] Fix element labels to be in line with original design. --- python/heck/lexer.py | 6 ++++-- python/heck/parse.py | 2 ++ python/heck/parser.py | 19 +++++++++++++------ python/heck/parsetab.py | 36 +++++++++++++++++++----------------- 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/python/heck/lexer.py b/python/heck/lexer.py index ae23547..c02d8cc 100644 --- a/python/heck/lexer.py +++ b/python/heck/lexer.py @@ -10,7 +10,7 @@ from typing import List, Optional import string -tokens = ('ATOM', 'BASE10', 'BASE16', 'COMMENT', 'STRING', 'SECTION', 'ATTRIB', 'DEEP') +tokens = ('ATOM', 'BASE10', 'BASE16', 'COMMENT', 'STRING', 'SECTION', 'ATTRIB', 'DEEP', 'ELEMENT') # COMMENT ::= # .*$ # ATOM ::= [A-Za-z_][A-Za-z0-9_-]? @@ -37,7 +37,7 @@ t_DEEP = r'^(>)+' t_BASE16 = r'0x[0-9A-Fa-f]+' t_SECTION = r'^%%%\s' t_ATTRIB = '=' - +t_ELEMENT = r'[A-Za-z_.][A-Za-z0-9.!@\$%^&*()_+/\\-]*' def t_ATOM(token: lex.LexToken): r'[A-Za-z_$][A-Za-z0-9_.-]*' @@ -47,6 +47,8 @@ def t_ATOM(token: lex.LexToken): token.value = False return token + + def t_BASE10(token: lex.LexToken): r'(-)?[0-9]+(\.?[0-9]+)?([FLUIDCfluidc])?(\b|$)' # python numbers are Very Flexible so we ignore typespec diff --git a/python/heck/parse.py b/python/heck/parse.py index c7f776b..7cdbeb8 100644 --- a/python/heck/parse.py +++ b/python/heck/parse.py @@ -212,6 +212,8 @@ test > _val 2 > _val 3 valueless +_more.orless complexelement +.yooooo boolean True %%% markdown # Some cheeky markdown to confuse our processing. diff --git a/python/heck/parser.py b/python/heck/parser.py index 53c8f97..15e9fd4 100644 --- a/python/heck/parser.py +++ b/python/heck/parser.py @@ -17,6 +17,13 @@ def p_value(p): p[0] = ("value", p[1]) +def p_elm(p): + """ + elm : ATOM + | ELEMENT + """ + p[0] = p[1] + def p_attribute(p): """attribute : ATOM ATTRIB value""" # print(p[0], p[1]) @@ -37,8 +44,8 @@ def p_attributes(p): def p_section(p): """ - section : SECTION ATOM - | SECTION ATOM attributes + section : SECTION elm + | SECTION elm attributes """ if (len(p) == 3): p[0] = ("section", p[2]) @@ -59,10 +66,10 @@ def p_values(p): def p_element(p): """ - element : ATOM values - | ATOM values attributes - | ATOM attributes - | ATOM + element : elm values + | elm values attributes + | elm attributes + | elm """ # print(len(p)) if len(p) <= 2: diff --git a/python/heck/parsetab.py b/python/heck/parsetab.py index b826a56..32ad143 100644 --- a/python/heck/parsetab.py +++ b/python/heck/parsetab.py @@ -6,9 +6,9 @@ _tabversion = '3.10' _lr_method = 'LALR' -_lr_signature = 'statementATOM ATTRIB BASE10 BASE16 COMMENT DEEP SECTION STRING\n value : BASE16\n | BASE10\n | STRING\n | ATOM\n attribute : ATOM ATTRIB value\n attributes : attributes attribute\n attributes : attribute\n \n section : SECTION ATOM\n | SECTION ATOM attributes\n \n values : values value\n values : value\n \n element : ATOM values\n | ATOM values attributes\n | ATOM attributes\n | ATOM\n \n statement : element\n | DEEP element\n | section\n ' +_lr_signature = 'statementATOM ATTRIB BASE10 BASE16 COMMENT DEEP ELEMENT SECTION STRING\n value : BASE16\n | BASE10\n | STRING\n | ATOM\n \n elm : ATOM\n | ELEMENT\n attribute : ATOM ATTRIB value\n attributes : attributes attribute\n attributes : attribute\n \n section : SECTION elm\n | SECTION elm attributes\n \n values : values value\n values : value\n \n element : elm values\n | elm values attributes\n | elm attributes\n | elm\n \n statement : element\n | DEEP element\n | section\n ' -_lr_action_items = {'DEEP':([0,],[3,]),'ATOM':([0,3,5,6,8,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,],[5,5,8,16,-4,8,20,-11,-7,-1,-2,-3,20,23,20,-10,-6,20,-4,-5,]),'SECTION':([0,],[6,]),'$end':([1,2,4,5,7,8,9,10,11,12,13,14,15,16,18,19,21,22,23,24,],[0,-16,-18,-15,-17,-4,-12,-14,-11,-7,-1,-2,-3,-8,-13,-10,-6,-9,-4,-5,]),'BASE16':([5,8,9,11,13,14,15,17,19,],[13,-4,13,-11,-1,-2,-3,13,-10,]),'BASE10':([5,8,9,11,13,14,15,17,19,],[14,-4,14,-11,-1,-2,-3,14,-10,]),'STRING':([5,8,9,11,13,14,15,17,19,],[15,-4,15,-11,-1,-2,-3,15,-10,]),'ATTRIB':([8,20,],[17,17,]),} +_lr_action_items = {'DEEP':([0,],[3,]),'SECTION':([0,],[6,]),'ATOM':([0,3,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,23,24,25,26,],[7,7,17,7,-5,-6,17,22,-13,-9,-1,-2,-3,-4,22,22,-12,-8,25,22,-4,-7,]),'ELEMENT':([0,3,6,],[8,8,8,]),'$end':([1,2,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,24,25,26,],[0,-18,-20,-17,-5,-6,-19,-14,-16,-13,-9,-1,-2,-3,-4,-10,-15,-12,-8,-11,-4,-7,]),'BASE16':([5,7,8,10,12,14,15,16,17,20,23,],[14,-5,-6,14,-13,-1,-2,-3,-4,-12,14,]),'BASE10':([5,7,8,10,12,14,15,16,17,20,23,],[15,-5,-6,15,-13,-1,-2,-3,-4,-12,15,]),'STRING':([5,7,8,10,12,14,15,16,17,20,23,],[16,-5,-6,16,-13,-1,-2,-3,-4,-12,16,]),'ATTRIB':([17,22,],[23,23,]),} _lr_action = {} for _k, _v in _lr_action_items.items(): @@ -17,7 +17,7 @@ for _k, _v in _lr_action_items.items(): _lr_action[_x][_k] = _y del _lr_action_items -_lr_goto_items = {'statement':([0,],[1,]),'element':([0,3,],[2,7,]),'section':([0,],[4,]),'values':([5,],[9,]),'attributes':([5,9,16,],[10,18,22,]),'value':([5,9,17,],[11,19,24,]),'attribute':([5,9,10,16,18,22,],[12,12,21,12,21,21,]),} +_lr_goto_items = {'statement':([0,],[1,]),'element':([0,3,],[2,9,]),'section':([0,],[4,]),'elm':([0,3,6,],[5,5,18,]),'values':([5,],[10,]),'attributes':([5,10,18,],[11,19,24,]),'value':([5,10,23,],[12,20,26,]),'attribute':([5,10,11,18,19,24,],[13,13,21,13,21,21,]),} _lr_goto = {} for _k, _v in _lr_goto_items.items(): @@ -31,18 +31,20 @@ _lr_productions = [ ('value -> BASE10','value',1,'p_value','parser.py',12), ('value -> STRING','value',1,'p_value','parser.py',13), ('value -> ATOM','value',1,'p_value','parser.py',14), - ('attribute -> ATOM ATTRIB value','attribute',3,'p_attribute','parser.py',21), - ('attributes -> attributes attribute','attributes',2,'p_attributes','parser.py',28), - ('attributes -> attribute','attributes',1,'p_attributes','parser.py',29), - ('section -> SECTION ATOM','section',2,'p_section','parser.py',40), - ('section -> SECTION ATOM attributes','section',3,'p_section','parser.py',41), - ('values -> values value','values',2,'p_values','parser.py',50), - ('values -> value','values',1,'p_values','parser.py',51), - ('element -> ATOM values','element',2,'p_element','parser.py',62), - ('element -> ATOM values attributes','element',3,'p_element','parser.py',63), - ('element -> ATOM attributes','element',2,'p_element','parser.py',64), - ('element -> ATOM','element',1,'p_element','parser.py',65), - ('statement -> element','statement',1,'p_statement','parser.py',78), - ('statement -> DEEP element','statement',2,'p_statement','parser.py',79), - ('statement -> section','statement',1,'p_statement','parser.py',80), + ('elm -> ATOM','elm',1,'p_elm','parser.py',22), + ('elm -> ELEMENT','elm',1,'p_elm','parser.py',23), + ('attribute -> ATOM ATTRIB value','attribute',3,'p_attribute','parser.py',27), + ('attributes -> attributes attribute','attributes',2,'p_attributes','parser.py',34), + ('attributes -> attribute','attributes',1,'p_attributes','parser.py',35), + ('section -> SECTION elm','section',2,'p_section','parser.py',46), + ('section -> SECTION elm attributes','section',3,'p_section','parser.py',47), + ('values -> values value','values',2,'p_values','parser.py',56), + ('values -> value','values',1,'p_values','parser.py',57), + ('element -> elm values','element',2,'p_element','parser.py',68), + ('element -> elm values attributes','element',3,'p_element','parser.py',69), + ('element -> elm attributes','element',2,'p_element','parser.py',70), + ('element -> elm','element',1,'p_element','parser.py',71), + ('statement -> element','statement',1,'p_statement','parser.py',84), + ('statement -> DEEP element','statement',2,'p_statement','parser.py',85), + ('statement -> section','statement',1,'p_statement','parser.py',86), ]