我开始学习亚历克斯并相信我已经达到了有状态的环境会有所帮助,但我不完全确定如何去做.我试图lex有限的erlang二进制子集.使用以下词法分析器:
{
module Main (main, Token(..), AlexPosn(..), alexScanTokens, token_posn) where
}
%wrapper "posn"
$digit = 0-9 -- digits
$alpha = [a-zA-Z] -- alphabetic characters
$dbl_quote = \"
tokens :-
$white+ ;
"," { tok (\p s -> Comma p) }
"<<" { tok (\p s -> BinaryOpen p) }
">>" { tok (\p s -> BinaryClose p) }
$dbl_quote [^$dbl_quote]* $dbl_quote { tok (\p s -> ErlStr p (init (tail s))) }
$digit+ { tok (\p …Run Code Online (Sandbox Code Playgroud) Github支持用于通知代码更改的post-receive挂钩,在此处记录.现在,为了测试一个钩子服务器,我需要发布一些json,我想使用curl这样做.我以前做过这个,但很少,我倾向于忘记我的解决方案.
我记得,每次都很乏味.
Github人员提供此JSON文档作为将在参数上POST的数据的示例payload:
{
"before": "5aef35982fb2d34e9d9d4502f6ede1072793222d",
"repository": {
"url": "http://github.com/defunkt/github",
"name": "github",
"description": "You're lookin' at it.",
"watchers": 5,
"forks": 2,
"private": 1,
"owner": {
"email": "chris@ozmm.org",
"name": "defunkt"
}
},
"commits": [
{
"id": "41a212ee83ca127e3c8cf465891ab7216a705f59",
"url": "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
"author": {
"email": "chris@ozmm.org",
"name": "Chris Wanstrath"
},
"message": "okay i give in",
"timestamp": "2008-02-15T14:57:17-08:00",
"added": ["filepath.rb"]
},
{
"id": "de8251ff97ee194a289832576287d6f8ad74e3d0",
"url": "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
"author": {
"email": "chris@ozmm.org",
"name": "Chris Wanstrath"
},
"message": "update pricing a tad",
"timestamp": "2008-02-15T14:36:34-08:00" …Run Code Online (Sandbox Code Playgroud) 我想为动态语言制作一个类型化的AST.目前,我一直坚持处理收藏品.这是一个代表性的代码示例:
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ExistentialQuantification #-}
data Box = forall s. B s
data BinOp = Add | Sub | Mul | Div
deriving (Eq, Show)
data Flag = Empty | NonEmpty
data List :: Flag -> * -> * where
Nil :: List Empty a
Cons :: a -> List f a -> List NonEmpty a
data Expr ty where
EInt :: Integer -> Expr Integer
EDouble :: …Run Code Online (Sandbox Code Playgroud) 假设我们有以下类型:
sealed trait T
case object Goat extends T
case object Monk extends T
case object Tiger extends T
Run Code Online (Sandbox Code Playgroud)
现在,如何构建一个集合,T使得每个子集中至少有一个T出现在集合中,这个约束是在编译时强制执行的?一个集合,与此相反:
val s:Seq[T] = Seq(Goat)
Run Code Online (Sandbox Code Playgroud)
编译,这:
val ts:TotalSeq[T] = TotalSeq(Goat, Goat, Tiger)
Run Code Online (Sandbox Code Playgroud)
才不是.我上面使用过Scala,但我很乐意看到其他语言的解决方案.
(请原谅我,如果我的话有点偏;我感冒了,今天我很开心,有谜题.)
我有一个commit-msg钩子,我为所有本地提交运行,对于某个项目,我需要运行.问题是,当我从其他叉子拉进来时,我的一些同胞没有运行这个commit-msg钩子.到目前为止,我一直在做
$ git rebase --interactive $commit_parent
Run Code Online (Sandbox Code Playgroud)
作为概括非常相似这里.选择未正确完成的提交,重新编辑等.一切都非常可行,但我手工做的也很乏味.
我该如何自动化?钩子不需要疏忽.
我决定在我的个人机器上从rvm转移到rbenv.按照rvm删除说明,安装rbenv,一切看起来很好看.重新启动我的shell会话后:
$ rbenv global
1.9.3-p0
$ ls .rvm
ls: cannot access .rvm: No such file or directory
$ rbenv exec gem list
*** LOCAL GEMS ***
Run Code Online (Sandbox Code Playgroud)
一个全新的安装在一个新的外壳 - RVM早已不复存在.现在,当我安装bundler时
$ rbenv exec gem install bundler
Fetching: bundler-1.0.22.gem (100%)
Successfully installed bundler-1.0.22
1 gem installed
$ rbenv rehash
$ echo $?
0
$ rbenv which bundle
rbenv: bundle: command not found
Run Code Online (Sandbox Code Playgroud)
什么?的确,看看这个废话:
$ ls .rvm/gems/ruby-1.9.3-p0/gems/bundler-1.0.22/
bin bundler.gemspec CHANGELOG.md ISSUES.md lib LICENSE man Rakefile README.md spec UPGRADING.md …Run Code Online (Sandbox Code Playgroud) 我有一个通用的测试套件,它尝试创建一个 ets 表以用于所有套件和所有测试用例。它看起来像这样:
-module(an_example_SUITE).
-include_lib("common_test/include/ct.hrl").
-compile(export_all).
all() -> [ets_tests].
init_per_suite(Config) ->
TabId = ets:new(conns, [set]),
ets:insert(TabId, {foo, 2131}),
[{table,TabId} | Config].
end_per_suite(Config) ->
ets:delete(?config(table, Config)).
ets_tests(Config) ->
TabId = ?config(table, Config),
[{foo, 2131}] = ets:lookup(TabId, foo).
Run Code Online (Sandbox Code Playgroud)
该ets_tests函数因 badarg而失败。创建/销毁每个测试用例的 ets 表,如下所示:
-module(an_example_SUITE).
-include_lib("common_test/include/ct.hrl").
-compile(export_all).
all() -> [ets_tests].
init_per_testcase(Config) ->
TabId = ets:new(conns, [set]),
ets:insert(TabId, {foo, 2131}),
[{table,TabId} | Config].
end_per_testcase(Config) ->
ets:delete(?config(table, Config)).
ets_tests(Config) ->
TabId = ?config(table, Config),
[{foo, 2131}] = ets:lookup(TabId, foo).
Run Code Online (Sandbox Code Playgroud)
运行这个,我发现它运行得很好。
我对这种行为感到困惑,无法确定为什么会发生这种情况,形成docs …
我希望应用一系列nom解析器并返回&str匹配的完整内容。我想匹配表单的字符串a+bc+。使用现有的chain!宏,我可以非常接近:
named!(aaabccc <&[u8], &str>,
map_res!(
chain!(
a: take_while!(is_a) ~
tag!("b") ~
take_while!(is_c) ,
|| {a}
),
from_utf8
));
Run Code Online (Sandbox Code Playgroud)
在哪里
fn is_a(l: u8) -> bool {
match l {
b'a' => true,
_ => false,
}
}
fn is_c(l: u8) -> bool {
match l {
b'c' => true,
_ => false,
}
}
Run Code Online (Sandbox Code Playgroud)
假设我们有 'aaabccc' 作为输入。上面的解析器将匹配输入,但只会返回“aaa”。我想做的是返回原始输入“aaabccc”。
chain!不是正确的宏,但没有另一个看起来更正确的宏。最好的方法是什么?
在撰写本文时,我正在使用 nom1.2.2和 rustc 1.9.0-nightly (a1e29daf1 2016-03-25)。
我和Limpens先生有一个非常相似的问题,其中一个主要不同:我确实将test_unit railtie包含在我的application.rb中.
从我的application.rb:
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require 'action_controller/railtie'
require 'dm-rails/railtie'
# require 'action_mailer/railtie'
# require 'active_resource/railtie'
require 'rails/test_unit/railtie'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
您将注意到我正在使用DataMapper并使用dm-rails引导程序初始化我的项目.我可以手动运行我的测试,如下所示:
$ ruby -Itest test/unit/test_habit.rb Loaded suite test/unit/test_habit Started ..... Finished in 2.554523 seconds. 5 tests, 7 assertions, 0 failures, …
我有两个文件,都是命名的server.pp.当我在缓冲区之间切换时,我看到server.pp和server.pp<1>.情况是一个是module1/server.pp另一个module2/server.pp.我怎样才能以包含一些路径前缀信息的方式切换缓冲区?