Cleaned lexing code and rationalized non-verbose syntax

This commit is contained in:
Denis Merigoux 2020-08-08 18:32:44 +02:00
parent df25d5d94d
commit 0f43975182
14 changed files with 330 additions and 344 deletions

View File

@ -54,6 +54,11 @@ jobs:
eval $(opam env) eval $(opam env)
make build make build
- name: Run tests
run: |
eval $(opam env)
make tests
- name: Make examples - name: Make examples
run: | run: |
eval $(opam env) eval $(opam env)

View File

@ -22,19 +22,42 @@ let code_string_acc : string ref = ref ""
let update_acc (lexbuf : lexbuf) : unit = code_string_acc := !code_string_acc ^ Utf8.lexeme lexbuf let update_acc (lexbuf : lexbuf) : unit = code_string_acc := !code_string_acc ^ Utf8.lexeme lexbuf
let raise_lexer_error (loc : Pos.t) (token : string) (msg : string) =
Errors.raise_spanned_error (Printf.sprintf "Parsing error on token \"%s\": %s" token msg) loc
let token_list_language_agnostic : (string * token) list =
[
("->", ARROW);
(".", DOT);
("<=", LESSER_EQUAL);
(">=", GREATER_EQUAL);
(">", GREATER);
("!=", NOT_EQUAL);
("=", EQUAL);
("(", LPAREN);
(")", RPAREN);
("+", PLUS);
("-", MINUS);
("*", MULT);
("/", DIV);
("|", VERTICAL);
(":", COLON);
("--", ALT);
]
let token_list : (string * token) list = let token_list : (string * token) list =
[ [
("scope", SCOPE); ("scope", SCOPE);
("|", CONSEQUENCE); ("]", CONSEQUENCE);
("data", DATA); ("data", DATA);
("depends on", DEPENDS); ("fun of", DEPENDS);
("declaration", DECLARATION); ("new", DECLARATION);
("context", CONTEXT); ("param", CONTEXT);
("decreasing", DECREASING); ("decreasing", DECREASING);
("increasing", INCREASING); ("increasing", INCREASING);
("of", OF); ("of", OF);
("collection", COLLECTION); ("set", COLLECTION);
("enumeration", ENUM); ("enum", ENUM);
("int", INTEGER); ("int", INTEGER);
("amount", MONEY); ("amount", MONEY);
("text", TEXT); ("text", TEXT);
@ -42,21 +65,21 @@ let token_list : (string * token) list =
("date", DATE); ("date", DATE);
("boolean", BOOLEAN); ("boolean", BOOLEAN);
("sum", SUM); ("sum", SUM);
("fulfilled", FILLED); ("ok", FILLED);
("def", DEFINITION); ("def", DEFINITION);
("equals", DEFINED_AS); ("equals", DEFINED_AS);
("match", MATCH); ("match", MATCH);
("with pattern", WITH); ("with", WITH);
("?", UNDER_CONDITION); ("[", UNDER_CONDITION);
("if", IF); ("if", IF);
("then", THEN); ("then", THEN);
("else", ELSE); ("else", ELSE);
("content", CONTENT); ("type", CONTENT);
("structure", STRUCT); ("struct", STRUCT);
("optional", OPTIONAL); ("option", OPTIONAL);
("assertion", ASSERTION); ("assert", ASSERTION);
("varies", VARIES); ("varies", VARIES);
("with", WITH_V); ("with parameter", WITH_V);
("for", FOR); ("for", FOR);
("all", ALL); ("all", ALL);
("we have", WE_HAVE); ("we have", WE_HAVE);
@ -75,7 +98,7 @@ let token_list : (string * token) list =
("true", TRUE); ("true", TRUE);
("false", FALSE); ("false", FALSE);
] ]
@ Lexer_fr.token_list_language_agnostic @ token_list_language_agnostic
let rec lex_code (lexbuf : lexbuf) : token = let rec lex_code (lexbuf : lexbuf) : token =
match%sedlex lexbuf with match%sedlex lexbuf with
@ -97,13 +120,13 @@ let rec lex_code (lexbuf : lexbuf) : token =
| "data" -> | "data" ->
update_acc lexbuf; update_acc lexbuf;
DATA DATA
| "depends on" -> | "fun of" ->
update_acc lexbuf; update_acc lexbuf;
DEPENDS DEPENDS
| "declaration" -> | "new" ->
update_acc lexbuf; update_acc lexbuf;
DECLARATION DECLARATION
| "context" -> | "param" ->
update_acc lexbuf; update_acc lexbuf;
CONTEXT CONTEXT
| "decreasing" -> | "decreasing" ->
@ -115,10 +138,10 @@ let rec lex_code (lexbuf : lexbuf) : token =
| "of" -> | "of" ->
update_acc lexbuf; update_acc lexbuf;
OF OF
| "collection" -> | "set" ->
update_acc lexbuf; update_acc lexbuf;
COLLECTION COLLECTION
| "enumeration" -> | "enum" ->
update_acc lexbuf; update_acc lexbuf;
ENUM ENUM
| "int" -> | "int" ->
@ -142,22 +165,28 @@ let rec lex_code (lexbuf : lexbuf) : token =
| "sum" -> | "sum" ->
update_acc lexbuf; update_acc lexbuf;
SUM SUM
| "fulfilled" -> | "ok" ->
update_acc lexbuf; update_acc lexbuf;
FILLED FILLED
| "def" -> | "def" ->
update_acc lexbuf; update_acc lexbuf;
DEFINITION DEFINITION
| "=" -> | ":=" ->
update_acc lexbuf; update_acc lexbuf;
DEFINED_AS DEFINED_AS
| "varies" ->
update_acc lexbuf;
VARIES
| "with" ->
update_acc lexbuf;
WITH_V
| "match" -> | "match" ->
update_acc lexbuf; update_acc lexbuf;
MATCH MATCH
| "with pattern" -> | "with" ->
update_acc lexbuf; update_acc lexbuf;
WITH WITH
| "?" -> | "[" ->
update_acc lexbuf; update_acc lexbuf;
UNDER_CONDITION UNDER_CONDITION
| "if" -> | "if" ->
@ -172,24 +201,18 @@ let rec lex_code (lexbuf : lexbuf) : token =
| "condition" -> | "condition" ->
update_acc lexbuf; update_acc lexbuf;
CONDITION CONDITION
| "content" -> | "type" ->
update_acc lexbuf; update_acc lexbuf;
CONTENT CONTENT
| "structure" -> | "structure" ->
update_acc lexbuf; update_acc lexbuf;
STRUCT STRUCT
| "optional" -> | "option" ->
update_acc lexbuf; update_acc lexbuf;
OPTIONAL OPTIONAL
| "assertion" -> | "assert" ->
update_acc lexbuf; update_acc lexbuf;
ASSERTION ASSERTION
| "varies" ->
update_acc lexbuf;
VARIES
| "with" ->
update_acc lexbuf;
WITH_V
| "for" -> | "for" ->
update_acc lexbuf; update_acc lexbuf;
FOR FOR
@ -233,7 +256,7 @@ let rec lex_code (lexbuf : lexbuf) : token =
| "not" -> | "not" ->
update_acc lexbuf; update_acc lexbuf;
NOT NOT
| "|" -> | "]" ->
update_acc lexbuf; update_acc lexbuf;
CONSEQUENCE CONSEQUENCE
| "number" -> | "number" ->
@ -333,7 +356,7 @@ let rec lex_code (lexbuf : lexbuf) : token =
(* Integer literal*) (* Integer literal*)
update_acc lexbuf; update_acc lexbuf;
INT_LITERAL (int_of_string (Utf8.lexeme lexbuf)) INT_LITERAL (int_of_string (Utf8.lexeme lexbuf))
| _ -> Lexer_fr.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token" | _ -> raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token"
let rec lex_law (lexbuf : lexbuf) : token = let rec lex_law (lexbuf : lexbuf) : token =
match%sedlex lexbuf with match%sedlex lexbuf with
@ -363,9 +386,7 @@ let rec lex_law (lexbuf : lexbuf) : token =
let pos = lexing_positions lexbuf in let pos = lexing_positions lexbuf in
if Filename.extension name = ".pdf" then LAW_INCLUDE (Ast.PdfFile ((name, pos), pages)) if Filename.extension name = ".pdf" then LAW_INCLUDE (Ast.PdfFile ((name, pos), pages))
else if Filename.extension name = ".catala" then LAW_INCLUDE (Ast.CatalaFile (name, pos)) else if Filename.extension name = ".catala" then LAW_INCLUDE (Ast.CatalaFile (name, pos))
else else raise_lexer_error (lexing_positions lexbuf) name "this type of file cannot be included"
Lexer_fr.raise_lexer_error (lexing_positions lexbuf) name
"this type of file cannot be included"
| "@@", Plus (Compl '@'), "@@", Star '+' -> | "@@", Plus (Compl '@'), "@@", Star '+' ->
let extract_code_title = R.regexp "@@([^@]+)@@([\\+]*)" in let extract_code_title = R.regexp "@@([^@]+)@@([\\+]*)" in
let get_match = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in let get_match = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in
@ -394,6 +415,6 @@ let rec lex_law (lexbuf : lexbuf) : token =
LAW_ARTICLE (title, None, None) LAW_ARTICLE (title, None, None)
| Plus (Compl ('@' | '/' | '\n')) -> LAW_TEXT (Utf8.lexeme lexbuf) | Plus (Compl ('@' | '/' | '\n')) -> LAW_TEXT (Utf8.lexeme lexbuf)
| _ -> Lexer_fr.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token" | _ -> raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token"
let lexer lexbuf = if !is_code then lex_code lexbuf else lex_law lexbuf let lexer lexbuf = if !is_code then lex_code lexbuf else lex_law lexbuf

View File

@ -14,14 +14,9 @@
open Parser open Parser
open Sedlexing open Sedlexing
module L = Lexer
module R = Re.Pcre module R = Re.Pcre
let is_code : bool ref = ref false
let code_string_acc : string ref = ref ""
let update_acc (lexbuf : lexbuf) : unit = code_string_acc := !code_string_acc ^ Utf8.lexeme lexbuf
let token_list_en : (string * token) list = let token_list_en : (string * token) list =
[ [
("scope", SCOPE); ("scope", SCOPE);
@ -75,178 +70,178 @@ let token_list_en : (string * token) list =
("true", TRUE); ("true", TRUE);
("false", FALSE); ("false", FALSE);
] ]
@ Lexer_fr.token_list_language_agnostic @ L.token_list_language_agnostic
let rec lex_code_en (lexbuf : lexbuf) : token = let rec lex_code_en (lexbuf : lexbuf) : token =
match%sedlex lexbuf with match%sedlex lexbuf with
| white_space -> | white_space ->
(* Whitespaces *) (* Whitespaces *)
update_acc lexbuf; L.update_acc lexbuf;
lex_code_en lexbuf lex_code_en lexbuf
| '#', Star (Compl '\n'), '\n' -> | '#', Star (Compl '\n'), '\n' ->
(* Comments *) (* Comments *)
update_acc lexbuf; L.update_acc lexbuf;
lex_code_en lexbuf lex_code_en lexbuf
| "*/" -> | "*/" ->
(* End of code section *) (* End of code section *)
is_code := false; L.is_code := false;
END_CODE !code_string_acc END_CODE !L.code_string_acc
| "scope" -> | "scope" ->
update_acc lexbuf; L.update_acc lexbuf;
SCOPE SCOPE
| "data" -> | "data" ->
update_acc lexbuf; L.update_acc lexbuf;
DATA DATA
| "depends on" -> | "depends on" ->
update_acc lexbuf; L.update_acc lexbuf;
DEPENDS DEPENDS
| "declaration" -> | "declaration" ->
update_acc lexbuf; L.update_acc lexbuf;
DECLARATION DECLARATION
| "context" -> | "context" ->
update_acc lexbuf; L.update_acc lexbuf;
CONTEXT CONTEXT
| "decreasing" -> | "decreasing" ->
update_acc lexbuf; L.update_acc lexbuf;
DECREASING DECREASING
| "increasing" -> | "increasing" ->
update_acc lexbuf; L.update_acc lexbuf;
INCREASING INCREASING
| "of" -> | "of" ->
update_acc lexbuf; L.update_acc lexbuf;
OF OF
| "collection" -> | "collection" ->
update_acc lexbuf; L.update_acc lexbuf;
COLLECTION COLLECTION
| "enumeration" -> | "enumeration" ->
update_acc lexbuf; L.update_acc lexbuf;
ENUM ENUM
| "integer" -> | "integer" ->
update_acc lexbuf; L.update_acc lexbuf;
INTEGER INTEGER
| "amount" -> | "amount" ->
update_acc lexbuf; L.update_acc lexbuf;
MONEY MONEY
| "text" -> | "text" ->
update_acc lexbuf; L.update_acc lexbuf;
TEXT TEXT
| "decimal" -> | "decimal" ->
update_acc lexbuf; L.update_acc lexbuf;
DECIMAL DECIMAL
| "date" -> | "date" ->
update_acc lexbuf; L.update_acc lexbuf;
DATE DATE
| "boolean" -> | "boolean" ->
update_acc lexbuf; L.update_acc lexbuf;
BOOLEAN BOOLEAN
| "sum" -> | "sum" ->
update_acc lexbuf; L.update_acc lexbuf;
SUM SUM
| "fulfilled" -> | "fulfilled" ->
update_acc lexbuf; L.update_acc lexbuf;
FILLED FILLED
| "definition" -> | "definition" ->
update_acc lexbuf; L.update_acc lexbuf;
DEFINITION DEFINITION
| "equals" -> | "equals" ->
update_acc lexbuf; L.update_acc lexbuf;
DEFINED_AS DEFINED_AS
| "match" -> | "match" ->
update_acc lexbuf; L.update_acc lexbuf;
MATCH MATCH
| "with pattern" -> | "with pattern" ->
update_acc lexbuf; L.update_acc lexbuf;
WITH WITH
| "under condition" -> | "under condition" ->
update_acc lexbuf; L.update_acc lexbuf;
UNDER_CONDITION UNDER_CONDITION
| "if" -> | "if" ->
update_acc lexbuf; L.update_acc lexbuf;
IF IF
| "consequence" -> | "consequence" ->
update_acc lexbuf; L.update_acc lexbuf;
CONSEQUENCE CONSEQUENCE
| "then" -> | "then" ->
update_acc lexbuf; L.update_acc lexbuf;
THEN THEN
| "else" -> | "else" ->
update_acc lexbuf; L.update_acc lexbuf;
ELSE ELSE
| "condition" -> | "condition" ->
update_acc lexbuf; L.update_acc lexbuf;
CONDITION CONDITION
| "content" -> | "content" ->
update_acc lexbuf; L.update_acc lexbuf;
CONTENT CONTENT
| "structure" -> | "structure" ->
update_acc lexbuf; L.update_acc lexbuf;
STRUCT STRUCT
| "optional" -> | "optional" ->
update_acc lexbuf; L.update_acc lexbuf;
OPTIONAL OPTIONAL
| "assertion" -> | "assertion" ->
update_acc lexbuf; L.update_acc lexbuf;
ASSERTION ASSERTION
| "varies" -> | "varies" ->
update_acc lexbuf; L.update_acc lexbuf;
VARIES VARIES
| "with" -> | "with" ->
update_acc lexbuf; L.update_acc lexbuf;
WITH_V WITH_V
| "for" -> | "for" ->
update_acc lexbuf; L.update_acc lexbuf;
FOR FOR
| "all" -> | "all" ->
update_acc lexbuf; L.update_acc lexbuf;
ALL ALL
| "we have" -> | "we have" ->
update_acc lexbuf; L.update_acc lexbuf;
WE_HAVE WE_HAVE
| "fixed" -> | "fixed" ->
update_acc lexbuf; L.update_acc lexbuf;
FIXED FIXED
| "by" -> | "by" ->
update_acc lexbuf; L.update_acc lexbuf;
BY BY
| "rule" -> | "rule" ->
(* 0xE8 is è *) (* 0xE8 is è *)
update_acc lexbuf; L.update_acc lexbuf;
RULE RULE
| "exists" -> | "exists" ->
update_acc lexbuf; L.update_acc lexbuf;
EXISTS EXISTS
| "in" -> | "in" ->
update_acc lexbuf; L.update_acc lexbuf;
IN IN
| "such" -> | "such" ->
update_acc lexbuf; L.update_acc lexbuf;
SUCH SUCH
| "that" -> | "that" ->
update_acc lexbuf; L.update_acc lexbuf;
THAT THAT
| "now" -> | "now" ->
update_acc lexbuf; L.update_acc lexbuf;
NOW NOW
| "and" -> | "and" ->
update_acc lexbuf; L.update_acc lexbuf;
AND AND
| "or" -> | "or" ->
update_acc lexbuf; L.update_acc lexbuf;
OR OR
| "not" -> | "not" ->
update_acc lexbuf; L.update_acc lexbuf;
NOT NOT
| "number" -> | "number" ->
update_acc lexbuf; L.update_acc lexbuf;
CARDINAL CARDINAL
| "true" -> | "true" ->
update_acc lexbuf; L.update_acc lexbuf;
TRUE TRUE
| "false" -> | "false" ->
update_acc lexbuf; L.update_acc lexbuf;
FALSE FALSE
| "year" -> | "year" ->
update_acc lexbuf; L.update_acc lexbuf;
YEAR YEAR
| 0x24, Star white_space, '0' .. '9', Star ('0' .. '9' | ','), Opt ('.', Rep ('0' .. '9', 0 .. 2)) | 0x24, Star white_space, '0' .. '9', Star ('0' .. '9' | ','), Opt ('.', Rep ('0' .. '9', 0 .. 2))
-> ->
@ -259,93 +254,99 @@ let rec lex_code_en (lexbuf : lexbuf) : token =
let remove_commas = R.regexp "," in let remove_commas = R.regexp "," in
let units = int_of_string (R.substitute ~rex:remove_commas ~subst:(fun _ -> "") units) in let units = int_of_string (R.substitute ~rex:remove_commas ~subst:(fun _ -> "") units) in
let cents = try int_of_string (parts 4) with Not_found -> 0 in let cents = try int_of_string (parts 4) with Not_found -> 0 in
update_acc lexbuf; L.update_acc lexbuf;
MONEY_AMOUNT (units, cents) MONEY_AMOUNT (units, cents)
| Plus '0' .. '9', '.', Star '0' .. '9' -> | Plus '0' .. '9', '.', Star '0' .. '9' ->
let extract_code_title = R.regexp "([0-9]+)\\.([0-9]*)" in let extract_code_title = R.regexp "([0-9]+)\\.([0-9]*)" in
let dec_parts = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in let dec_parts = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in
(* Integer literal*) (* Integer literal*)
update_acc lexbuf; L.update_acc lexbuf;
DECIMAL_LITERAL (int_of_string (dec_parts 1), int_of_string (dec_parts 2)) DECIMAL_LITERAL (int_of_string (dec_parts 1), int_of_string (dec_parts 2))
| "->" -> | "->" ->
update_acc lexbuf; L.update_acc lexbuf;
ARROW ARROW
| '.' -> | '.' ->
update_acc lexbuf; L.update_acc lexbuf;
DOT DOT
| "<=" -> | "<=" ->
update_acc lexbuf; L.update_acc lexbuf;
LESSER_EQUAL LESSER_EQUAL
| '<' -> | '<' ->
update_acc lexbuf; L.update_acc lexbuf;
LESSER LESSER
| ">=" -> | ">=" ->
update_acc lexbuf; L.update_acc lexbuf;
GREATER_EQUAL GREATER_EQUAL
| '>' -> | '>' ->
update_acc lexbuf; L.update_acc lexbuf;
GREATER GREATER
| "!=" -> | "!=" ->
update_acc lexbuf; L.update_acc lexbuf;
NOT_EQUAL NOT_EQUAL
| '=' -> | '=' ->
update_acc lexbuf; L.update_acc lexbuf;
EQUAL EQUAL
| '(' -> | '(' ->
update_acc lexbuf; L.update_acc lexbuf;
LPAREN LPAREN
| ')' -> | ')' ->
update_acc lexbuf; L.update_acc lexbuf;
RPAREN RPAREN
| '+' -> | '+' ->
update_acc lexbuf; L.update_acc lexbuf;
PLUS PLUS
| '-' -> | '-' ->
update_acc lexbuf; L.update_acc lexbuf;
MINUS MINUS
| '*' -> | '*' ->
update_acc lexbuf; L.update_acc lexbuf;
MULT MULT
| '%' -> | '%' ->
update_acc lexbuf; L.update_acc lexbuf;
PERCENT PERCENT
| '/' -> | '/' ->
update_acc lexbuf; L.update_acc lexbuf;
DIV DIV
| '|' -> | '|' ->
update_acc lexbuf; L.update_acc lexbuf;
VERTICAL VERTICAL
| ':' -> | ':' ->
update_acc lexbuf; L.update_acc lexbuf;
COLON COLON
| "--" -> | "--" ->
update_acc lexbuf; L.update_acc lexbuf;
ALT ALT
| uppercase, Star (uppercase | lowercase | '0' .. '9' | '_' | '\'') -> | uppercase, Star (uppercase | lowercase | '0' .. '9' | '_' | '\'') ->
(* Name of constructor *) (* Name of constructor *)
update_acc lexbuf; L.update_acc lexbuf;
CONSTRUCTOR (Utf8.lexeme lexbuf) CONSTRUCTOR (Utf8.lexeme lexbuf)
| lowercase, Star (lowercase | uppercase | '0' .. '9' | '_' | '\'') -> | lowercase, Star (lowercase | uppercase | '0' .. '9' | '_' | '\'') ->
(* Name of variable *) (* Name of variable *)
update_acc lexbuf; L.update_acc lexbuf;
IDENT (Utf8.lexeme lexbuf) IDENT (Utf8.lexeme lexbuf)
| Plus '0' .. '9' -> | Plus '0' .. '9' ->
(* Integer literal*) (* Integer literal*)
update_acc lexbuf; L.update_acc lexbuf;
INT_LITERAL (int_of_string (Utf8.lexeme lexbuf)) INT_LITERAL (int_of_string (Utf8.lexeme lexbuf))
| _ -> Lexer_fr.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token" | _ -> L.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token"
let rec lex_law_en (lexbuf : lexbuf) : token = let rec lex_law_en (lexbuf : lexbuf) : token =
match%sedlex lexbuf with match%sedlex lexbuf with
| '\n' -> lex_law_en lexbuf | '\n' -> lex_law_en lexbuf
| "/*" -> | "/*" ->
is_code := true; L.is_code := true;
code_string_acc := ""; L.code_string_acc := "";
BEGIN_CODE BEGIN_CODE
| eof -> EOF | eof -> EOF
| "@@", Star white_space, "Master file", Star white_space, "@@" -> MASTER_FILE | "@@", Star white_space, "Master file", Star white_space, "@@" ->
| "@@", Star white_space, "Begin metadata", Star white_space, "@@" -> BEGIN_METADATA Cli.debug_print "A1";
| "@@", Star white_space, "End metadata", Star white_space, "@@" -> END_METADATA MASTER_FILE
| "@@", Star white_space, "Begin metadata", Star white_space, "@@" ->
Cli.debug_print "A1";
BEGIN_METADATA
| "@@", Star white_space, "End metadata", Star white_space, "@@" ->
Cli.debug_print "A1";
END_METADATA
| ( "@@", | ( "@@",
Star white_space, Star white_space,
"Include:", "Include:",
@ -363,9 +364,7 @@ let rec lex_law_en (lexbuf : lexbuf) : token =
let pos = lexing_positions lexbuf in let pos = lexing_positions lexbuf in
if Filename.extension name = ".pdf" then LAW_INCLUDE (Ast.PdfFile ((name, pos), pages)) if Filename.extension name = ".pdf" then LAW_INCLUDE (Ast.PdfFile ((name, pos), pages))
else if Filename.extension name = ".catala" then LAW_INCLUDE (Ast.CatalaFile (name, pos)) else if Filename.extension name = ".catala" then LAW_INCLUDE (Ast.CatalaFile (name, pos))
else else L.raise_lexer_error (lexing_positions lexbuf) name "this type of file cannot be included"
Lexer_fr.raise_lexer_error (lexing_positions lexbuf) name
"this type of file cannot be included"
| "@@", Plus (Compl '@'), "@@", Star '+' -> | "@@", Plus (Compl '@'), "@@", Star '+' ->
let extract_code_title = R.regexp "@@([^@]+)@@([\\+]*)" in let extract_code_title = R.regexp "@@([^@]+)@@([\\+]*)" in
let get_match = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in let get_match = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in
@ -394,6 +393,6 @@ let rec lex_law_en (lexbuf : lexbuf) : token =
LAW_ARTICLE (title, None, None) LAW_ARTICLE (title, None, None)
| Plus (Compl ('@' | '/' | '\n')) -> LAW_TEXT (Utf8.lexeme lexbuf) | Plus (Compl ('@' | '/' | '\n')) -> LAW_TEXT (Utf8.lexeme lexbuf)
| _ -> Lexer_fr.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token" | _ -> L.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token"
let lexer_en lexbuf = if !is_code then lex_code_en lexbuf else lex_law_en lexbuf let lexer_en lexbuf = if !L.is_code then lex_code_en lexbuf else lex_law_en lexbuf

View File

@ -14,43 +14,9 @@
open Parser open Parser
open Sedlexing open Sedlexing
module L = Lexer
module R = Re.Pcre module R = Re.Pcre
let is_code : bool ref = ref false
let code_string_acc : string ref = ref ""
let raise_lexer_error (loc : Pos.t) (token : string) (msg : string) =
Errors.raise_spanned_error (Printf.sprintf "Parsing error on token \"%s\": %s" token msg) loc
let rec lex_code_as_string (lexbuf : lexbuf) (acc : string) : token =
match%sedlex lexbuf with
| "*/" -> END_CODE (acc ^ Utf8.lexeme lexbuf)
| any -> lex_code_as_string lexbuf (acc ^ Utf8.lexeme lexbuf)
| _ -> raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unexpected token"
let update_acc (lexbuf : lexbuf) = code_string_acc := !code_string_acc ^ Utf8.lexeme lexbuf
let token_list_language_agnostic : (string * token) list =
[
("->", ARROW);
(".", DOT);
("<=", LESSER_EQUAL);
(">=", GREATER_EQUAL);
(">", GREATER);
("!=", NOT_EQUAL);
("=", EQUAL);
("(", LPAREN);
(")", RPAREN);
("+", PLUS);
("-", MINUS);
("*", MULT);
("/", DIV);
("|", VERTICAL);
(":", COLON);
("--", ALT);
]
let token_list_fr : (string * token) list = let token_list_fr : (string * token) list =
[ [
("champ d'application", SCOPE); ("champ d'application", SCOPE);
@ -104,184 +70,184 @@ let token_list_fr : (string * token) list =
("vrai", TRUE); ("vrai", TRUE);
("faux", FALSE); ("faux", FALSE);
] ]
@ token_list_language_agnostic @ L.token_list_language_agnostic
let rec lex_code_fr (lexbuf : lexbuf) : token = let rec lex_code_fr (lexbuf : lexbuf) : token =
match%sedlex lexbuf with match%sedlex lexbuf with
| white_space | '\n' -> | white_space | '\n' ->
(* Whitespaces *) (* Whitespaces *)
update_acc lexbuf; L.update_acc lexbuf;
lex_code_fr lexbuf lex_code_fr lexbuf
| '#', Star (Compl '\n'), '\n' -> | '#', Star (Compl '\n'), '\n' ->
(* Comments *) (* Comments *)
update_acc lexbuf; L.update_acc lexbuf;
lex_code_fr lexbuf lex_code_fr lexbuf
| "*/" -> | "*/" ->
(* End of code section *) (* End of code section *)
is_code := false; L.is_code := false;
END_CODE !code_string_acc END_CODE !L.code_string_acc
| "champ d\'application" -> | "champ d\'application" ->
update_acc lexbuf; L.update_acc lexbuf;
SCOPE SCOPE
| "donn", 0xE9, "e" -> | "donn", 0xE9, "e" ->
(* 0xE9 is é *) (* 0xE9 is é *)
update_acc lexbuf; L.update_acc lexbuf;
DATA DATA
| "d", 0xE9, "pend de" -> | "d", 0xE9, "pend de" ->
update_acc lexbuf; L.update_acc lexbuf;
DEPENDS DEPENDS
| "d", 0xE9, "claration" -> | "d", 0xE9, "claration" ->
update_acc lexbuf; L.update_acc lexbuf;
DECLARATION DECLARATION
| "contexte" -> | "contexte" ->
update_acc lexbuf; L.update_acc lexbuf;
CONTEXT CONTEXT
| "d", 0xE9, "croissant" -> | "d", 0xE9, "croissant" ->
update_acc lexbuf; L.update_acc lexbuf;
DECREASING DECREASING
| "croissant" -> | "croissant" ->
update_acc lexbuf; L.update_acc lexbuf;
INCREASING INCREASING
| "de" -> | "de" ->
update_acc lexbuf; L.update_acc lexbuf;
OF OF
| "collection" -> | "collection" ->
update_acc lexbuf; L.update_acc lexbuf;
COLLECTION COLLECTION
| 0xE9, "num", 0xE9, "ration" -> | 0xE9, "num", 0xE9, "ration" ->
update_acc lexbuf; L.update_acc lexbuf;
ENUM ENUM
| "entier" -> | "entier" ->
update_acc lexbuf; L.update_acc lexbuf;
INTEGER INTEGER
| "montant" -> | "montant" ->
update_acc lexbuf; L.update_acc lexbuf;
MONEY MONEY
| "texte" -> | "texte" ->
update_acc lexbuf; L.update_acc lexbuf;
TEXT TEXT
| "d", 0xE9, "cimal" -> | "d", 0xE9, "cimal" ->
update_acc lexbuf; L.update_acc lexbuf;
DECIMAL DECIMAL
| "date" -> | "date" ->
update_acc lexbuf; L.update_acc lexbuf;
DATE DATE
| "bool", 0xE9, "en" -> | "bool", 0xE9, "en" ->
update_acc lexbuf; L.update_acc lexbuf;
BOOLEAN BOOLEAN
| "somme" -> | "somme" ->
update_acc lexbuf; L.update_acc lexbuf;
SUM SUM
| "rempli" -> | "rempli" ->
update_acc lexbuf; L.update_acc lexbuf;
FILLED FILLED
| "d", 0xE9, "finition" -> | "d", 0xE9, "finition" ->
(* 0xE9 is é *) (* 0xE9 is é *)
update_acc lexbuf; L.update_acc lexbuf;
DEFINITION DEFINITION
| 0xE9, "gal ", 0x00E0 -> | 0xE9, "gal ", 0x00E0 ->
(* 0xE9 is é *) (* 0xE9 is é *)
update_acc lexbuf; L.update_acc lexbuf;
DEFINED_AS DEFINED_AS
| "selon" -> | "selon" ->
update_acc lexbuf; L.update_acc lexbuf;
MATCH MATCH
| "sous forme" -> | "sous forme" ->
update_acc lexbuf; L.update_acc lexbuf;
WITH WITH
| "sous condition" -> | "sous condition" ->
update_acc lexbuf; L.update_acc lexbuf;
UNDER_CONDITION UNDER_CONDITION
| "si" -> | "si" ->
update_acc lexbuf; L.update_acc lexbuf;
IF IF
| "cons", 0xE9, "quence" -> | "cons", 0xE9, "quence" ->
(* 0xE9 is é *) (* 0xE9 is é *)
update_acc lexbuf; L.update_acc lexbuf;
CONSEQUENCE CONSEQUENCE
| "alors" -> | "alors" ->
(* 0xE9 is é *) (* 0xE9 is é *)
update_acc lexbuf; L.update_acc lexbuf;
THEN THEN
| "sinon" -> | "sinon" ->
update_acc lexbuf; L.update_acc lexbuf;
ELSE ELSE
| "condition" -> | "condition" ->
update_acc lexbuf; L.update_acc lexbuf;
CONDITION CONDITION
| "contenu" -> | "contenu" ->
update_acc lexbuf; L.update_acc lexbuf;
CONTENT CONTENT
| "structure" -> | "structure" ->
update_acc lexbuf; L.update_acc lexbuf;
STRUCT STRUCT
| "optionnel" -> | "optionnel" ->
update_acc lexbuf; L.update_acc lexbuf;
OPTIONAL OPTIONAL
| "assertion" -> | "assertion" ->
update_acc lexbuf; L.update_acc lexbuf;
ASSERTION ASSERTION
| "varie" -> | "varie" ->
update_acc lexbuf; L.update_acc lexbuf;
VARIES VARIES
| "avec" -> | "avec" ->
update_acc lexbuf; L.update_acc lexbuf;
WITH_V WITH_V
| "pour" -> | "pour" ->
update_acc lexbuf; L.update_acc lexbuf;
FOR FOR
| "tout" -> | "tout" ->
update_acc lexbuf; L.update_acc lexbuf;
ALL ALL
| "on a" -> | "on a" ->
update_acc lexbuf; L.update_acc lexbuf;
WE_HAVE WE_HAVE
| "fix", 0xE9 -> | "fix", 0xE9 ->
(* 0xE9 is é *) (* 0xE9 is é *)
update_acc lexbuf; L.update_acc lexbuf;
FIXED FIXED
| "par" -> | "par" ->
update_acc lexbuf; L.update_acc lexbuf;
BY BY
| "r", 0xE8, "gle" -> | "r", 0xE8, "gle" ->
(* 0xE8 is è *) (* 0xE8 is è *)
update_acc lexbuf; L.update_acc lexbuf;
RULE RULE
| "existe" -> | "existe" ->
update_acc lexbuf; L.update_acc lexbuf;
EXISTS EXISTS
| "dans" -> | "dans" ->
update_acc lexbuf; L.update_acc lexbuf;
IN IN
| "tel" -> | "tel" ->
update_acc lexbuf; L.update_acc lexbuf;
SUCH SUCH
| "que" -> | "que" ->
update_acc lexbuf; L.update_acc lexbuf;
THAT THAT
| "maintenant" -> | "maintenant" ->
update_acc lexbuf; L.update_acc lexbuf;
NOW NOW
| "et" -> | "et" ->
update_acc lexbuf; L.update_acc lexbuf;
AND AND
| "ou" -> | "ou" ->
update_acc lexbuf; L.update_acc lexbuf;
OR OR
| "non" -> | "non" ->
update_acc lexbuf; L.update_acc lexbuf;
NOT NOT
| "nombre" -> | "nombre" ->
update_acc lexbuf; L.update_acc lexbuf;
CARDINAL CARDINAL
| "vrai" -> | "vrai" ->
update_acc lexbuf; L.update_acc lexbuf;
TRUE TRUE
| "faux" -> | "faux" ->
update_acc lexbuf; L.update_acc lexbuf;
FALSE FALSE
| "an" -> | "an" ->
update_acc lexbuf; L.update_acc lexbuf;
YEAR YEAR
| ( '0' .. '9', | ( '0' .. '9',
Star ('0' .. '9' | white_space), Star ('0' .. '9' | white_space),
@ -297,88 +263,88 @@ let rec lex_code_fr (lexbuf : lexbuf) : token =
let remove_spaces = R.regexp " " in let remove_spaces = R.regexp " " in
let units = int_of_string (R.substitute ~rex:remove_spaces ~subst:(fun _ -> "") units) in let units = int_of_string (R.substitute ~rex:remove_spaces ~subst:(fun _ -> "") units) in
let cents = try int_of_string (parts 4) with Not_found -> 0 in let cents = try int_of_string (parts 4) with Not_found -> 0 in
update_acc lexbuf; L.update_acc lexbuf;
MONEY_AMOUNT (units, cents) MONEY_AMOUNT (units, cents)
| Plus '0' .. '9', ',', Star '0' .. '9' -> | Plus '0' .. '9', ',', Star '0' .. '9' ->
let extract_code_title = R.regexp "([0-9]+),([0-9]*)" in let extract_code_title = R.regexp "([0-9]+),([0-9]*)" in
let dec_parts = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in let dec_parts = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in
(* Integer literal*) (* Integer literal*)
update_acc lexbuf; L.update_acc lexbuf;
DECIMAL_LITERAL (int_of_string (dec_parts 1), int_of_string (dec_parts 2)) DECIMAL_LITERAL (int_of_string (dec_parts 1), int_of_string (dec_parts 2))
| "->" -> | "->" ->
update_acc lexbuf; L.update_acc lexbuf;
ARROW ARROW
| '.' -> | '.' ->
update_acc lexbuf; L.update_acc lexbuf;
DOT DOT
| "<=" -> | "<=" ->
update_acc lexbuf; L.update_acc lexbuf;
LESSER_EQUAL LESSER_EQUAL
| '<' -> | '<' ->
update_acc lexbuf; L.update_acc lexbuf;
LESSER LESSER
| ">=" -> | ">=" ->
update_acc lexbuf; L.update_acc lexbuf;
GREATER_EQUAL GREATER_EQUAL
| '>' -> | '>' ->
update_acc lexbuf; L.update_acc lexbuf;
GREATER GREATER
| "!=" -> | "!=" ->
update_acc lexbuf; L.update_acc lexbuf;
NOT_EQUAL NOT_EQUAL
| '=' -> | '=' ->
update_acc lexbuf; L.update_acc lexbuf;
EQUAL EQUAL
| '(' -> | '(' ->
update_acc lexbuf; L.update_acc lexbuf;
LPAREN LPAREN
| ')' -> | ')' ->
update_acc lexbuf; L.update_acc lexbuf;
RPAREN RPAREN
| '+' -> | '+' ->
update_acc lexbuf; L.update_acc lexbuf;
PLUS PLUS
| '-' -> | '-' ->
update_acc lexbuf; L.update_acc lexbuf;
MINUS MINUS
| '*' -> | '*' ->
update_acc lexbuf; L.update_acc lexbuf;
MULT MULT
| '%' -> | '%' ->
update_acc lexbuf; L.update_acc lexbuf;
PERCENT PERCENT
| '/' -> | '/' ->
update_acc lexbuf; L.update_acc lexbuf;
DIV DIV
| '|' -> | '|' ->
update_acc lexbuf; L.update_acc lexbuf;
VERTICAL VERTICAL
| ':' -> | ':' ->
update_acc lexbuf; L.update_acc lexbuf;
COLON COLON
| "--" -> | "--" ->
update_acc lexbuf; L.update_acc lexbuf;
ALT ALT
| uppercase, Star (uppercase | lowercase | '0' .. '9' | '_' | '\'') -> | uppercase, Star (uppercase | lowercase | '0' .. '9' | '_' | '\'') ->
(* Name of constructor *) (* Name of constructor *)
update_acc lexbuf; L.update_acc lexbuf;
CONSTRUCTOR (Utf8.lexeme lexbuf) CONSTRUCTOR (Utf8.lexeme lexbuf)
| lowercase, Star (lowercase | uppercase | '0' .. '9' | '_' | '\'') -> | lowercase, Star (lowercase | uppercase | '0' .. '9' | '_' | '\'') ->
(* Name of variable *) (* Name of variable *)
update_acc lexbuf; L.update_acc lexbuf;
IDENT (Utf8.lexeme lexbuf) IDENT (Utf8.lexeme lexbuf)
| Plus '0' .. '9' -> | Plus '0' .. '9' ->
(* Integer literal*) (* Integer literal*)
update_acc lexbuf; L.update_acc lexbuf;
INT_LITERAL (int_of_string (Utf8.lexeme lexbuf)) INT_LITERAL (int_of_string (Utf8.lexeme lexbuf))
| _ -> raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token" | _ -> L.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token"
let rec lex_law_fr (lexbuf : lexbuf) : token = let rec lex_law_fr (lexbuf : lexbuf) : token =
match%sedlex lexbuf with match%sedlex lexbuf with
| '\n' -> lex_law_fr lexbuf | '\n' -> lex_law_fr lexbuf
| "/*" -> | "/*" ->
is_code := true; L.is_code := true;
code_string_acc := ""; L.code_string_acc := "";
BEGIN_CODE BEGIN_CODE
| eof -> EOF | eof -> EOF
| "@@", Star white_space, "Fichier ma", 0x00EE, "tre", Star white_space, "@@" -> | "@@", Star white_space, "Fichier ma", 0x00EE, "tre", Star white_space, "@@" ->
@ -408,7 +374,7 @@ let rec lex_law_fr (lexbuf : lexbuf) : token =
if R.pmatch ~rex:jorftext name then LAW_INCLUDE (Ast.LegislativeText (name, pos)) if R.pmatch ~rex:jorftext name then LAW_INCLUDE (Ast.LegislativeText (name, pos))
else if Filename.extension name = ".pdf" then LAW_INCLUDE (Ast.PdfFile ((name, pos), pages)) else if Filename.extension name = ".pdf" then LAW_INCLUDE (Ast.PdfFile ((name, pos), pages))
else if Filename.extension name = ".catala" then LAW_INCLUDE (Ast.CatalaFile (name, pos)) else if Filename.extension name = ".catala" then LAW_INCLUDE (Ast.CatalaFile (name, pos))
else raise_lexer_error (lexing_positions lexbuf) name "this type of file cannot be included" else L.raise_lexer_error (lexing_positions lexbuf) name "this type of file cannot be included"
| "@@", Plus (Compl '@'), "@@", Star '+' -> | "@@", Plus (Compl '@'), "@@", Star '+' ->
let extract_code_title = R.regexp "@@([^@]+)@@([\\+]*)" in let extract_code_title = R.regexp "@@([^@]+)@@([\\+]*)" in
let get_match = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in let get_match = R.get_substring (R.exec ~rex:extract_code_title (Utf8.lexeme lexbuf)) in
@ -445,6 +411,7 @@ let rec lex_law_fr (lexbuf : lexbuf) : token =
LAW_ARTICLE (title, article_id, article_expiration_date) LAW_ARTICLE (title, article_id, article_expiration_date)
| Plus (Compl ('@' | '/' | '\n')) -> LAW_TEXT (Utf8.lexeme lexbuf) | Plus (Compl ('@' | '/' | '\n')) -> LAW_TEXT (Utf8.lexeme lexbuf)
| _ -> raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token" | _ -> L.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "unknown token"
let lexer_fr (lexbuf : lexbuf) : token = if !is_code then lex_code_fr lexbuf else lex_law_fr lexbuf let lexer_fr (lexbuf : lexbuf) : token =
if !L.is_code then lex_code_fr lexbuf else lex_law_fr lexbuf

View File

@ -131,7 +131,7 @@ let sedlex_with_menhir (lexer' : lexbuf -> Parser.token) (token_list : (string *
in in
try loop lexer token_list lexbuf None (target_rule (fst @@ Sedlexing.lexing_positions lexbuf)) try loop lexer token_list lexbuf None (target_rule (fst @@ Sedlexing.lexing_positions lexbuf))
with Sedlexing.MalFormed | Sedlexing.InvalidCodepoint _ -> with Sedlexing.MalFormed | Sedlexing.InvalidCodepoint _ ->
Lexer_fr.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "malformed token" Lexer.raise_lexer_error (lexing_positions lexbuf) (Utf8.lexeme lexbuf) "malformed token"
let rec parse_source_files (source_files : string list) (language : Cli.frontend_lang) : Ast.program let rec parse_source_files (source_files : string list) (language : Cli.frontend_lang) : Ast.program
= =

View File

@ -112,11 +112,11 @@ let retrieve_loc_text (pos : t) : string =
| None -> [] | None -> []
in in
let pos_lines = get_lines 1 in let pos_lines = get_lines 1 in
let spaces = int_of_float (floor (log (float_of_int eline))) in let spaces = int_of_float (log10 (float_of_int eline)) + 1 in
close_in oc; close_in oc;
Cli.print_with_style blue_style "%*s--> %s\n%s" spaces "" filename Cli.print_with_style blue_style "%*s--> %s\n%s" spaces "" filename
(Cli.add_prefix_to_each_line (Cli.add_prefix_to_each_line
(Printf.sprintf "\n%s\n" (String.concat "\n" pos_lines)) (Printf.sprintf "\n%s" (String.concat "\n" pos_lines))
(fun i -> (fun i ->
let cur_line = sline - include_extra_count + i - 1 in let cur_line = sline - include_extra_count + i - 1 in
if if

View File

@ -31,6 +31,6 @@ test_scope/sub_scope.catala:
$(call interpret_with_scope_and_compare,nv,A) $(call interpret_with_scope_and_compare,nv,A)
$(call interpret_with_scope_and_compare,nv,B) $(call interpret_with_scope_and_compare,nv,B)
test_scope/sub_sub_scope.catala: test_scope/sub_sub_scope.catala:
$(call interpret_with_scope_and_compare,en,A) $(call interpret_with_scope_and_compare,nv,A)
$(call interpret_with_scope_and_compare,en,B) $(call interpret_with_scope_and_compare,nv,B)
$(call interpret_with_scope_and_compare,en,C) $(call interpret_with_scope_and_compare,nv,C)

View File

@ -1,10 +1,10 @@
/* /*
declaration scope TestBool : new scope TestBool :
context foo content bool param foo type bool
context bar content int param bar type int
scope TestBool : scope TestBool :
def bar = 1 def bar := 1
def foo ? bar >= 0 |= true def foo [ bar >= 0 ] := true
def foo ? bar < 0 |= false def foo [ bar < 0 ] := false
*/ */

View File

@ -1,14 +1,14 @@
/* /*
declaration scope S: new scope S:
context f content int depends on int param f type int fun of int
context x content int param x type int
context b content bool param b type bool
scope S: scope S:
def f of x ? (x >= x) |= x + x def f of x [ (x >= x) ] := x + x
def f of x ? not b |= x * x def f of x [ not b ] := x * x
def b = false def b := false
def x = f of 3 def x := f of 3
*/ */

View File

@ -1,13 +1,13 @@
/* /*
declaration scope A: new scope A:
context a content int param a type int
context b content dec param b type dec
context c content bool param c type bool
scope A: scope A:
def c = false def c := false
def a ? c |= 42 def a [ c ] := 42
def a ? not c |= 0 def a [ not c ] := 0
def b ? not c |= 1337 def b [ not c ] := 1337
def b ? not c |= 0 def b [ not c ] := 0
*/ */

View File

@ -3,20 +3,17 @@
[ERROR] The conflict concerns this variable b [ERROR] The conflict concerns this variable b
[ERROR] --> test_scope/scope.catala [ERROR] --> test_scope/scope.catala
[ERROR] | [ERROR] |
[ERROR] 4 | context b content dec [ERROR] 4 | param b type dec
[ERROR] | ^ [ERROR] | ^
[ERROR] |
[ERROR] [ERROR]
[ERROR] This justification is true: [ERROR] This justification is true:
[ERROR] --> test_scope/scope.catala [ERROR] --> test_scope/scope.catala
[ERROR] | [ERROR] |
[ERROR] 11 | def b ? not c |= 1337 [ERROR] 11 | def b [ not c ] := 1337
[ERROR] | ^^^^^ [ERROR] | ^^^^^
[ERROR] | [ERROR]
[ERROR]
[ERROR] This justification is true: [ERROR] This justification is true:
[ERROR] --> test_scope/scope.catala [ERROR] --> test_scope/scope.catala
[ERROR] | [ERROR] |
[ERROR] 12 | def b ? not c |= 0 [ERROR] 12 | def b [ not c ] := 0
[ERROR] | ^^^^^ [ERROR] | ^^^^^
[ERROR] |

View File

@ -1,22 +1,22 @@
/* /*
declaration scope A: new scope A:
context a content int param a type int
context b content bool param b type bool
context a_base content int param a_base type int
declaration scope B: new scope B:
context a content int param a type int
context b content bool param b type bool
context scopeA scope A param scopeA scope A
context scopeAbis scope A param scopeAbis scope A
scope A: scope A:
def a_base = 1 def a_base := 1
def a = -1 def a := -1
def b = a > 0 def b := a > 0
scope B: scope B:
def a = 42 def a := 42
def b = scopeA.b def b := scopeA.b
def scopeA.a ? a > 0 |= scopeA.a_base def scopeA.a [ a > 0 ] := scopeA.a_base
*/ */

View File

@ -1,28 +1,28 @@
/* /*
declaration scope A: new scope A:
context x content integer param x type int
context u content boolean param u type bool
declaration scope B: new scope B:
context a scope A param a scope A
context y content integer param y type int
declaration scope C: new scope C:
context a scope A param a scope A
context b scope B param b scope B
context z content integer param z type int
scope A: scope A:
definition x equals 0 def x := 0
definition u equals true def u := true
scope B: scope B:
definition a.x under condition a.u consequence equals 1 def a.x [ a.u ] := 1
definition y under condition a.x = 1 consequence equals 1 def y [ a.x = 1 ] := 1
definition y under condition a.x + 1 = 2 consequence equals 1 def y [ a.x + 1 = 2 ] := 1
scope C: scope C:
definition a.x equals 2 def a.x := 2
definition b.y equals 3 def b.y := 3
definition z equals 2 def z := 2
*/ */

View File

@ -1,22 +1,19 @@
[ERROR] Default logic conflict, multiple justifications are true but are not related by a precedence [ERROR] Default logic conflict, multiple justifications are true but are not related by a precedence
[ERROR] [ERROR]
[ERROR] The conflict concerns this variable y [ERROR] The conflict concerns this variable y
[ERROR] --> test_scope/sub_sub_scope.catala
[ERROR] |
[ERROR] 8 | param y type int
[ERROR] | ^
[ERROR]
[ERROR] This justification is true:
[ERROR] --> test_scope/sub_sub_scope.catala [ERROR] --> test_scope/sub_sub_scope.catala
[ERROR] | [ERROR] |
[ERROR] 8 | context y content integer [ERROR] 21 | def y [ a.x = 1 ] := 1
[ERROR] | ^ [ERROR] | ^^^^^^^
[ERROR]
[ERROR] This justification is true:
[ERROR] --> test_scope/sub_sub_scope.catala
[ERROR] | [ERROR] |
[ERROR] [ERROR] 22 | def y [ a.x + 1 = 2 ] := 1
[ERROR] This justification is true: [ERROR] | ^^^^^^^^^^^
[ERROR] --> test_scope/sub_sub_scope.catala
[ERROR] |
[ERROR] 21 | definition y under condition a.x = 1 consequence equals 1
[ERROR] | ^^^^^^^
[ERROR] |
[ERROR]
[ERROR] This justification is true:
[ERROR] --> test_scope/sub_sub_scope.catala
[ERROR] |
[ERROR] 22 | definition y under condition a.x + 1 = 2 consequence equals 1
[ERROR] | ^^^^^^^^^^^
[ERROR] |