Begin draft surface AST

This commit is contained in:
Denis Merigoux 2020-04-14 11:01:31 +02:00
parent 8c79bdd1dd
commit 5779b26e32
3 changed files with 29 additions and 12 deletions

View File

@ -28,11 +28,11 @@ let source_file_item_to_latex (i : A.source_file_item) : string =
| A.LawCode c -> P.sprintf "\\section*{%s}" c
| A.LawText t -> pre_latexify t
| A.LawArticle a -> P.sprintf "\\paragraph{%s}" (pre_latexify a)
| A.CodeBlock c ->
| A.CodeBlock (_, c) ->
P.sprintf "\\begin{minted}[firstnumber=%d]{lawspec}%s\\end{minted}"
(Pos.get_start_line (Pos.get_position c) + 1)
(Pos.unmark c)
| A.MetadataBlock c ->
| A.MetadataBlock (_, c) ->
P.sprintf
"\\begin{tcolorbox}[colframe=OliveGreen, breakable, \
title=\\textcolor{black}{\\texttt{Métadonnées}},title after \

View File

@ -12,11 +12,17 @@
or implied. See the License for the specific language governing permissions and limitations under
the License. *)
type code_item = FieldUse of unit | FieldDecl of unit | StructDecl of unit | EnumDecl of unit
type code_block = code_item list
type source_repr = string Pos.marked
type source_file_item =
| LawCode of string
| LawArticle of string
| LawText of string
| CodeBlock of string Pos.marked
| MetadataBlock of string Pos.marked
| CodeBlock of code_block * source_repr
| MetadataBlock of code_block * source_repr
type source_file = source_file_item list

View File

@ -250,23 +250,34 @@ enum_decl_line:
| ALT CONSTRUCTOR option(enum_decl_line_payload) {}
code_item:
| FIELD CONSTRUCTOR COLON nonempty_list(application_field_item) { }
| DECLARATION STRUCT CONSTRUCTOR COLON list(struct_field) {}
| DECLARATION FIELD CONSTRUCTOR COLON nonempty_list(field_decl_item) list(field_decl_includes) {}
| DECLARATION ENUM CONSTRUCTOR COLON nonempty_list(enum_decl_line) {}
| FIELD CONSTRUCTOR COLON nonempty_list(application_field_item) { FieldUse () }
| DECLARATION STRUCT CONSTRUCTOR COLON list(struct_field) { StructDecl () }
| DECLARATION FIELD CONSTRUCTOR COLON nonempty_list(field_decl_item) list(field_decl_includes) {
FieldDecl ()
}
| DECLARATION ENUM CONSTRUCTOR COLON nonempty_list(enum_decl_line) { EnumDecl () }
code:
| list(code_item) { mk_position $sloc }
| code = list(code_item) { (code, mk_position $sloc) }
metadata_block:
| BEGIN_CODE pos = code text = END_CODE END_METADATA { (text, pos) }
| BEGIN_CODE code_and_pos = code text = END_CODE END_METADATA {
let (code, pos) = code_and_pos in
(code, (text, pos))
}
source_file_item:
| title = LAW_ARTICLE { LawArticle title }
| code = LAW_CODE { LawCode code }
| text = LAW_TEXT { LawText text }
| BEGIN_METADATA text = metadata_block { MetadataBlock text }
| BEGIN_CODE pos = code text = END_CODE { CodeBlock (text, pos) }
| BEGIN_METADATA code = metadata_block {
let (code, source_repr) = code in
MetadataBlock (code, source_repr)
}
| BEGIN_CODE code_and_pos = code text = END_CODE {
let (code, pos) = code_and_pos in
CodeBlock (code, (text, pos))
}
source_file:
| i = source_file_item f = source_file { i::f }