Skip to content

Commit

Permalink
Make TildePrefix.recognize aware of its surroundings
Browse files Browse the repository at this point in the history
  • Loading branch information
Niols committed Sep 17, 2023
1 parent e2b0d81 commit 325ba8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/prelexerState.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ let string_of_word (Word (s, _)) = s

let string_of_attribute = function
| NoAttribute -> ""
| ParameterLength -> "#"
| ParameterLength -> "#"
| UseDefaultValues (p, w) -> p ^ string_of_word w
| AssignDefaultValues (p, w) -> p ^ string_of_word w
| IndicateErrorifNullorUnset (p, w) -> p ^ string_of_word w
Expand Down Expand Up @@ -366,7 +366,7 @@ let return ?(with_newline=false) lexbuf (current : prelexer_state) tokens =
| QuotingMark _ -> []
) (buffer current)))
in
let csts = TildePrefix.recognize csts in
let csts = TildePrefix.recognize ~in_assignment:false csts in (* FIXME: sometimes should be true *)
[Pretoken.PreWord (w, csts)]
in
let tokens = if with_newline then tokens @ [Pretoken.NEWLINE] else tokens in
Expand Down
10 changes: 4 additions & 6 deletions src/tildePrefix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,10 @@ let rec concat_words_with_colon (words : word_cst list) : word_cst =
(** Recognises tilde prefixes in a word, that is recognises eg. [WordLiteral
"~foo"] and replaces it by [WordTildePrefix "foo"] when in the right
position. *)
let recognize (word : word_cst) =
match word with
| [WordAssignmentWord (name, Word (s, word))] ->
let recognize ~in_assignment (word : word_cst) =
if in_assignment then
let words = split_word_on_colon word in
let words = List.map extract_tilde_prefix_from_word_if_present words in
let word = concat_words_with_colon words in
[WordAssignmentWord (name, Word (s, word))]
| _ ->
concat_words_with_colon words
else
extract_tilde_prefix_from_word_if_present word

0 comments on commit 325ba8b

Please sign in to comment.