GCC预处理器线标记的正则表达式

时间:2018-02-07 15:11:23

标签: c gcc

下面的C预处理器行标记是否有任何Bash或Python正则表达式?

C预处理器输出行标记如下:

# 74 "a/b/some_file.c" 3 4

首先是符号 - # 空间 然后行号 - 74 空间 然后 - "文件路径" 空间 然后由空格分隔的零个或多个整数 - 3 4

更多信息:

https://gcc.gnu.org/onlinedocs/gcc-6.4.0/cpp/Preprocessor-Output.html

1 个答案:

答案 0 :(得分:1)

我不知道你希望Bash匹配这些行,而Python无疑可以用它的正则表达式来实现。我有一个#line脚本,用于将#!/bin/sh # # @(#)$Id: linecomments.sh,v 1.3 2018/01/05 05:12:10 jleffler Exp $ # # Convert #line directives into comments # Deals with four forms of the #line directive: # # line 99 "file" # # line 99 # # 99 "file" # # 99 exec sed \ -e 's%^[[:space:]]*#[[:space:]]*line[[:space:]][0-9][0-9]*[[:space:]].*%/*&*/%' \ -e 's%^[[:space:]]*#[[:space:]]*[0-9][0-9]*[[:space:]].*%/*&*/%' \ -e 's%^[[:space:]]*#[[:space:]]*line[[:space:]][0-9][0-9]*$%/*&*/%' \ -e 's%^[[:space:]]*#[[:space:]]*[0-9][0-9]*$%/*&*/%' \ "$@" 指令转换为注释(有时可以使调试预处理代码更容易)。它看起来像这样:

%

我使用/*来分隔正则表达式,因为我在替换文本中需要*/[  ]。正则表达式匹配“尾随垃圾”#39;例如GCC发出的额外数字。

2018年的编辑用[[:space:]]替换了看起来像Counting objects: 3, done. Delta compression using up to 6 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 336 bytes | 336.00 KiB/s, done. Total 3 (delta 2), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Ruby app detected remote: -----> Compiling Ruby/Rails remote: -----> Using Ruby version: ruby-2.3.4 remote: ###### WARNING: remote: Removing `Gemfile.lock` because it was generated on Windows. remote: Bundler will do a full resolve so native gems are handled properly. remote: This may result in unexpected gem versions being used in your app. remote: In rare occasions Bundler may not be able to resolve your dependencies at all. remote: https://devcenter.heroku.com/articles/bundler-windows-gemfile remote: remote: -----> Installing dependencies using bundler 1.15.2 remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 remote: The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86- mingw32 x86-mswin32 x64-mingw32 java`. remote: Fetching gem metadata from https://rubygems.org/.......... remote: Fetching version metadata from https://rubygems.org/.. remote: Fetching dependency metadata from https://rubygems.org/. remote: Resolving dependencies... remote: Using rake 12.3.0 remote: Using concurrent-ruby 1.0.5 remote: Using minitest 5.11.3 remote: Using thread_safe 0.3.6 remote: Using builder 3.2.3 remote: Using erubi 1.7.0 remote: Using mini_portile2 2.3.0 remote: Using crass 1.0.3 remote: Using rack 2.0.4 remote: Using nio4r 2.2.0 remote: Using websocket-extensions 0.1.3 remote: Using mini_mime 1.0.0 remote: Using arel 8.0.0 remote: Using bundler 1.15.2 remote: Using coffee-script-source 1.12.2 remote: Using execjs 2.7.0 remote: Using method_source 0.9.0 remote: Using thor 0.20.0 remote: Using ffi 1.9.21 remote: Using multi_json 1.13.1 remote: Fetching pg 0.17.1 remote: Using puma 3.11.2 remote: Using rails_serve_static_assets 0.0.5 remote: Using rails_stdout_logging 0.0.5 remote: Using rb-fsevent 0.10.2 remote: Using tilt 2.0.8 remote: Using turbolinks-source 5.1.0 remote: Using i18n 0.9.3 remote: Using tzinfo 1.2.5 remote: Using nokogiri 1.8.2 remote: Using websocket-driver 0.6.5 remote: Using rack-test 0.8.2 remote: Using sprockets 3.7.1 remote: Using mail 2.7.0 remote: Using uglifier 4.1.5 remote: Using coffee-script 2.4.1 remote: Using rb-inotify 0.9.10 remote: Fetching rails_12factor 0.0.2 remote: Using turbolinks 5.1.0 remote: Using activesupport 5.1.4 remote: Using loofah 2.1.1 remote: Using sass-listen 4.0.0 remote: Using rails-dom-testing 2.0.3 remote: Using globalid 0.4.1 remote: Using activemodel 5.1.4 remote: Using jbuilder 2.7.0 remote: Using rails-html-sanitizer 1.0.3 remote: Using sass 3.5.5 remote: Using activejob 5.1.4 remote: Using activerecord 5.1.4 remote: Using actionview 5.1.4 remote: Using actionpack 5.1.4 remote: Using actioncable 5.1.4 remote: Using actionmailer 5.1.4 remote: Using railties 5.1.4 remote: Using sprockets-rails 3.2.1 remote: Using coffee-rails 4.2.2 remote: Using rails 5.1.4 remote: Using sass-rails 5.0.7 remote: Installing pg 0.17.1 with native extensions remote: Installing rails_12factor 0.0.2 remote: Bundle complete! 15 Gemfile dependencies, 59 gems now installed. remote: Gems in the groups development and test were not installed. remote: Bundled gems are installed into ./vendor/bundle. remote: Bundle completed (9.84s) remote: Cleaning up the bundler cache. remote: Removing pg (1.0.0) remote: Removing rails_12factor (0.0.3) remote: The latest bundler is 1.16.1, but you are currently running 1.15.2. remote: To update, run `gem install bundler` remote: -----> Installing node-v6.11.1-linux-x64 remote: -----> Detecting rake tasks remote: -----> Preparing app for Rails asset pipeline remote: Running: rake assets:precompile remote: Yarn executable was not detected in the system. remote: Download Yarn at https://yarnpkg.com/en/docs/install remote: Asset precompilation completed (1.55s) remote: Cleaning assets remote: Running: rake assets:clean remote: remote: ###### WARNING: remote: Removing `Gemfile.lock` because it was generated on Windows. remote: Bundler will do a full resolve so native gems are handled properly. remote: This may result in unexpected gem versions being used in your app. remote: In rare occasions Bundler may not be able to resolve your dependencies at all. remote: https://devcenter.heroku.com/articles/bundler-windows-gemfile remote: remote: ###### WARNING: remote: No Procfile detected, using the default web server. remote: We recommend explicitly declaring how to boot your server process via a Procfile. remote: https://devcenter.heroku.com/articles/ruby-default-web-server remote: remote: -----> Discovering process types remote: Procfile declares types -> (none) remote: Default types for buildpack -> console, rake, web, worker remote: remote: -----> Compressing... remote: Done: 37.4M remote: -----> Launching... remote: Released v9 remote: https://coolguygear.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. To https://git.heroku.com/coolguygear.git 69e3355..ce67809 master -> master C:\Users\Jared\testapp> 的片段 - 旧代码(2001年)在每种情况下都使用了空格和制表符。这更清楚;您可以复制“粘贴”,而无需担心标签的位置。