Skip to content

Commit

Permalink
Fix line number increment after token + comment parse examples
Browse files Browse the repository at this point in the history
Previous code appeared to assume that every token comprises
exactly one character.
  • Loading branch information
IlmariReissumies committed May 6, 2024
1 parent 072c030 commit 35327df
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions pancake/parser/panConcreteExamplesScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fun parse_pancake q =
end

val check_success = assert $ sumSyntax.is_inl o rhs o concl
val check_failure = assert $ sumSyntax.is_inr o rhs o concl

(** Examples can be written using quoted strings and passed to the ML
function parse_pancake. *)
Expand Down Expand Up @@ -311,4 +312,43 @@ val shmem_ex = ‘

val shmem_ex_parse = check_success $ parse_pancake shmem_ex;

val comment_ex =
‘/* this /* non-recursive block comment
*/
// and these single-line comments
fun main() { //should not interfer with parsing
return /* nor shoud this */ 1;
}

val comment_ex_parse = check_success $ parse_pancake comment_ex

val error_line_ex1 =
‘/* this
nasty /* non recursive /*
block comment
*/
// and these
// single-line comments
fun fun main() { //should not interfer with error line reporting
return /* nor shoud this */ 1;
}

val error_line_ex1_parse = check_failure $ parse_pancake error_line_ex1

val error_line_ex2 =
‘/* this
nasty /* non recursive /*
block comment
*/
// and these
// single-line comments
fun main() { //should not interfer with error line reporting
return val /* nor shoud this */ 1;
}

val error_line_ex2_parse = check_failure $ parse_pancake error_line_ex2

val _ = export_theory();
2 changes: 1 addition & 1 deletion pancake/parser/panLexerScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ Definition pancake_lex_aux_def:
(case next_token input loc of
| NONE => []
| SOME (token, Locs locB locE, rest) =>
(token, Locs locB locE) :: pancake_lex_aux rest (next_loc 1 loc))
(token, Locs locB locE) :: pancake_lex_aux rest locE)
Termination
WF_REL_TAC ‘measure (LENGTH o FST)’ >> rw[]
>> imp_res_tac next_token_LESS
Expand Down

0 comments on commit 35327df

Please sign in to comment.