@@ -378,6 +378,9 @@ def KW_ORDERED(self, token: Token) -> str: # noqa: N802
378378 def KW_TOPIC (self , token : Token ) -> str : # noqa: N802
379379 return token .value .upper ()
380380
381+ def KW_GUIDELINES (self , token : Token ) -> str : # noqa: N802
382+ return token .value .upper ()
383+
381384 def COMPARATOR (self , token : Token ) -> str : # noqa: N802
382385 return token .value
383386
@@ -529,6 +532,36 @@ def description(self, items: List[Any]) -> str:
529532 def description_lines (self , items : List [Any ]) -> List [Any ]:
530533 return items
531534
535+ def guidelines_lines (self , items : List [Any ]) -> List [Any ]:
536+ return items
537+
538+ def guidelines_block (self , items : List [Any ]) -> Tuple [str , Any ]:
539+ lines : List [str ] = []
540+ pending_blank = False
541+ keywords = {"GUIDELINES" , "END" }
542+ flattened : List [Any ] = []
543+ for item in items :
544+ if isinstance (item , list ):
545+ flattened .extend (item )
546+ else :
547+ flattened .append (item )
548+ for item in flattened :
549+ if isinstance (item , Token ) and item .type in {"NEWLINE" , "_INDENT" , "_DEDENT" }:
550+ if item .type == "NEWLINE" :
551+ if pending_blank :
552+ lines .append ("" )
553+ pending_blank = False
554+ else :
555+ pending_blank = True
556+ continue
557+ if isinstance (item , str ):
558+ if item .upper () in keywords :
559+ continue
560+ lines .append (item )
561+ pending_blank = False
562+ text = "\n " .join (lines ).strip ()
563+ return ("guidelines" , text if text else None )
564+
532565 @v_args (tree = True )
533566 def source_block (self , tree : Any ) -> SourceNode :
534567 meta = tree .meta
@@ -745,6 +778,7 @@ def field_def_block(self, tree: Any) -> FieldSpec:
745778 values = None
746779 relations = None
747780 arity = None
781+ guidelines = None
748782 for prop in props :
749783 key , value = prop
750784 if key == "scope" :
@@ -759,6 +793,8 @@ def field_def_block(self, tree: Any) -> FieldSpec:
759793 relations = value
760794 elif key == "arity" :
761795 arity = value
796+ elif key == "guidelines" :
797+ guidelines = value
762798 if scope is None :
763799 scope = Scope .ITEM
764800 return FieldSpec (
@@ -770,6 +806,7 @@ def field_def_block(self, tree: Any) -> FieldSpec:
770806 values = values ,
771807 relations = relations ,
772808 arity = arity ,
809+ guidelines = guidelines ,
773810 location = _source_location (self .file_path , meta ),
774811 )
775812
@@ -790,6 +827,8 @@ def field_props(self, items: List[Any]) -> Tuple[str, Any]:
790827 return ("arity" , f"{ items [1 ]} { items [2 ]} " )
791828 if items [0 ] == "VALUES" :
792829 return ("values" , items [1 ])
830+ if isinstance (items [0 ], tuple ) and items [0 ][0 ] == "guidelines" :
831+ return items [0 ]
793832 return ("relations" , items [1 ])
794833
795834 def scope_type (self , items : List [Any ]) -> str :
0 commit comments