Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regex literal, ideas from Cindy #9

Open
c9s opened this issue Oct 14, 2013 · 0 comments
Open

regex literal, ideas from Cindy #9

c9s opened this issue Oct 14, 2013 · 0 comments
Labels

Comments

@c9s
Copy link
Owner

c9s commented Oct 14, 2013

Cindy said:

有打算在字串或 regex 的 literal 裡面能塞複雜的 expression 嗎?
像是 perl 的 "... @{[ sin 5 ]}..." 或 ruby 的 "... #{ sine 5 } ... "

我記得在 C 裡面因為字串很單純, 頂多就 \ 能 escape 一個字, 所以 C 的 string literal 可以用 lexer 就認得出來
如果裡面還能塞 expression 的話, regex 就認不了了

(這邊的 regex 指的是 lexer ^^|)
就要寫入 context free grammar 裡面

javascript 的字串或 regex 都沒有變數 interpolation, 事情有簡化一點
perl 因為有 interpolation, 而且直接就塞簡單變數, 不需要 #{ }, 所以有 ambiguity 需要投票
/...$a[12].../ 可以解讀為 $a 的內容, 然後 [12] 或是 $a 陣列的 [12] 這個元素
嗯, 如果可以統一定成... 一定會 greedy
往後延伸, 或是一定要 #{$a[12]} 都可以避開 ambiguity
覺得 ruby (也是 coffeescript) 的 interpolation 比較好做. 雖然就總是要多寫 #{...}
用簡單變數的時候反而比原生 php 還長.. 不過 php 一整個是在亂做 orz

啊我看你的設計裡面變數什麼的好像都沒有 prefix, 那就不用煩惱這種事了, 反正一定不能用 php / perl 這種簡易 interpolate

那用 #{...} 好了, 這樣設計的語言還不少, 用起來比較熟悉...
ruby, coffeescript, sass 都是 #{...}
php 的 regex 是用函數做的, 而且主流有兩種.... (聽說全世界主流 regex 也就這兩種 XD) 如果不要做 =~ 而只有做 regex 的 literal 的話, 好處是比較靈活能套來路不明的 regex engine
如果做了 =~ 就相當於釘死要用哪一套了

@c9s c9s added the syntax label May 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant